apispec
apispec copied to clipboard
Incorrect handling of nullable enums in marshmallow converter
According to the OpenAPI specification, nullable enums must list null in the allowed options. apispec doesn't do this by default, so in my projects I've had to patch this behaviour in with the following attribute function:
def field_to_properties(self, field, ret):
enum = ret.get('enum', [])
nullable = ret.get('nullable', False)
if enum and nullable and None not in enum:
return {'enum': [*enum, None]}
return {}
It would be nice if apispec implemented this.
Hi Peter. Thanks for reporting.
This also applies to the new Enum field (enum2properties).
This should be a relatively easy fix. Anybody willing to look into it, please go ahead.
fixed by #888