Skip to content

Commit 1a4945d

Browse files
fix(event-handler): restore accidentally removed comments in openapi/models.py
fix(event-handler): restore accidentally removed comments in openapi/models.py Signed-off-by: hirenkumar-n-dholariya <hirenkumarnd@gmail.com>
1 parent adbbc5a commit 1a4945d

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

  • aws_lambda_powertools/event_handler/openapi

aws_lambda_powertools/event_handler/openapi/models.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# ruff: noqa: FA100
2+
# ruff: noqa: FA100
23
from enum import Enum
34
from typing import Any, Literal, Union
45

@@ -27,6 +28,10 @@ class OpenAPIExtensions(BaseModel):
2728

2829
openapi_extensions: dict[str, Any] | None = None
2930

31+
# If the 'openapi_extensions' field is present in the 'values' dictionary,
32+
# And if the extension starts with x- (must respect the RFC)
33+
# update the 'values' dictionary with the contents of 'openapi_extensions',
34+
# and then remove the 'openapi_extensions' field from the 'values' dictionary
3035
# If the 'openapi_extensions' field is present in the 'values' dictionary,
3136
# And if the extension starts with x- (must respect the RFC)
3237
# update the 'values' dictionary with the contents of 'openapi_extensions',
@@ -48,6 +53,7 @@ def serialize_openapi_extension_v2(self):
4853
return self
4954

5055

56+
# https://swagger.io/specification/#contact-object
5157
class Contact(BaseModel):
5258
name: str | None = None
5359
url: AnyUrl | None = None
@@ -56,6 +62,7 @@ class Contact(BaseModel):
5662
model_config = MODEL_CONFIG_ALLOW
5763

5864

65+
# https://swagger.io/specification/#license-object
5966
class License(BaseModel):
6067
name: str
6168
identifier: str | None = None
@@ -64,6 +71,7 @@ class License(BaseModel):
6471
model_config = MODEL_CONFIG_ALLOW
6572

6673

74+
# https://swagger.io/specification/#info-object
6775
class Info(BaseModel):
6876
title: str
6977
description: str | None = None
@@ -76,6 +84,7 @@ class Info(BaseModel):
7684
model_config = MODEL_CONFIG_IGNORE
7785

7886

87+
# https://swagger.io/specification/#server-variable-object
7988
class ServerVariable(BaseModel):
8089
enum: Annotated[list[str] | None, Field(min_length=1)] = None
8190
default: str
@@ -84,6 +93,7 @@ class ServerVariable(BaseModel):
8493
model_config = MODEL_CONFIG_ALLOW
8594

8695

96+
# https://swagger.io/specification/#server-object
8797
class Server(OpenAPIExtensions):
8898
url: Union[AnyUrl, str]
8999
description: str | None = None
@@ -92,15 +102,18 @@ class Server(OpenAPIExtensions):
92102
model_config = MODEL_CONFIG_ALLOW
93103

94104

105+
# https://swagger.io/specification/#reference-object
95106
class Reference(BaseModel):
96107
ref: str = Field(alias="$ref")
97108

98109

110+
# https://swagger.io/specification/#discriminator-object
99111
class Discriminator(BaseModel):
100112
propertyName: str
101113
mapping: dict[str, str] | None = None
102114

103115

116+
# https://swagger.io/specification/#xml-object
104117
class XML(BaseModel):
105118
name: str | None = None
106119
namespace: str | None = None
@@ -111,14 +124,18 @@ class XML(BaseModel):
111124
model_config = MODEL_CONFIG_ALLOW
112125

113126

127+
# https://swagger.io/specification/#external-documentation-object
114128
class ExternalDocumentation(BaseModel):
115129
description: str | None = None
116130
url: AnyUrl
117131

118132
model_config = MODEL_CONFIG_ALLOW
119133

120134

135+
# https://swagger.io/specification/#schema-object
121136
class Schema(BaseModel):
137+
# Ref: JSON Schema 2020-12: https://json-schema.org/draft/2020-12/json-schema-core.html#name-the-json-schema-core-vocabu
138+
# Core Vocabulary
122139
schema_: str | None = Field(default=None, alias="$schema")
123140
vocabulary: str | None = Field(default=None, alias="$vocabulary")
124141
id: str | None = Field(default=None, alias="$id") # noqa: A003
@@ -128,6 +145,8 @@ class Schema(BaseModel):
128145
dynamicRef: str | None = Field(default=None, alias="$dynamicRef")
129146
defs: dict[str, "SchemaOrBool"] | None = Field(default=None, alias="$defs")
130147
comment: str | None = Field(default=None, alias="$comment")
148+
# Ref: JSON Schema 2020-12: https://json-schema.org/draft/2020-12/json-schema-core.html#name-a-vocabulary-for-applying-s
149+
# A Vocabulary for Applying Subschemas
131150
allOf: list["SchemaOrBool"] | None = None
132151
anyOf: list["SchemaOrBool"] | None = None
133152
oneOf: list["SchemaOrBool"] | None = None
@@ -139,12 +158,17 @@ class Schema(BaseModel):
139158
prefixItems: list["SchemaOrBool"] | None = None
140159
items: Union["SchemaOrBool", list["SchemaOrBool"]] | None = None
141160
contains: "SchemaOrBool | None" = None
161+
# MAINTENANCE: uncomment and remove below when deprecating Pydantic v1
162+
# MAINTENANCE: It generates a list of schemas for tuples, before prefixItems was available
163+
# MAINTENANCE: items: Optional["SchemaOrBool"] = None
142164
properties: dict[str, "SchemaOrBool"] | None = None
143165
patternProperties: dict[str, "SchemaOrBool"] | None = None
144166
additionalProperties: "SchemaOrBool | None" = None
145167
propertyNames: "SchemaOrBool | None" = None
146168
unevaluatedItems: "SchemaOrBool | None" = None
147169
unevaluatedProperties: "SchemaOrBool | None" = None
170+
# Ref: JSON Schema Validation 2020-12: https://json-schema.org/draft/2020-12/json-schema-validation.html#name-a-vocabulary-for-structural
171+
# A Vocabulary for Structural Validation
148172
type: str | None = None # noqa: A003
149173
enum: list[Any] | None = None
150174
const: Any | None = None
@@ -165,27 +189,38 @@ class Schema(BaseModel):
165189
minProperties: int | None = Field(default=None, ge=0)
166190
required: list[str] | None = None
167191
dependentRequired: dict[str, set[str]] | None = None
192+
# Ref: JSON Schema Validation 2020-12: https://json-schema.org/draft/2020-12/json-schema-validation.html#name-vocabularies-for-semantic-c
193+
# Vocabularies for Semantic Content With "format"
168194
format: str | None = None # noqa: A003
195+
# Ref: JSON Schema Validation 2020-12: https://json-schema.org/draft/2020-12/json-schema-validation.html#name-a-vocabulary-for-the-conten
196+
# A Vocabulary for the Contents of String-Encoded Data
169197
contentEncoding: str | None = None
170198
contentMediaType: str | None = None
171199
contentSchema: "SchemaOrBool | None" = None
200+
# Ref: JSON Schema Validation 2020-12: https://json-schema.org/draft/2020-12/json-schema-validation.html#name-a-vocabulary-for-basic-meta
201+
# A Vocabulary for Basic Meta-Data Annotations
172202
title: str | None = None
173203
description: str | None = None
174204
default: Any | None = None
175205
deprecated: bool | None = None
176206
readOnly: bool | None = None
177207
writeOnly: bool | None = None
178208
examples: list[Any] | None = None
209+
# Ref: OpenAPI 3.0.0: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#schema-object
210+
# Schema Object
179211
discriminator: Discriminator | None = None
180212
xml: XML | None = None
181213
externalDocs: ExternalDocumentation | None = None
182214

183215
model_config = MODEL_CONFIG_ALLOW
184216

185217

218+
# Ref: https://json-schema.org/draft/2020-12/json-schema-core.html#name-json-schema-documents
219+
# A JSON Schema MUST be an object or a boolean.
186220
SchemaOrBool = Union[Schema, bool]
187221

188222

223+
# https://swagger.io/specification/#example-object
189224
class Example(BaseModel):
190225
summary: str | None = None
191226
description: str | None = None
@@ -202,6 +237,7 @@ class ParameterInType(Enum):
202237
cookie = "cookie"
203238

204239

240+
# https://swagger.io/specification/#encoding-object
205241
class Encoding(BaseModel):
206242
contentType: str | None = None
207243
headers: dict[str, Union["Header", Reference]] | None = None
@@ -212,6 +248,7 @@ class Encoding(BaseModel):
212248
model_config = MODEL_CONFIG_ALLOW
213249

214250

251+
# https://swagger.io/specification/#media-type-object
215252
class MediaType(BaseModel):
216253
schema_: Union[Schema, Reference] | None = Field(default=None, alias="schema")
217254
examples: dict[str, Union[Example, Reference]] | None = None
@@ -220,15 +257,18 @@ class MediaType(BaseModel):
220257
model_config = MODEL_CONFIG_ALLOW
221258

222259

260+
# https://swagger.io/specification/#parameter-object
223261
class ParameterBase(BaseModel):
224262
description: str | None = None
225263
required: bool | None = None
226264
deprecated: bool | None = None
265+
# Serialization rules for simple scenarios
227266
style: str | None = None
228267
explode: bool | None = None
229268
allowReserved: bool | None = None
230269
schema_: Union[Schema, Reference] | None = Field(default=None, alias="schema")
231270
examples: dict[str, Union[Example, Reference]] | None = None
271+
# Serialization rules for more complex scenarios
232272
content: dict[str, MediaType] | None = None
233273

234274
model_config = MODEL_CONFIG_ALLOW
@@ -243,6 +283,7 @@ class Header(ParameterBase):
243283
pass
244284

245285

286+
# https://swagger.io/specification/#request-body-object
246287
class RequestBody(BaseModel):
247288
description: str | None = None
248289
content: dict[str, MediaType]
@@ -251,6 +292,7 @@ class RequestBody(BaseModel):
251292
model_config = MODEL_CONFIG_ALLOW
252293

253294

295+
# https://swagger.io/specification/#link-object
254296
class Link(BaseModel):
255297
operationRef: str | None = None
256298
operationId: str | None = None
@@ -262,6 +304,7 @@ class Link(BaseModel):
262304
model_config = MODEL_CONFIG_ALLOW
263305

264306

307+
# https://swagger.io/specification/#response-object
265308
class Response(BaseModel):
266309
description: str
267310
headers: dict[str, Union[Header, Reference]] | None = None
@@ -271,6 +314,7 @@ class Response(BaseModel):
271314
model_config = MODEL_CONFIG_ALLOW
272315

273316

317+
# https://swagger.io/specification/#tag-object
274318
class Tag(BaseModel):
275319
name: str
276320
description: str | None = None
@@ -279,6 +323,7 @@ class Tag(BaseModel):
279323
model_config = MODEL_CONFIG_ALLOW
280324

281325

326+
# https://swagger.io/specification/#operation-object
282327
class Operation(OpenAPIExtensions):
283328
tags: list[str] | None = None
284329
summary: str | None = None
@@ -289,13 +334,15 @@ class Operation(OpenAPIExtensions):
289334
requestBody: Union[RequestBody, Reference] | None = None
290335
responses: dict[int, Union[Response, Any]] | None = None
291336
callbacks: dict[str, Union[dict[str, "PathItem"], Reference]] | None = None
337+
# Using Any for Specification Extensions
292338
deprecated: bool | None = None
293339
security: list[dict[str, list[str]]] | None = None
294340
servers: list[Server] | None = None
295341

296342
model_config = MODEL_CONFIG_ALLOW
297343

298344

345+
# https://swagger.io/specification/#path-item-object
299346
class PathItem(BaseModel):
300347
ref: str | None = Field(default=None, alias="$ref")
301348
summary: str | None = None
@@ -314,6 +361,7 @@ class PathItem(BaseModel):
314361
model_config = MODEL_CONFIG_ALLOW
315362

316363

364+
# https://swagger.io/specification/#security-scheme-object
317365
class SecuritySchemeType(Enum):
318366
apiKey = "apiKey"
319367
http = "http"
@@ -404,6 +452,7 @@ class MutualTLS(SecurityBase):
404452
SecurityScheme = Union[APIKey, HTTPBase, OAuth2, OpenIdConnect, HTTPBearer, MutualTLS]
405453

406454

455+
# https://swagger.io/specification/#components-object
407456
class Components(BaseModel):
408457
schemas: dict[str, Union[Schema, Reference]] | None = None
409458
responses: dict[str, Union[Response, Reference]] | None = None
@@ -416,16 +465,19 @@ class Components(BaseModel):
416465
callbacks: dict[str, Union[dict[str, PathItem], Reference, Any]] | None = None
417466
pathItems: dict[str, Union[PathItem, Reference]] | None = None
418467

468+
# Using Any for Specification Extensions
419469
model_config = MODEL_CONFIG_ALLOW
420470

421471

472+
# https://swagger.io/specification/#openapi-object
422473
class OpenAPI(OpenAPIExtensions):
423474
openapi: str
424475
info: Info
425476
jsonSchemaDialect: str | None = None
426477
servers: list[Server] | None = None
427478
paths: dict[str, Union[PathItem, Any]] | None = None
428479
webhooks: dict[str, Union[PathItem, Reference]] | None = None
480+
# Using Any for Specification Extensions
429481
components: Components | None = None
430482
security: list[dict[str, list[str]]] | None = None
431483
tags: list[Tag] | None = None

0 commit comments

Comments
 (0)