Skip to content
This repository was archived by the owner on Oct 19, 2022. It is now read-only.
This repository was archived by the owner on Oct 19, 2022. It is now read-only.

Add support for Apispec / OpenApi #24

Description

@bustawin

OpenApi spec allows defining enumerations, following the JSON Schema validation. Apispec allows generating such OpenApi spec from Marshmallow schemas.

Currently Apispec does not get enumeration information from MarshmallowEnum. It is easy to add support by doing something like the following in the __init__ of the EnumField class:

self.metadata['enum'] = [e.name for e in enum]

metadata is a property of Field that apispec uses to retrieve OpenApi-related fields.

Currently I am achieving the same by doing:

class ApispecEnumField(EnumField):
    def __init__(self, enum, by_value=False, load_by=None, dump_by=None, error='', *args,
                 **kwargs):
        super().__init__(enum, by_value, load_by, dump_by, error, *args, **kwargs)
        self.metadata['enum'] = [e.name for e in enum]

Finally I would like to thank you for your package :-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions