Skip to content

Commit f26f1c9

Browse files
authored
Improve models
Improve models
1 parent 3d12b78 commit f26f1c9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+978
-504
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[flake8]
22
max-line-length = 120
33
# __init__ exports names
4-
per-file-ignores=./flask_openapi3/__init__.py: F401
4+
per-file-ignores=__init__.py: F401

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This workflow will upload a Python Package using Twine when a release is created
22
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
33

4-
name: Upload Python Package
4+
name: publish
55

66
on:
77
release:

docs/Reference/Models.md

Lines changed: 60 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,69 @@
11
::: flask_openapi3.models.APISpec
22

3-
::: flask_openapi3.models.info.Info
4-
::: flask_openapi3.models.info.Contact
5-
::: flask_openapi3.models.info.License
3+
::: flask_openapi3.models.OAuthConfig
64

7-
::: flask_openapi3.models.tag.Tag
5+
::: flask_openapi3.models.Callback
86

9-
::: flask_openapi3.models.file.FileStorage
7+
::: flask_openapi3.models.Components
108

11-
::: flask_openapi3.models.component.Components
9+
::: flask_openapi3.models.Contact
1210

13-
::: flask_openapi3.models.oauth.OAuthConfig
11+
::: flask_openapi3.models.Discriminator
1412

15-
::: flask_openapi3.models.common.MediaType
16-
::: flask_openapi3.models.common.ExternalDocumentation
17-
::: flask_openapi3.models.common.XML
18-
::: flask_openapi3.models.common.Discriminator
19-
::: flask_openapi3.models.common.Reference
20-
::: flask_openapi3.models.common.Schema
21-
::: flask_openapi3.models.common.Example
22-
::: flask_openapi3.models.common.Encoding
23-
::: flask_openapi3.models.common.Header
24-
::: flask_openapi3.models.common.ExtraRequestBody
13+
::: flask_openapi3.models.Encoding
2514

26-
::: flask_openapi3.models.path.Link
27-
::: flask_openapi3.models.path.RequestBody
28-
::: flask_openapi3.models.path.Response
29-
::: flask_openapi3.models.path.Parameter
30-
::: flask_openapi3.models.path.Operation
31-
::: flask_openapi3.models.path.PathItem
15+
::: flask_openapi3.models.Example
3216

33-
::: flask_openapi3.models.validation_error.ValidationErrorModel
17+
::: flask_openapi3.models.ExternalDocumentation
18+
19+
::: flask_openapi3.models.FileStorage
20+
21+
::: flask_openapi3.models.Header
22+
23+
::: flask_openapi3.models.Info
24+
25+
::: flask_openapi3.models.License
26+
27+
::: flask_openapi3.models.Link
28+
29+
::: flask_openapi3.models.MediaType
30+
31+
::: flask_openapi3.models.OAuthFlow
32+
33+
::: flask_openapi3.models.OAuthFlows
34+
35+
::: flask_openapi3.models.Operation
36+
37+
::: flask_openapi3.models.Parameter
38+
39+
::: flask_openapi3.models.ParameterInType
40+
41+
::: flask_openapi3.models.PathItem
42+
43+
::: flask_openapi3.models.Paths
44+
45+
::: flask_openapi3.models.Reference
46+
47+
::: flask_openapi3.models.RequestBody
48+
49+
::: flask_openapi3.models.Response
50+
51+
::: flask_openapi3.models.Responses
52+
53+
::: flask_openapi3.models.Schema
54+
55+
::: flask_openapi3.models.SecurityRequirement
56+
57+
::: flask_openapi3.models.SecurityScheme
58+
59+
::: flask_openapi3.models.Server
60+
61+
::: flask_openapi3.models.ServerVariable
62+
63+
::: flask_openapi3.models.StyleValues
64+
65+
::: flask_openapi3.models.Tag
66+
67+
::: flask_openapi3.models.ValidationErrorModel
68+
69+
::: flask_openapi3.models.XML

flask_openapi3/__init__.py

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,50 @@
44

55
from .__version__ import __version__
66
from .blueprint import APIBlueprint
7-
from .models.common import Discriminator
8-
from .models.common import Encoding
9-
from .models.common import Example
10-
from .models.common import ExternalDocumentation
11-
from .models.common import ExtraRequestBody
12-
from .models.common import Header
13-
from .models.common import MediaType
14-
from .models.common import Reference
15-
from .models.common import Schema
16-
from .models.common import XML
17-
from .models.component import Components
18-
from .models.file import FileStorage
19-
from .models.info import Contact
20-
from .models.info import Info
21-
from .models.info import License
22-
from .models.oauth import OAuthConfig
23-
from .models.path import Link
24-
from .models.path import Operation
25-
from .models.path import Parameter
26-
from .models.path import ParameterInType
27-
from .models.path import PathItem
28-
from .models.path import RequestBody
29-
from .models.path import Response
30-
from .models.path import StyleValues
7+
from .models import APISpec
8+
from .models import Components
9+
from .models import Contact
10+
from .models import Discriminator
11+
from .models import Encoding
12+
from .models import Example
13+
from .models import ExternalDocumentation
14+
from .models import ExtraRequestBody
15+
from .models import FileStorage
16+
from .models import Header
17+
from .models import Info
18+
from .models import License
19+
from .models import Link
20+
from .models import MediaType
21+
from .models import OAuthConfig
22+
from .models import OAuthFlow
23+
from .models import OAuthFlows
24+
from .models import Operation
25+
from .models import Parameter
26+
from .models import ParameterInType
27+
from .models import PathItem
28+
from .models import Reference
29+
from .models import RequestBody
30+
from .models import Response
31+
from .models import Schema
32+
from .models import SecurityScheme
33+
from .models import Server
34+
from .models import ServerVariable
35+
from .models import StyleValues
36+
from .models import Tag
37+
from .models import UnprocessableEntity
38+
from .models import ValidationErrorModel
39+
from .models import XML
3140
from .models.security import APIKey
3241
from .models.security import APIKeyIn
3342
from .models.security import HTTPBase
3443
from .models.security import HTTPBearer
3544
from .models.security import OAuth2
36-
from .models.security import OAuthFlow
3745
from .models.security import OAuthFlowAuthorizationCode
3846
from .models.security import OAuthFlowClientCredentials
3947
from .models.security import OAuthFlowImplicit
4048
from .models.security import OAuthFlowPassword
41-
from .models.security import OAuthFlows
4249
from .models.security import OpenIdConnect
4350
from .models.security import SecurityBase
4451
from .models.security import SecuritySchemeType
45-
from .models.server import Server
46-
from .models.server import ServerVariable
47-
from .models.tag import Tag
48-
from .models.validation_error import UnprocessableEntity
49-
from .models.validation_error import ValidationErrorModel
5052
from .openapi import OpenAPI
5153
from .view import APIView

flask_openapi3/blueprint.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,20 @@
88
from pydantic import BaseModel
99

1010
from ._http import HTTPMethod
11-
from .models import Tag, ExternalDocumentation
12-
from .models.common import ExtraRequestBody
13-
from .models.server import Server
11+
from .models import ExternalDocumentation
12+
from .models import ExtraRequestBody
13+
from .models import Server
14+
from .models import Tag
1415
from .scaffold import APIScaffold
1516
from .types import ResponseDict
16-
from .utils import get_operation, get_responses, parse_and_store_tags, parse_parameters, parse_method, \
17-
get_operation_id_for_path, parse_rule, convert_responses_key_to_string
17+
from .utils import convert_responses_key_to_string
18+
from .utils import get_operation
19+
from .utils import get_operation_id_for_path
20+
from .utils import get_responses
21+
from .utils import parse_and_store_tags
22+
from .utils import parse_method
23+
from .utils import parse_parameters
24+
from .utils import parse_rule
1825

1926

2027
class APIBlueprint(APIScaffold, Blueprint):
@@ -43,7 +50,7 @@ def __init__(
4350
doc_ui: Enable OpenAPI document UI (Swagger UI, Redoc, and Rapidoc). Defaults to True.
4451
operation_id_callback: Callback function for custom operation_id generation.
4552
Receives name (str), path (str) and method (str) parameters.
46-
Default to `get_operation_id_for_path` from utils
53+
Defaults to `get_operation_id_for_path` from utils
4754
**kwargs: Flask Blueprint kwargs
4855
"""
4956
super(APIBlueprint, self).__init__(name, import_name, **kwargs)
@@ -124,16 +131,15 @@ def _do_decorator(
124131
description: A verbose explanation of the operation behavior.
125132
external_docs: Additional external documentation for this operation.
126133
operation_id: Unique string used to identify the operation.
127-
extra_form: Extra information describing the request body(application/form).
128-
extra_body: Extra information describing the request body(application/json).
134+
extra_form: **Deprecated in v3.x**. Extra information describing the request body(application/form).
135+
extra_body: **Deprecated in v3.x**. Extra information describing the request body(application/json).
129136
responses: API responses should be either a subclass of BaseModel, a dictionary, or None.
130-
extra_responses: Extra information for responses.
137+
extra_responses: **Deprecated in v3.x**. Extra information for responses.
131138
deprecated: Declares this operation to be deprecated.
132139
security: A declaration of which security mechanisms can be used for this operation.
133140
servers: An alternative server array to service this operation.
134141
openapi_extensions: Allows extensions to the OpenAPI Schema.
135-
doc_ui: Add openapi document UI (swagger, rapidoc and redoc).
136-
Defaults to True.
142+
doc_ui: Declares this operation to be shown. Default to True.
137143
"""
138144
if self.doc_ui is True and doc_ui is True:
139145
if responses is None:

flask_openapi3/models/__init__.py

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,45 @@
11
# -*- coding: utf-8 -*-
22
# @Author : llc
33
# @Time : 2021/4/28 10:58
4-
from typing import Optional, List, Dict
4+
5+
from typing import Optional, List, Any, Dict, Union
56

67
from pydantic import BaseModel
78

8-
from .common import ExternalDocumentation
9-
from .component import Components
9+
from .callback import Callback
10+
from .components import Components
11+
from .contact import Contact
12+
from .discriminator import Discriminator
13+
from .encoding import Encoding
14+
from .example import Example
15+
from .external_documentation import ExternalDocumentation
16+
from .file import FileStorage
17+
from .header import Header
1018
from .info import Info
11-
from .path import PathItem
19+
from .license import License
20+
from .link import Link
21+
from .media_type import MediaType
22+
from .oauth_flow import OAuthFlow
23+
from .oauth_flows import OAuthFlows
24+
from .operation import Operation
25+
from .parameter import Parameter
26+
from .parameter_in_type import ParameterInType
27+
from .path_item import PathItem
28+
from .paths import Paths
29+
from .reference import Reference
30+
from .request_body import RequestBody
31+
from .response import Response
32+
from .responses import Responses
33+
from .schema import Schema
34+
from .security_requirement import SecurityRequirement
35+
from .security_scheme import SecurityScheme
1236
from .server import Server
37+
from .server_variable import ServerVariable
38+
from .style_values import StyleValues
1339
from .tag import Tag
40+
from .validation_error import UnprocessableEntity
41+
from .validation_error import ValidationErrorModel
42+
from .xml import XML
1443

1544
OPENAPI3_REF_PREFIX = '#/components/schemas'
1645
OPENAPI3_REF_TEMPLATE = OPENAPI3_REF_PREFIX + '/{model}'
@@ -29,3 +58,30 @@ class APISpec(BaseModel):
2958

3059
class Config:
3160
extra = "allow"
61+
62+
63+
class ExtraRequestBody(BaseModel):
64+
description: Optional[str] = None
65+
required: Optional[bool] = True
66+
# For MediaType
67+
example: Optional[Any] = None
68+
examples: Optional[Dict[str, Union[Example, Reference]]] = None
69+
encoding: Optional[Dict[str, Encoding]] = None
70+
71+
72+
class OAuthConfig(BaseModel):
73+
"""
74+
https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/oauth2.md#oauth-20-configuration
75+
"""
76+
clientId: Optional[str] = None
77+
clientSecret: Optional[str] = None
78+
realm: Optional[str] = None
79+
appName: Optional[str] = None
80+
scopeSeparator: Optional[str] = None
81+
scopes: Optional[str] = None
82+
additionalQueryStringParams: Optional[Dict[str, str]] = None
83+
useBasicAuthenticationWithAccessCodeGrant: Optional[bool] = False
84+
usePkceWithAuthorizationCodeGrant: Optional[bool] = False
85+
86+
87+
PathItem.update_forward_refs(Operation=Operation)

flask_openapi3/models/callback.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# -*- coding: utf-8 -*-
2+
# @Author : llc
3+
# @Time : 2023/7/4 9:35
4+
from typing import TYPE_CHECKING, Dict
5+
6+
if TYPE_CHECKING:
7+
from .path_item import PathItem
8+
else:
9+
PathItem = "PathItem"
10+
11+
"""
12+
A map of possible out-of band callbacks related to the parent operation.
13+
Each value in the map is a [Path Item Object](#pathItemObject)
14+
that describes a set of requests that may be initiated by the API provider and the expected responses.
15+
The key value used to identify the path item object is an expression, evaluated at runtime,
16+
that identifies a URL to use for the callback operation.
17+
"""
18+
Callback = Dict[str, PathItem]

0 commit comments

Comments
 (0)