-
-
Notifications
You must be signed in to change notification settings - Fork 74
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 Flask status code processing after release 1.2.2 #341
Conversation
Demo example: from uuid import uuid4
from datetime import timedelta
from flask import Flask, make_response
from pydantic import Field, BaseModel, constr
from spectree import Response, SpecTree
AUTH_COOKIES_CONFIG = {
"domain": None,
"secure": False,
"httponly": False,
"samesite": None,
"max_age": timedelta(days=10),
}
class Profile(BaseModel):
name: constr(min_length=2, max_length=40) # constrained str
age: int = Field(..., gt=0, lt=150, description="user age(Human)")
class Config:
schema_extra = {
# provide an example
"example": {
"name": "very_important_user",
"age": 42,
}
}
class Message(BaseModel):
text: str
app = Flask(__name__)
spec = SpecTree(path="docs", backend_name="flask")
@app.route("/api/user", methods=["POST"])
@spec.validate(json=Profile, resp=Response(HTTP_201=Message, HTTP_403=None), tags=["api"])
def user_profile():
"""
verify user profile (summary of this endpoint)
user's name, user's age, ... (long description)
"""
response = make_response(Message(text="it works!").dict(), 201)
response.set_cookie(
key="auth_token",
value=str(uuid4()),
**AUTH_COOKIES_CONFIG,
)
return response
if __name__ == "__main__":
spec.register(app) # if you don't register in api init step
app.run(port=8000) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution! 🎉
I will figure out the pypy test failure later.
@kemingy |
Let me figure out. Thanks for your feedback. |
Following the release of version 1.2.2, the server response's status code generated through "make_response" is no longer being processed accurately. Instead, it is being overwritten with the status code 200.