Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Bangertm opened this issue Oct 2, 2017 · 1 comment

Comments

@Bangertm
Copy link
Collaborator

commented Oct 2, 2017

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': []}
@sloria

This comment has been minimized.

Copy link
Member

commented Oct 3, 2017

Good point. I would certainly review and merge a PR for this.

@sloria sloria closed this Oct 23, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.