Comments (5)
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.
from flask_accepts.
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.
from flask_accepts.
Example here
from flask_accepts.
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.
from flask_accepts.
Closing as the title issue has been resolved. Will open a separate thread for validator discussion.
from flask_accepts.
Related Issues (20)
- When using the @responds decorator, X-Fields headers are automatically applied to the swagger request HOT 2
- Swagger fails to load when a schema does not have a default set in one of the fields. HOT 4
- Marshmallow schema for form data HOT 1
- Query parameter and header schemas do not respect the data key attribute HOT 1
- Passing a schema type to the `schema` argument of @accepts ignores the type's Meta attributes
- Marshmallow 4 breaking changes
- Overriding flask_restx field
- Nested Marshmallow Schemas throwing error on Swagger HOT 5
- Partial param for Schema loading HOT 4
- [Q] Customize schema_errors? HOT 2
- Only swagger generation for end-point HOT 10
- What is the best practice for file uploads? HOT 2
- Working with UUIDs, Marshmallow & 'missing' fields
- Nested schemas with many=true do not generate a list of schemas in the swagger docs HOT 6
- The new partial keyword of accepts() breaks the marshmallow schema
- Using multiple different schemas in accepts decorator raises KeyError if there is a ValidationError
- Cookie header validation works on gunicorn, does not on NGINX
- Static typing on request.parsed_obj
- More forgiving loading of the JSON schema payload ignoring the mimetype
- Skip response fields where value is None
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flask_accepts.