-
-
Notifications
You must be signed in to change notification settings - Fork 171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
explode and style are hardcoded in OpenAPIConverter.property2parameter #500
Comments
Separating this out like with the attribute_functions makes sense to me. Note that based on the comment in #499 about not parsing location from metadata the path for apispec/src/apispec/ext/marshmallow/openapi.py Lines 122 to 135 in 15a06eb
|
Good. Looks like that change ( |
This part of apispec/src/apispec/ext/marshmallow/openapi.py Lines 169 to 182 in 15a06eb
|
Let's wait for webargs 6 and tackle this (remove location + this issue) in apispec 4. |
@Bangertm, your comments assume that Should we make it private API? The tests currently call it directly. We'd have to rework them. |
The one reason to leave it public is that currently apispec does not handle webargs arguments defined as a dictionary of name, field pairs. The tests calling Other than that there isn't a good reason for leaving it public. |
I see what you mean. I'm leaning towards making all those methods private. We could support the |
@lafrech did you ever find an easy way to work around this limitation? I'm trying to do the exact same thing, document a DelimitedList field. I'm looking at subclassing or monkeypatching OpenAPIConverter to do it at this point. |
Nope, this is still a TODO. The path is relatively clear. I just didn't get the time to do it. I'd like to finish #526 then address this. Once this is done, user code can provide custom behaviour for |
Ok, thanks again for your work @lafrech! In the meantime, I monkeypatched field2parameter to manually manipulate the explode param. Here's how to do it if anyone else runs into this: from apispec.ext.marshmallow import openapi
from marshmallow import fields
from webargs.fields import DelimitedList
def patched_field2parameter(self, field, *, name, default_in):
"""
Monkeypatch apispec to add proper support for webargs `DelimitedList` field.
A fix may be coming in a future version of the library. More details here:
https://github.com/marshmallow-code/apispec/issues/500
"""
# This section is copied directly from
# https://github.com/marshmallow-code/apispec/blob/dev/src/apispec/ext/marshmallow/openapi.py#L193
location = field.metadata.get('location', None)
prop = self.field2property(field)
param = self.property2parameter(
prop,
name=name,
required=field.required,
multiple=isinstance(field, fields.List),
location=location,
default_in=default_in,
)
# This section has been introduced by us
if isinstance(field, DelimitedList):
# Force apispec to allow DelimitedList query params in the format 'ids=123,456,789'
# instead of the default which is 'id=123&id=456&id=789'. Read more about this setting
# here: https://swagger.io/docs/specification/serialization/.
param['explode'] = False
return param
openapi.OpenAPIConverter.field2parameter = patched_field2parameter |
Nice. I wasn't that clever in my own app: I patched the generated documentation dict... |
The refactor is achieved in 4.0. This issue should now be addressable in a non-breaking way in a 4.x version. I can't do it right now so let's not block 4.0. |
It should be easier now. It happens in |
I've been trying to document webargs's
DelimitedList
(child class ofList
) and I'm stuck because I'd need to override hardcoded stuff.To document
DelimitedList
, we'd need to setexplode
to False. That's assuming we use default,
as delimiter. Using space or pipe would require to also modifystyle
.To make this more generic, we could remove
multiple
and create an extensible mechanism to allow custom post-processings afterproperty2parameter
. And add a post-processor forList
to do what's currently done withmultiple
.Kinda like what's been done with attribute_functions in
FieldConverter
.(Maybe we could separate the property2bodyparameter case as right now it does not involve a specific
List
case.)The text was updated successfully, but these errors were encountered: