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

Responses key supports both string, int, and HTTPStatus #87

Closed
wants to merge 4 commits into from

Conversation

luolingchun
Copy link
Owner

@luolingchun luolingchun commented Jul 9, 2023

Checklist:

  • Run pytest tests and no failed.
  • Run flake8 flask_openapi3 tests examples and no failed.
  • Run mypy flask_openapi3 and no failed.
  • Run mkdocs serve and no failed.

fix: #86

Copy link
Contributor

@CostcoFanboy CostcoFanboy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few questions.


@api.get("/hello/<string:name>",
responses={
HTTPStatus.OK: Message,
Copy link
Owner Author

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.

Copy link
Contributor

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!

message = {"message": f"""Hello {path.name}!"""}

response = make_response(json.dumps(message), HTTPStatus.OK)
# response = make_response("sss", HTTPStatus.OK)
Copy link
Contributor

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}
Copy link
Contributor

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.

Copy link
Owner Author

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,
Copy link
Contributor

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.

Copy link
Owner Author

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.

Copy link
Contributor

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,
Copy link
Contributor

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 👍🏻


@api.get("/hello/<string:name>",
responses={
HTTPStatus.OK: Message,
Copy link
Owner Author

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.

@luolingchun luolingchun deleted the response_supports_string_and_int branch July 30, 2023 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Supports both string, int, and HTTPStatus
2 participants