11import enum
22from typing import Any
3- from typing import Optional
4- from typing import Union
3+ from typing import TypeAlias
54
65import pydantic
76
1211# https://spec.openapis.org/oas/v3.0.0.html#info-object
1312class Info (base_model .BaseModel ):
1413 title : str
15- description : Optional [ str ] = None
16- termsOfService : Optional [ str ] = None
14+ description : str | None = None
15+ termsOfService : str | None = None
1716 contact : Any = None
1817 license : Any = None
1918 version : str
@@ -22,11 +21,11 @@ class Info(base_model.BaseModel):
2221# https://spec.openapis.org/oas/v3.0.0.html#server-object
2322class Server (base_model .BaseModel ):
2423 url : str
25- description : Optional [ str ] = None
24+ description : str | None = None
2625 variables : dict [str , Any ] = pydantic .Field (default_factory = dict )
2726
2827
29- Schema = Any
28+ Schema : TypeAlias = Any
3029
3130
3231# https://spec.openapis.org/oas/v3.0.0.html#style-values
@@ -42,13 +41,13 @@ class Style(str, enum.Enum):
4241
4342# https://spec.openapis.org/oas/v3.0.0.html#header-object
4443class Header (base_model .BaseModel ):
45- description : Optional [ str ] = None
44+ description : str | None = None
4645 required : bool = False
4746 deprecated : bool = False
4847 allowEmptyValue : bool = False
4948
50- style : Optional [ Style ] = None
51- explode : Optional [ bool ] = None
49+ style : Style | None = None
50+ explode : bool | None = None
5251 allowReserved : bool = False
5352 schema_ : Schema = pydantic .Field (alias = 'schema' )
5453 example : Any = None
@@ -76,7 +75,7 @@ class Ref(base_model.BaseModel):
7675# https://spec.openapis.org/oas/v3.0.0.html#responses-object
7776class Response (base_model .BaseModel ):
7877 description : str
79- headers : dict [str , Union [ Header , Ref ] ] = pydantic .Field (default_factory = dict )
78+ headers : dict [str , Header | Ref ] = pydantic .Field (default_factory = dict )
8079 content : dict [str , MediaType ] = pydantic .Field (default_factory = dict )
8180 # TODO: links
8281
@@ -102,25 +101,25 @@ class QueryLogMode(str, enum.Enum):
102101class Parameter (base_model .BaseModel ):
103102 name : str
104103 in_ : In = pydantic .Field (alias = 'in' )
105- description : Optional [ str ] = None
104+ description : str | None = None
106105 required : bool = False
107106 deprecated : bool = False
108107 allowEmptyValue : bool = False
109108
110- style : Optional [ Style ] = None
111- explode : Optional [ bool ] = None
109+ style : Style | None = None
110+ explode : bool | None = None
112111 allowReserved : bool = False
113112 schema_ : Schema = pydantic .Field (alias = 'schema' )
114113 example : Any = None
115114 examples : dict [str , Any ] = pydantic .Field (default_factory = dict )
116115
117116 # content: dict[str, MediaType] = {}
118117
119- x_handler_tag : Optional [ str ] = pydantic .Field (
118+ x_handler_tag : str | None = pydantic .Field (
120119 default = None ,
121120 validation_alias = pydantic .AliasChoices ('x-taxi-handler-tag' , 'x-usrv-handler-tag' ),
122121 )
123- x_cpp_name : Optional [ str ] = pydantic .Field (
122+ x_cpp_name : str | None = pydantic .Field (
124123 default = None ,
125124 validation_alias = pydantic .AliasChoices ('x-taxi-cpp-name' , 'x-usrv-cpp-name' ),
126125 )
@@ -148,7 +147,7 @@ def model_post_init(self, context: Any, /) -> None:
148147
149148# https://spec.openapis.org/oas/v3.0.0.html#request-body-object
150149class RequestBody (base_model .BaseModel ):
151- description : Optional [ str ] = None
150+ description : str | None = None
152151 content : dict [str , MediaType ]
153152 required : bool = False
154153
@@ -167,48 +166,48 @@ class SecurityIn(str, enum.Enum):
167166
168167
169168class ImplicitFlow (base_model .BaseModel ):
170- refreshUrl : Optional [ str ] = None
169+ refreshUrl : str | None = None
171170 scopes : dict [str , str ] = pydantic .Field (default_factory = dict )
172171 authorizationUrl : str
173172
174173
175174class PasswordFlow (base_model .BaseModel ):
176- refreshUrl : Optional [ str ] = None
175+ refreshUrl : str | None = None
177176 scopes : dict [str , str ] = pydantic .Field (default_factory = dict )
178177 tokenUrl : str
179178
180179
181180class ClientCredFlow (base_model .BaseModel ):
182- refreshUrl : Optional [ str ] = None
181+ refreshUrl : str | None = None
183182 scopes : dict [str , str ] = pydantic .Field (default_factory = dict )
184183 tokenUrl : str
185184
186185
187186class AuthCodeFlow (base_model .BaseModel ):
188- refreshUrl : Optional [ str ] = None
187+ refreshUrl : str | None = None
189188 scopes : dict [str , str ] = pydantic .Field (default_factory = dict )
190189 authorizationUrl : str
191190 tokenUrl : str
192191
193192
194193# https://spec.openapis.org/oas/v3.0.0.html#oauth-flows-object
195194class OAuthFlows (base_model .BaseModel ):
196- implicit : Optional [ ImplicitFlow ] = None
197- password : Optional [ PasswordFlow ] = None
198- clientCredentials : Optional [ ClientCredFlow ] = None
199- authorizationCode : Optional [ AuthCodeFlow ] = None
195+ implicit : ImplicitFlow | None = None
196+ password : PasswordFlow | None = None
197+ clientCredentials : ClientCredFlow | None = None
198+ authorizationCode : AuthCodeFlow | None = None
200199
201200
202201# https://spec.openapis.org/oas/v3.0.0.html#security-scheme-object
203202class SecurityScheme (base_model .BaseModel ):
204203 type : SecurityType
205- description : Optional [ str ] = None
206- name : Optional [ str ] = None
207- in_ : Optional [ SecurityIn ] = pydantic .Field (alias = 'in' , default = None )
208- scheme_ : Optional [ str ] = pydantic .Field (alias = 'scheme' , default = None )
209- bearerFormat : Optional [ str ] = None
210- flows : Optional [ OAuthFlows ] = None
211- openIdConnectUrl : Optional [ str ] = None
204+ description : str | None = None
205+ name : str | None = None
206+ in_ : SecurityIn | None = pydantic .Field (alias = 'in' , default = None )
207+ scheme_ : str | None = pydantic .Field (alias = 'scheme' , default = None )
208+ bearerFormat : str | None = None
209+ flows : OAuthFlows | None = None
210+ openIdConnectUrl : str | None = None
212211
213212 def model_post_init (self , context : Any , / ) -> None :
214213 super ().model_post_init (context )
@@ -229,11 +228,11 @@ def model_post_init(self, context: Any, /) -> None:
229228 raise ValueError (errors .missing_field_msg ('openIdConnectUrl' ))
230229
231230
232- SecuritySchemes = dict [str , Union [ SecurityScheme , Ref ] ]
231+ SecuritySchemes : TypeAlias = dict [str , SecurityScheme | Ref ]
233232
234233
235234# https://spec.openapis.org/oas/v3.0.0.html#security-requirement-object
236- Security = dict [str , list [str ]]
235+ Security : TypeAlias = dict [str , list [str ]]
237236
238237
239238# https://spec.openapis.org/oas/v3.0.0.html#components-object
@@ -250,19 +249,19 @@ class Components(base_model.BaseModel):
250249# https://spec.openapis.org/oas/v3.0.0.html#operation-object
251250class Operation (base_model .BaseModel ):
252251 tags : list [str ] = pydantic .Field (default_factory = list )
253- summary : Optional [ str ] = None
252+ summary : str | None = None
254253 description : str = ''
255254 externalDocs : Any = None
256255
257- operationId : Optional [ str ] = None
258- parameters : list [Union [ Parameter , Ref ] ] = pydantic .Field (default_factory = list )
259- requestBody : Optional [ Union [ RequestBody , Ref ]] = None
260- responses : dict [Union [ str , int ], Union [ Response , Ref ] ]
256+ operationId : str | None = None
257+ parameters : list [Parameter | Ref ] = pydantic .Field (default_factory = list )
258+ requestBody : RequestBody | Ref | None = None
259+ responses : dict [str | int , Response | Ref ]
261260 deprecated : bool = False
262- security : Optional [ Security ] = None
261+ security : Security | None = None
263262 servers : list [Server ] = pydantic .Field (default_factory = list )
264263
265- x_taxi_middlewares : Optional [ base_model .XMiddlewares ] = pydantic .Field (
264+ x_taxi_middlewares : base_model .XMiddlewares | None = pydantic .Field (
266265 default = None ,
267266 validation_alias = pydantic .AliasChoices ('x-taxi-middlewares' , 'x-usrv-middlewares' ),
268267 )
@@ -292,20 +291,20 @@ def model_post_init(self, context: Any, /) -> None:
292291
293292# https://spec.openapis.org/oas/v3.0.0.html#path-item-object
294293class Path (base_model .BaseModel ):
295- summary : Optional [ str ] = None
294+ summary : str | None = None
296295 description : str = ''
297296
298- get : Optional [ Operation ] = None
299- post : Optional [ Operation ] = None
300- put : Optional [ Operation ] = None
301- delete : Optional [ Operation ] = None
302- options : Optional [ Operation ] = None
303- head : Optional [ Operation ] = None
304- patch : Optional [ Operation ] = None
305- trace : Optional [ Operation ] = None
297+ get : Operation | None = None
298+ post : Operation | None = None
299+ put : Operation | None = None
300+ delete : Operation | None = None
301+ options : Operation | None = None
302+ head : Operation | None = None
303+ patch : Operation | None = None
304+ trace : Operation | None = None
306305
307306 servers : list [Server ] = pydantic .Field (default_factory = list )
308- parameters : list [Union [ Parameter , Ref ] ] = pydantic .Field (default_factory = list )
307+ parameters : list [Parameter | Ref ] = pydantic .Field (default_factory = list )
309308
310309
311310class XTaxiClientQos (base_model .BaseModel ):
@@ -315,24 +314,24 @@ class XTaxiClientQos(base_model.BaseModel):
315314# https://spec.openapis.org/oas/v3.0.0.html#schema
316315class OpenApi (base_model .BaseModel ):
317316 openapi : str = '3.0.0'
318- info : Optional [ Info ] = None
317+ info : Info | None = None
319318 servers : list [Server ] = pydantic .Field (default_factory = list )
320319 paths : dict [str , Path ] = pydantic .Field (default_factory = dict )
321320 components : Components = Components ()
322321 security : Security = pydantic .Field (default_factory = dict )
323322 tags : list [Any ] = pydantic .Field (default_factory = list )
324323 externalDocs : Any = None
325324
326- x_taxi_client_qos : Optional [ XTaxiClientQos ] = pydantic .Field (
325+ x_taxi_client_qos : XTaxiClientQos | None = pydantic .Field (
327326 default = None ,
328327 validation_alias = pydantic .AliasChoices ('x-taxi-client-qos' , 'x-usrv-client-qos' ),
329328 )
330- x_taxi_middlewares : Optional [ base_model .XMiddlewares ] = pydantic .Field (
329+ x_taxi_middlewares : base_model .XMiddlewares | None = pydantic .Field (
331330 default = None ,
332331 validation_alias = pydantic .AliasChoices ('x-taxi-middlewares' , 'x-usrv-middlewares' ),
333332 )
334333
335- def validate_security (self , security : Optional [ Security ] ) -> None :
334+ def validate_security (self , security : Security | None ) -> None :
336335 if not security :
337336 return
338337
0 commit comments