-
Notifications
You must be signed in to change notification settings - Fork 35
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
Responses key supports both string, int, and HTTPStatus #87
Conversation
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.
Few questions.
docs/Usage/Response.md
Outdated
|
||
@api.get("/hello/<string:name>", | ||
responses={ | ||
HTTPStatus.OK: Message, |
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.
HTTPStatus.OK: Message
is not a type of hint. HTTPStatus.OK
is key and Message
is value.
And I will improve the documentation here.
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.
Apologies I was tired and didn't read properly. Please ignore!
docs/Usage/Response.md
Outdated
message = {"message": f"""Hello {path.name}!"""} | ||
|
||
response = make_response(json.dumps(message), HTTPStatus.OK) | ||
# response = make_response("sss", HTTPStatus.OK) |
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.
Leftover debug?
from enum import Enum | ||
from http import HTTPStatus | ||
|
||
HTTP_STATUS = {str(status.value): status.phrase for status in HTTPStatus} |
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.
Why do that though 🤔 you can just get rid of this entirely. It's not used anywhere despite this being labelled an internal module.
Not a blocker just curious.
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.
I just want to be consistent with the built-in modules, HTTPStatus
is not useless, it is used in utils.py
@@ -48,7 +49,7 @@ def _do_decorator( | |||
operation_id: Optional[str] = None, | |||
extra_form: Optional[ExtraRequestBody] = None, | |||
extra_body: Optional[ExtraRequestBody] = None, | |||
responses: Optional[Dict[str, Union[Type[BaseModel], Dict[Any, Any], None]]] = None, | |||
responses: Optional[ResponseDict] = None, |
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.
Why not use inheritance for GET, PUT, DELETE, etc and only overwrite the http method?
Every time there is a change, you need to change like 5-6 classes. It's inconvenient for you.
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.
I think this code is more straightforward and easier to understand, and if you have a better way, I suggest reopening a PR to discuss.
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.
Understood, I'm not sure if my way is technically better. I'll propose one and show what I mean later. Maybe you'll like it.
@@ -283,13 +285,11 @@ def parse_body( | |||
|
|||
|
|||
def get_responses( | |||
responses: Optional[Dict[str, Union[Type[BaseModel], Dict[Any, Any], None]]], | |||
responses: ResponseStrKeyDict, |
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.
Great change way easier to read 👍🏻
docs/Usage/Response.md
Outdated
|
||
@api.get("/hello/<string:name>", | ||
responses={ | ||
HTTPStatus.OK: Message, |
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.
HTTPStatus.OK: Message
is not a type of hint. HTTPStatus.OK
is key and Message
is value.
And I will improve the documentation here.
Checklist:
pytest tests
and no failed.flake8 flask_openapi3 tests examples
and no failed.mypy flask_openapi3
and no failed.mkdocs serve
and no failed.fix: #86