-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathcomponents.py
142 lines (123 loc) · 4.81 KB
/
components.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
from typing import Dict, Optional, Union
from pydantic import BaseModel
from openapi_pydantic.compat import PYDANTIC_V2, ConfigDict, Extra
from .callback import Callback
from .example import Example
from .header import Header
from .link import Link
from .parameter import Parameter
from .path_item import PathItem
from .reference import Reference
from .request_body import RequestBody
from .response import Response
from .schema import Schema
from .security_scheme import SecurityScheme
_examples = [
{
"schemas": {
"GeneralError": {
"type": "object",
"properties": {
"code": {"type": "integer", "format": "int32"},
"message": {"type": "string"},
},
},
"Category": {
"type": "object",
"properties": {
"id": {"type": "integer", "format": "int64"},
"name": {"type": "string"},
},
},
"Tag": {
"type": "object",
"properties": {
"id": {"type": "integer", "format": "int64"},
"name": {"type": "string"},
},
},
},
"parameters": {
"skipParam": {
"name": "skip",
"in": "query",
"description": "number of items to skip",
"required": True,
"schema": {"type": "integer", "format": "int32"},
},
"limitParam": {
"name": "limit",
"in": "query",
"description": "max records to return",
"required": True,
"schema": {"type": "integer", "format": "int32"},
},
},
"responses": {
"NotFound": {"description": "Entity not found."},
"IllegalInput": {"description": "Illegal input for operation."},
"GeneralError": {
"description": "General Error",
"content": {
"application/json": {
"schema": {"$ref": "#/components/schemas/GeneralError"}
}
},
},
},
"securitySchemes": {
"api_key": {
"type": "apiKey",
"name": "api_key",
"in": "header",
},
"petstore_auth": {
"type": "oauth2",
"flows": {
"implicit": {
"authorizationUrl": "http://example.org/api/oauth/dialog",
"scopes": {
"write:pets": "modify pets in your account",
"read:pets": "read your pets",
},
}
},
},
},
}
]
class Components(BaseModel):
"""
Holds a set of reusable objects for different aspects of the OAS.
All objects defined within the components object will have no effect on the API
unless they are explicitly referenced from properties outside the components object.
"""
schemas: Optional[Dict[str, Schema]] = None
"""An object to hold reusable [Schema Objects](#schemaObject)."""
responses: Optional[Dict[str, Union[Response, Reference]]] = None
"""An object to hold reusable [Response Objects](#responseObject)."""
parameters: Optional[Dict[str, Union[Parameter, Reference]]] = None
"""An object to hold reusable [Parameter Objects](#parameterObject)."""
examples: Optional[Dict[str, Union[Example, Reference]]] = None
"""An object to hold reusable [Example Objects](#exampleObject)."""
requestBodies: Optional[Dict[str, Union[RequestBody, Reference]]] = None
"""An object to hold reusable [Request Body Objects](#requestBodyObject)."""
headers: Optional[Dict[str, Union[Header, Reference]]] = None
"""An object to hold reusable [Header Objects](#headerObject)."""
securitySchemes: Optional[Dict[str, Union[SecurityScheme, Reference]]] = None
"""An object to hold reusable [Security Scheme Objects](#securitySchemeObject)."""
links: Optional[Dict[str, Union[Link, Reference]]] = None
"""An object to hold reusable [Link Objects](#linkObject)."""
callbacks: Optional[Dict[str, Union[Callback, Reference]]] = None
"""An object to hold reusable [Callback Objects](#callbackObject)."""
pathItems: Optional[Dict[str, Union[PathItem, Reference]]] = None
"""An object to hold reusable [Path Item Object](#pathItemObject)."""
if PYDANTIC_V2:
model_config = ConfigDict(
extra="allow",
json_schema_extra={"examples": _examples},
)
else:
class Config:
extra = Extra.allow
schema_extra = {"examples": _examples}