Skip to content

Marshmallow validate.Equal does not generate an enum in swagger #155

@Bangertm

Description

@Bangertm

I would have expected that the marshmallow Equal validator to generate an enum with a single entry in swagger and be the equivalent of OneOf with only a single entry in the list.

For example:

from pprint import pprint
from apispec import APISpec

from marshmallow import Schema, fields
from marshmallow.validate import OneOf, Equal

class MySchema(Schema):
    property_1 = fields.Str(validate=OneOf(['only_choice']))

    property_2 = fields.Str(validate=Equal('only_choice'))

spec = APISpec(title='Demo',
               version='1',
               info=dict(description='demo'),
               plugins=['apispec.ext.marshmallow'])

spec.definition('MySchema', schema=MySchema)

pprint(spec.to_dict())

produces:

{'definitions': {'MySchema': {u'properties': {'property_1': {u'enum': ['only_choice'], u'type': u'string'}, 'property_2': {u'type': u'string'}},
                              u'type': u'object'}},
 'info': {'description': 'demo', 'title': 'Demo', 'version': '1'},
 'parameters': {},
 'paths': OrderedDict(),
 'swagger': '2.0',
 'tags': []}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions