Skip to content

Commit 632f790

Browse files
committed
Document add_parameter_attribute_function
1 parent 83a49a5 commit 632f790

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

docs/conf.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
default_role = "py:obj"
1919

2020
intersphinx_mapping = {
21-
"python": ("http://python.readthedocs.io/en/latest/", None),
22-
"marshmallow": ("http://marshmallow.readthedocs.io/en/latest/", None),
21+
"python": ("https://python.readthedocs.io/en/latest/", None),
22+
"marshmallow": ("https://marshmallow.readthedocs.io/en/latest/", None),
23+
"webargs": ("https://webargs.readthedocs.io/en/latest/", None),
2324
}
2425

2526
issues_github_path = "marshmallow-code/apispec"

docs/using_plugins.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,32 @@ method. Continuing from the example above:
295295
The function passed to `add_attribute_function` will be bound to the converter.
296296
It must accept the converter instance as first positional argument.
297297

298+
In some rare cases, typically with container fields such as fields derived from
299+
:class:`List <marshmallow.fields.List>`, documenting the parameters using this
300+
field require some more customization.
301+
This can be achieved using the `add_parameter_attribute_function
302+
<apispec.ext.marshmallow.openapi.OpenAPIConverter.add_parameter_attribute_function>`
303+
method.
304+
305+
For instance, when documenting webargs's
306+
:class:`DelimitedList <webargs.fields.DelimitedList>` field, one may register
307+
this function:
308+
309+
.. code-block:: python
310+
311+
def delimited_list2param(self, field, **kwargs):
312+
ret: dict = {}
313+
if isinstance(field, DelimitedList):
314+
if self.openapi_version.major < 3:
315+
ret["collectionFormat"] = "csv"
316+
else:
317+
ret["explode"] = False
318+
ret["style"] = "form"
319+
return ret
320+
321+
322+
ma_plugin.converter.add_parameter_attribute_function(delimited_list2param)
323+
298324
Next Steps
299325
----------
300326

0 commit comments

Comments
 (0)