Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix __root__ #95

Merged
merged 3 commits into from
Dec 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.3.15",
version="0.3.16",
author="Keming Yang",
author_email="kemingy94@gmail.com",
description=(
Expand Down
2 changes: 1 addition & 1 deletion spectree/plugins/falcon_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def validate(
model = resp.find_model(_resp.status[:3])
if model:
try:
model.validate(_resp.media)
model.parse_obj(_resp.media)
except ValidationError as err:
resp_validation_error = err
_resp.status = "500 Internal Service Response Validation Error"
Expand Down
2 changes: 1 addition & 1 deletion spectree/plugins/flask_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def validate(
model = resp.find_model(response.status_code)
if model:
try:
model.validate(response.get_json())
model.parse_obj(response.get_json())
except ValidationError as err:
resp_validation_error = err
response = make_response(
Expand Down
2 changes: 1 addition & 1 deletion spectree/plugins/starlette_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ async def validate(
model = resp.find_model(response.status_code)
if model:
try:
model.validate(json_loads(response.body))
model.parse_obj(json_loads(response.body))
except ValidationError as err:
resp_validation_error = err
response = JSONResponse(err.errors(), 500)
Expand Down
6 changes: 5 additions & 1 deletion tests/common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from enum import Enum, IntEnum
from typing import List
from typing import Dict, List

from pydantic import BaseModel, Field, root_validator

Expand All @@ -18,6 +18,10 @@ class JSON(BaseModel):
limit: int


class StrDict(BaseModel):
__root__: Dict[str, str]


class Resp(BaseModel):
name: str
score: List[int]
Expand Down
3 changes: 2 additions & 1 deletion tests/test_plugin_falcon.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from spectree import Response, SpecTree

from .common import JSON, Cookies, Headers, Query, Resp
from .common import JSON, Cookies, Headers, Query, Resp, StrDict


def before_handler(req, resp, err, instance):
Expand Down Expand Up @@ -40,6 +40,7 @@ class UserScore:
def extra_method(self):
pass

@api.validate(resp=Response(HTTP_200=StrDict))
def on_get(self, req, resp, name):
self.extra_method()
resp.media = {"name": name}
Expand Down
4 changes: 2 additions & 2 deletions tests/test_plugin_flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from spectree import Response, SpecTree

from .common import JSON, Cookies, Headers, Query, Resp
from .common import JSON, Cookies, Headers, Query, Resp, StrDict


def before_handler(req, resp, err, _):
Expand All @@ -27,7 +27,7 @@ def api_after_handler(req, resp, err, _):


@app.route("/ping")
@api.validate(headers=Headers, tags=["test", "health"])
@api.validate(headers=Headers, resp=Response(HTTP_200=StrDict), tags=["test", "health"])
def ping():
"""summary
description"""
Expand Down
4 changes: 2 additions & 2 deletions tests/test_plugin_flask_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from spectree import Response, SpecTree

from .common import JSON, Cookies, Headers, Query, Resp
from .common import JSON, Cookies, Headers, Query, Resp, StrDict


def before_handler(req, resp, err, _):
Expand All @@ -27,7 +27,7 @@ def api_after_handler(req, resp, err, _):


@app.route("/ping")
@api.validate(headers=Headers, tags=["test", "health"])
@api.validate(headers=Headers, resp=Response(HTTP_200=StrDict), tags=["test", "health"])
def ping():
"""summary
description"""
Expand Down
9 changes: 7 additions & 2 deletions tests/test_plugin_starlette.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from spectree import Response, SpecTree

from .common import JSON, Cookies, Headers, Query, Resp
from .common import JSON, Cookies, Headers, Query, Resp, StrDict


def before_handler(req, resp, err, instance):
Expand All @@ -32,7 +32,12 @@ def method_handler(req, resp, err, instance):
class Ping(HTTPEndpoint):
name = "Ping"

@api.validate(headers=Headers, tags=["test", "health"], after=method_handler)
@api.validate(
headers=Headers,
resp=Response(HTTP_200=StrDict),
tags=["test", "health"],
after=method_handler,
)
def get(self, request):
"""summary
description"""
Expand Down