13
13
"""
14
14
15
15
16
- class OpenapiExtensions (BaseModel ):
17
- """OpenAPI extensions, see https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#specification-extensions"""
18
-
19
- openapi_extensions : Optional [Dict [str , Any ]] = None
20
-
21
- if PYDANTIC_V2 :
22
-
23
- @parser_openapi_extension ()
24
- def serialize (self ):
25
- # If the 'openapi_extensions' field is not None, return it
26
- if self .openapi_extensions :
27
- return self .openapi_extensions
28
-
29
- else :
30
-
31
- # If the 'openapi_extensions' field is present in the 'values' dictionary,
32
- # update the 'values' dictionary with the contents of 'openapi_extensions',
33
- # and then remove the 'openapi_extensions' field from the 'values' dictionary
34
- @parser_openapi_extension (pre = False , allow_reuse = True )
35
- def check_json (cls , values ):
36
- if values .get ("openapi_extensions" ):
37
- values .update (values ["openapi_extensions" ])
38
- del values ["openapi_extensions" ]
39
- return values
40
-
41
-
42
16
# https://swagger.io/specification/#contact-object
43
17
class Contact (BaseModel ):
44
18
name : Optional [str ] = None
@@ -103,16 +77,33 @@ class Config:
103
77
104
78
105
79
# https://swagger.io/specification/#server-object
106
- class Server (OpenapiExtensions ):
80
+ class Server (BaseModel ):
107
81
url : Union [AnyUrl , str ]
108
82
description : Optional [str ] = None
109
83
variables : Optional [Dict [str , ServerVariable ]] = None
84
+ openapi_extensions : Optional [Dict [str , Any ]] = None
110
85
111
86
if PYDANTIC_V2 :
112
87
model_config = {"extra" : "allow" }
113
88
89
+ @parser_openapi_extension ()
90
+ def serialize (self ):
91
+ # If the 'openapi_extensions' field is not None, return it
92
+ if self .openapi_extensions :
93
+ return self .openapi_extensions
94
+
114
95
else :
115
96
97
+ # If the 'openapi_extensions' field is present in the 'values' dictionary,
98
+ # update the 'values' dictionary with the contents of 'openapi_extensions',
99
+ # and then remove the 'openapi_extensions' field from the 'values' dictionary
100
+ @parser_openapi_extension (pre = False , allow_reuse = True )
101
+ def check_json (cls , values ):
102
+ if values .get ("openapi_extensions" ):
103
+ values .update (values ["openapi_extensions" ])
104
+ del values ["openapi_extensions" ]
105
+ return values
106
+
116
107
class Config :
117
108
extra = "allow"
118
109
@@ -405,7 +396,7 @@ class Config:
405
396
406
397
407
398
# https://swagger.io/specification/#operation-object
408
- class Operation (OpenapiExtensions ):
399
+ class Operation (BaseModel ):
409
400
tags : Optional [List [str ]] = None
410
401
summary : Optional [str ] = None
411
402
description : Optional [str ] = None
@@ -419,12 +410,23 @@ class Operation(OpenapiExtensions):
419
410
deprecated : Optional [bool ] = None
420
411
security : Optional [List [Dict [str , List [str ]]]] = None
421
412
servers : Optional [List [Server ]] = None
413
+ openapi_extensions : Optional [Dict [str , Any ]] = None
422
414
423
415
if PYDANTIC_V2 :
424
416
model_config = {"extra" : "allow" }
425
417
426
418
else :
427
419
420
+ # If the 'openapi_extensions' field is present in the 'values' dictionary,
421
+ # update the 'values' dictionary with the contents of 'openapi_extensions',
422
+ # and then remove the 'openapi_extensions' field from the 'values' dictionary
423
+ @parser_openapi_extension (pre = False , allow_reuse = True )
424
+ def check_json (cls , values ):
425
+ if values .get ("openapi_extensions" ):
426
+ values .update (values ["openapi_extensions" ])
427
+ del values ["openapi_extensions" ]
428
+ return values
429
+
428
430
class Config :
429
431
extra = "allow"
430
432
@@ -462,15 +464,32 @@ class SecuritySchemeType(Enum):
462
464
openIdConnect = "openIdConnect"
463
465
464
466
465
- class SecurityBase (OpenapiExtensions ):
467
+ class SecurityBase (BaseModel ):
466
468
type_ : SecuritySchemeType = Field (alias = "type" )
467
469
description : Optional [str ] = None
470
+ openapi_extensions : Optional [Dict [str , Any ]] = None
468
471
469
472
if PYDANTIC_V2 :
470
473
model_config = {"extra" : "allow" , "populate_by_name" : True }
471
474
475
+ @parser_openapi_extension ()
476
+ def serialize (self ):
477
+ # If the 'openapi_extensions' field is not None, return it
478
+ if self .openapi_extensions :
479
+ return self .openapi_extensions
480
+
472
481
else :
473
482
483
+ # If the 'openapi_extensions' field is present in the 'values' dictionary,
484
+ # update the 'values' dictionary with the contents of 'openapi_extensions',
485
+ # and then remove the 'openapi_extensions' field from the 'values' dictionary
486
+ @parser_openapi_extension (pre = False , allow_reuse = True )
487
+ def check_json (cls , values ):
488
+ if values .get ("openapi_extensions" ):
489
+ values .update (values ["openapi_extensions" ])
490
+ del values ["openapi_extensions" ]
491
+ return values
492
+
474
493
class Config :
475
494
extra = "allow"
476
495
allow_population_by_field_name = True
@@ -560,7 +579,7 @@ class OpenIdConnect(SecurityBase):
560
579
561
580
562
581
# https://swagger.io/specification/#components-object
563
- class Components (OpenapiExtensions ):
582
+ class Components (BaseModel ):
564
583
schemas : Optional [Dict [str , Union [Schema , Reference ]]] = None
565
584
responses : Optional [Dict [str , Union [Response , Reference ]]] = None
566
585
parameters : Optional [Dict [str , Union [Parameter , Reference ]]] = None
@@ -583,7 +602,7 @@ class Config:
583
602
584
603
585
604
# https://swagger.io/specification/#openapi-object
586
- class OpenAPI (OpenapiExtensions ):
605
+ class OpenAPI (BaseModel ):
587
606
openapi : str
588
607
info : Info
589
608
jsonSchemaDialect : Optional [str ] = None
@@ -595,12 +614,23 @@ class OpenAPI(OpenapiExtensions):
595
614
security : Optional [List [Dict [str , List [str ]]]] = None
596
615
tags : Optional [List [Tag ]] = None
597
616
externalDocs : Optional [ExternalDocumentation ] = None
617
+ openapi_extensions : Optional [Dict [str , Any ]] = None
598
618
599
619
if PYDANTIC_V2 :
600
620
model_config = {"extra" : "allow" }
601
621
602
622
else :
603
623
624
+ # If the 'openapi_extensions' field is present in the 'values' dictionary,
625
+ # update the 'values' dictionary with the contents of 'openapi_extensions',
626
+ # and then remove the 'openapi_extensions' field from the 'values' dictionary
627
+ @parser_openapi_extension (pre = False , allow_reuse = True )
628
+ def check_json (cls , values ):
629
+ if values .get ("openapi_extensions" ):
630
+ values .update (values ["openapi_extensions" ])
631
+ del values ["openapi_extensions" ]
632
+ return values
633
+
604
634
class Config :
605
635
extra = "allow"
606
636
0 commit comments