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
Metadata
Release files for schema-validator 0.2.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| schema_validator-0.2.5.tar.gz | 10.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| schema_validator-0.2.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 24.1 kB
Release files / schema_validator-0.2.5.tar.gz
| Download URL | schema_validator-0.2.5.tar.gz |
|---|---|
| Size | 10.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bf80a8f9d55d1342a35b1f5422f7cbd33e5ba08dbcb56e6e99afff3608aae4e9
|
|
BLAKE2b-256 checksum How to use checksums |
57abfdaca277af898bb228e9e228a639bc8df2649814b67a0bdff9f223bd1bf0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.10 CPython/3.8.5 Darwin/19.5.0
|
Release files / schema_validator-0.2.5-py3-none-any.whl
| Download URL | schema_validator-0.2.5-py3-none-any.whl |
|---|---|
| Size | 14.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e8d3ff391e0bf58d4f5ac83f7932df2f598c96a4e9113c535db5a3153ad320c7
|
|
BLAKE2b-256 checksum How to use checksums |
56304303cc886d835728dfbcbaadeef026064ca13fd687570dee31cc190d6819
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.10 CPython/3.8.5 Darwin/19.5.0
|