marshmallow-code / marshmallow-code/apispec
Allow user-defined field types to implement their own attribute function
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.2k
- Forks
- 202
- Avg merge
- 3h 38m
- Merged PRs (30d)
- 3
Description
When using user-defined fields ( such as EnumField as requested in #506 or Union from marshmallow-union) it would be nice to be able to hook directly into apispec.ext.marshmallow.field_converter.FieldConverterMixin.field2property by defining a specific method.
I'm currently using this simple code for that purpose:
def customfield2properties(self: OpenAPIConverter, field: fields.Field, ret: Dict[str, Any]) -> Dict[str, Any]:
"""
A field attribute function to allow field classes to declare
how to generate/add parameters to their jsonschema representation
"""
if hasattr(field, "apispec_field2properties"):
field.apispec_field2properties(self, ret)
return ret
Once added to the converter with any field defining the apispec_field2properties method can describe itself without having to add a specific attribute_function to the Marshmallow plugin.
Is this something you would be interested in having in apispec? I can work on a pull request.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at apispec.ext.marshmallow.field_converter.FieldConverterMixin.field2property and compare it with the proposed customfield2properties example. Determine how user-defined fields can supply their own JSON Schema attributes without registering a Marshmallow plugin attribute function. Done means the hook is supported and its behavior is covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100