Skip to main content

schema-validator

Generate from quart-schema

Install

  • pip install schema-validator
How to use
    from dataclasses import dataclass
    from datetime import datetime
    from typing import Optional
    from pydantic import BaseModel

    from flask import Flask
    from quart import Quart
    from schema_validator import SchemaValidator
    from schema_validator.flask import validate
    # from schema_validator.quart import validate


    app = Flask(__name__)

    # or 
    app = Quart(__name__)
    
    
    OR
    
    schema = SchemaValidator(app)
    schema.init_app(app)

    @dataclass
    class Todo:
        task: str
        due: Optional[datetime]

    class TodoResponse(BaseModel):
        id: int
        name: str

    @app.post("/")
    @validate(body=Todo, responses=TodoResponse)
    def create_todo():
        # balabala
        return dict(id=1, name="2")
        
    @app.get("/")
    @validate(
        query=Todo,
        responses={200: TodoResponse, 400: TodoResponse}
    )
    def update_todo():
        # balabala
        return TodoResponse(id=1, name="123")

    @app.delete("/")
    @validate(
        body=Todo,
        responses={200: TodoResponse}
    )
    def delete():
        # balabala
        return jsonify(id=1)

    @tags("SOME-TAG", "OTHER-TAG")  # only for swagger
    class View(MethodView):
        @validate(...)
        def get(self):
            return {}
       
    
How to show the swagger

app.config["SWAGGER_ROUTE"] = True

http://yourhost/swagger/docs   -> show the all swagger

http://yourhost/swagger/docs/{tag} -> show the swagger which include tag

How to export the swagger
add command in flask/quart:
    app.cli.add_command(generate_schema_command)

Export all swagger to json file:

 - flask/quart schema -o swagger.json

Export the swagger which include the ACCOUNT tag:

 - flask/quart schema -o swagger.json -t ACCOUNT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

schema_validator-0.2.5.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

schema_validator-0.2.5-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file schema_validator-0.2.5.tar.gz.

File metadata

  • Download URL: schema_validator-0.2.5.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.10 CPython/3.8.5 Darwin/19.5.0

File hashes

Hashes for schema_validator-0.2.5.tar.gz
Algorithm Hash digest
SHA256 bf80a8f9d55d1342a35b1f5422f7cbd33e5ba08dbcb56e6e99afff3608aae4e9
MD5 5d28fa5edb1f8b122504f02e90c424c8
BLAKE2b-256 57abfdaca277af898bb228e9e228a639bc8df2649814b67a0bdff9f223bd1bf0

See more details on using hashes here.

File details

Details for the file schema_validator-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: schema_validator-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.10 CPython/3.8.5 Darwin/19.5.0

File hashes

Hashes for schema_validator-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 e8d3ff391e0bf58d4f5ac83f7932df2f598c96a4e9113c535db5a3153ad320c7
MD5 67bb8c02d3a3a54c7ec9d9738f16adb1
BLAKE2b-256 56304303cc886d835728dfbcbaadeef026064ca13fd687570dee31cc190d6819

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.5 This release

2 files

0.2.4

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.20

2 files

0.1.19

2 files

0.1.18

2 files

0.1.17

2 files

0.1.16

2 files

0.1.15

2 files

0.1.14

2 files

0.1.13

2 files

0.1.12

2 files

0.1.11

2 files

0.1.10

2 files

0.1.9

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

0.0.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page