%global _empty_manifest_terminate_build 0
Name: python-schema-validator
Version: 0.2.5
Release: 1
Summary: A flask/quart extension to provide schema validation with pydantic.
License: MIT
URL: https://github.com/huangxiaohen2738/schema-validator
Source0: https://mirrors.aliyun.com/pypi/web/packages/57/ab/fdaca277af898bb228e9e228a639bc8df2649814b67a0bdff9f223bd1bf0/schema_validator-0.2.5.tar.gz
BuildArch: noarch
Requires: python3-pyhumps
Requires: python3-pydantic
%description
#### 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
```
%package -n python3-schema-validator
Summary: A flask/quart extension to provide schema validation with pydantic.
Provides: python-schema-validator
BuildRequires: python3-devel
BuildRequires: python3-setuptools
BuildRequires: python3-pip
%description -n python3-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
```
%package help
Summary: Development documents and examples for schema-validator
Provides: python3-schema-validator-doc
%description help
#### 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
```
%prep
%autosetup -n schema_validator-0.2.5
%build
%py3_build
%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
find usr/lib -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
find usr/lib64 -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
find usr/bin -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
find usr/sbin -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
find usr/share/man -type f -printf "\"/%h/%f.gz\"\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .
%files -n python3-schema-validator -f filelist.lst
%dir %{python3_sitelib}/*
%files help -f doclist.lst
%{_docdir}/*
%changelog
* Thu Jun 08 2023 Python_Bot - 0.2.5-1
- Package Spec generated