-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# -*- coding: utf-8 -*- | ||
# @Author : llc | ||
# @Time : 2021/6/21 15:54 | ||
from enum import Enum | ||
from http import HTTPStatus | ||
|
||
HTTP_STATUS = {str(status.value): status.phrase for status in HTTPStatus} | ||
|
||
|
||
class HTTPMethod(str, Enum): | ||
GET = "GET" | ||
POST = "POST" | ||
PUT = "PUT" | ||
DELETE = "DELETE" | ||
PATCH = "PATCH" | ||
HEAD = "HEAD" | ||
OPTIONS = "OPTIONS" | ||
TRACE = "TRACE" | ||
CONNECT = "CONNECT" |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,18 +7,19 @@ | |
import warnings | ||
from abc import ABC | ||
from functools import wraps | ||
from typing import Callable, List, Optional, Dict, Type, Any, Tuple, Union | ||
from typing import Callable, List, Optional, Dict, Type, Any, Tuple | ||
|
||
from flask.scaffold import Scaffold | ||
from flask.wrappers import Response | ||
from pydantic import BaseModel | ||
|
||
from .http import HTTPMethod | ||
from ._http import HTTPMethod | ||
from .models import ExternalDocumentation | ||
from .models.common import ExtraRequestBody | ||
from .models.server import Server | ||
from .models.tag import Tag | ||
from .request import _do_request | ||
from .types import ResponseDict | ||
|
||
if sys.version_info >= (3, 8): | ||
iscoroutinefunction = inspect.iscoroutinefunction | ||
|
@@ -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 commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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. |
||
extra_responses: Optional[Dict[str, dict]] = None, | ||
deprecated: Optional[bool] = None, | ||
security: Optional[List[Dict[str, List[Any]]]] = None, | ||
|
@@ -146,7 +147,7 @@ def get( | |
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, | ||
extra_responses: Optional[Dict[str, dict]] = None, | ||
deprecated: Optional[bool] = None, | ||
security: Optional[List[Dict[str, List[Any]]]] = None, | ||
|
@@ -232,7 +233,7 @@ def post( | |
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, | ||
extra_responses: Optional[Dict[str, dict]] = None, | ||
deprecated: Optional[bool] = None, | ||
security: Optional[List[Dict[str, List[Any]]]] = None, | ||
|
@@ -316,7 +317,7 @@ def put( | |
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, | ||
extra_responses: Optional[Dict[str, dict]] = None, | ||
deprecated: Optional[bool] = None, | ||
security: Optional[List[Dict[str, List[Any]]]] = None, | ||
|
@@ -400,7 +401,7 @@ def delete( | |
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, | ||
extra_responses: Optional[Dict[str, dict]] = None, | ||
deprecated: Optional[bool] = None, | ||
security: Optional[List[Dict[str, List[Any]]]] = None, | ||
|
@@ -484,7 +485,7 @@ def patch( | |
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, | ||
extra_responses: Optional[Dict[str, dict]] = None, | ||
deprecated: Optional[bool] = None, | ||
security: Optional[List[Dict[str, List[Any]]]] = 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 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 inutils.py