Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

Commit

Permalink
fix return jsonify
Browse files Browse the repository at this point in the history
  • Loading branch information
ponytailer committed Sep 27, 2021
1 parent ca90a94 commit 9f6aacd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,19 @@ flask-dantic-schema
name: str
@app.post("/")
@validate(body=Todo, responses={200: TodoResponse})
@validate(body=Todo, responses=TodoResponse)
def create_todo():
... # Do something with data, e.g. save to the DB
return data
return dict(id=1, name="2")
@app.put("/")
@validate(
body=Todo,
responses={200: TodoResponse, 400: TodoResponse}
)
def update_todo():
... # Do something with data, e.g. save to the DB
return TodoResponse(id=1, name="123")
app.cli.add_command(generate_schema_command)
Expand Down
5 changes: 5 additions & 0 deletions schema_validator/validation.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json

from dataclasses import asdict, is_dataclass
from enum import Enum, auto
from functools import wraps
Expand Down Expand Up @@ -76,6 +78,9 @@ def check_response(result, response_model: Dict[int, PydanticModel]):
else:
value = result

if isinstance(value, Response):
value = value.get_json()

status = 200
if status_or_headers is not None and not isinstance(
status_or_headers, (Headers, dict, list)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest
from pydantic import BaseModel
from pydantic.dataclasses import dataclass as pydantic_dataclass
from flask import Flask
from flask import Flask, jsonify

from schema_validator import (
DataSource,
Expand Down Expand Up @@ -137,7 +137,7 @@ def test_response_validation(model: Any, return_value: Any,
@app.route("/")
@validate(responses=model)
def item() -> ResponseReturnValue:
return return_value
return jsonify(return_value)

test_client = app.test_client()
response = test_client.get("/")
Expand Down

0 comments on commit 9f6aacd

Please sign in to comment.