You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is it possible to validate that ResponseModel is what's returned? Hoping I've missed something obvious in the docs: I see query, body, and form, along with the ability to generate response_many.
Extending the sample app.py a tiny bit:
fromtypingimportOptionalfromflaskimportFlask, requestfrompydanticimportBaseModelfromflask_pydanticimportvalidateapp=Flask("flask_pydantic_app")
classQueryModel(BaseModel):
age: intclassResponseModel(BaseModel):
id: intage: intname: strnickname: Optional[str] =None# Example 1: query parameters only@app.route("/", methods=["GET"])@validate()defget(query: QueryModel) ->ResponseModel:
age=query.ageifage>10:
return {'asdf': False}. # This should NOT be a valid responsereturnResponseModel(
age=age,
id=0, name="abc", nickname="123"
)
Now querying and getting a response that doesn't match the expected ResponseModel:
Is it possible to validate that
ResponseModel
is what's returned? Hoping I've missed something obvious in the docs: I seequery
,body
, andform
, along with the ability to generateresponse_many
.Extending the sample
app.py
a tiny bit:Now querying and getting a response that doesn't match the expected
ResponseModel
:Was hoping that there was a way to ensure that an invalid response schema couldn't be returned. Any pointers?
The text was updated successfully, but these errors were encountered: