Skip to content

Commit

Permalink
0.10.5
Browse files Browse the repository at this point in the history
Signed-off-by: Keming <kemingy94@gmail.com>
  • Loading branch information
kemingy committed Aug 7, 2022
1 parent 668c88a commit a657261
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
43 changes: 43 additions & 0 deletions examples/multi_example_demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from flask import Flask
from pydantic import BaseModel

from spectree import SpecTree


class Query(BaseModel):
name: str
limit: int

class Config:
schema_extra = {
"examples": {
"test1": {
"name": "hello",
"limit": 1,
},
"test2": {
"name": "world",
"limit": 2,
},
},
"example": {
"name": "hello",
"limit": 5,
},
}


app = Flask(__name__)
spec = SpecTree("flask", annotations=True)


@app.route("/", methods=["POST"])
@spec.validate()
def index(json: Query):
print(json)
return "msg: ok"


if __name__ == "__main__":
spec.register(app)
app.run()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

setup(
name="spectree",
version="0.10.4",
version="0.10.5",
license="Apache-2.0",
author="Keming Yang",
author_email="kemingy94@gmail.com",
Expand Down
11 changes: 5 additions & 6 deletions tests/test_response.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List
from typing import List, get_type_hints

import pytest
from pydantic import BaseModel
Expand Down Expand Up @@ -43,10 +43,9 @@ def test_init_response():
expect_400_model = gen_list_model(JSON)
assert resp.has_model()
assert resp.find_model(200) is None
assert (
type(resp.find_model(400)) == type(expect_400_model)
and resp.find_model(400).__annotations__ == expect_400_model.__annotations__
)
assert type(resp.find_model(400)) == type(expect_400_model) and get_type_hints(
resp.find_model(400)
) == get_type_hints(expect_400_model)
assert resp.find_model(401) == DemoModel
assert resp.find_model(402) is None
assert resp.find_model(403) == DemoModel
Expand Down Expand Up @@ -112,7 +111,7 @@ def test_list_model():
resp = Response(HTTP_200=List[JSON])
model = resp.find_model(200)
expect_model = gen_list_model(JSON)
assert model.__annotations__ == expect_model.__annotations__
assert get_type_hints(model) == get_type_hints(expect_model)
assert type(model) == type(expect_model)
assert issubclass(model, BaseModel)
data = [
Expand Down

0 comments on commit a657261

Please sign in to comment.