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

Support is missing for some field types, particularly Boolean, Date, and DateTime #15

Closed
flayman opened this issue Aug 23, 2019 · 5 comments

Comments

@flayman
Copy link

flayman commented Aug 23, 2019

As in the title, it would be very useful to support the Date, DateTime, and Boolean field types. These don't come through in the registered model, and I can see that they are not in the type_map dict in utils.py. There are a great many field types in Marshmallow, some of which may not be relevant to this conversion exercise, but the three I've listed are arguably essential. Where a type is not supported in flask-accepts, I'd say it should default to Raw.

@flayman
Copy link
Author

flayman commented Aug 23, 2019

Looking at the code, it seems there is also no support for various validation qualifiers such as min_length, max_length, pattern, minimum, maximum, etc. These would probably translate from validators. For example:

class UserSchema(Schema):
    name = fields.Str(validate=validate.Length(min=1))
    permission = fields.Str(validate=validate.OneOf(["read", "write", "admin"]))
    age = fields.Int(validate=validate.Range(min=18, max=40))

Taken from https://marshmallow.readthedocs.io/en/stable/quickstart.html?highlight=length#validation

I think it will be quite a lot of work to get this into a fully featured tool, but I'd be glad to help. The apispec project has a Marshmallow Plugin that converts Marshmallow schemas to json schema. It does a pretty good job and you might want to have a look at that. The json schema validation qualifiers are similar to what flask-restplus models use. One thing that is missing from their translation is default values.

@apryor6
Copy link
Owner

apryor6 commented Aug 23, 2019

Good points. Easy to add the additional types where there is a straightforward match. I only skipped them because I didn't need them at the time and figured if/when anybody else was interested they could be implemented at that time.

As for the validator conversion, are you referring to converting the validators from the schema into something that can be documented in Swagger? The actual validation functionality can be used as-is because the marshmallow schema is used to perform the validation when a schema is provided (not a converted api.Model). The converted model only exists in the documentation.

@apryor6
Copy link
Owner

apryor6 commented Aug 23, 2019

Example here

@apryor6
Copy link
Owner

apryor6 commented Aug 23, 2019

Supporting the validations within Swagger like here from the RESTplus docs could be done via a direct translation. There are likely some cases that don't have a counterpart, and that would probably require something more custom.

@apryor6
Copy link
Owner

apryor6 commented Aug 23, 2019

Closing as the title issue has been resolved. Will open a separate thread for validator discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants