Coder Social home page Coder Social logo

Comments (5)

flayman avatar flayman commented on June 12, 2024

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.

apryor6 avatar apryor6 commented on June 12, 2024

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.

apryor6 avatar apryor6 commented on June 12, 2024

Example here

from flask_accepts.

apryor6 avatar apryor6 commented on June 12, 2024

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.

apryor6 avatar apryor6 commented on June 12, 2024

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

from flask_accepts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.