OpenAPI
MODULE | DESCRIPTION |
---|---|
dependant |
|
encoders |
|
exceptions |
|
models |
|
params |
|
swagger_ui |
|
dependant ¶
FUNCTION | DESCRIPTION |
---|---|
add_param_to_fields |
Adds a parameter to the list of parameters in the dependant model. |
get_body_field |
Get the Body field for a given Dependant object. |
get_body_field_info |
Get the Body field info and kwargs for a given body model. |
get_dependant |
Returns a dependant model for a handler function. A dependant model is a model that contains |
get_flat_params |
Get a list of all the parameters from a Dependant object. |
get_path_param_names |
Returns the path parameter names from a path template. Those are the strings between { and }. |
get_typed_annotation |
Evaluates a type annotation, which can be a string or a ForwardRef. |
get_typed_signature |
Returns a typed signature for a callable, resolving forward references. |
is_body_param |
Returns whether a parameter is a request body parameter, by checking if it is a scalar field or a body field. |
add_param_to_fields ¶
add_param_to_fields(
*, field: ModelField, dependant: Dependant
) -> None
Adds a parameter to the list of parameters in the dependant model.
PARAMETER | DESCRIPTION |
---|---|
field
|
The field to add
TYPE:
|
dependant
|
The dependant model to add the field to
TYPE:
|
Source code in aws_lambda_powertools/event_handler/openapi/dependant.py
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 |
|
get_body_field ¶
get_body_field(
*, dependant: Dependant, name: str
) -> ModelField | None
Get the Body field for a given Dependant object.
Source code in aws_lambda_powertools/event_handler/openapi/dependant.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
|
get_body_field_info ¶
get_body_field_info(
*,
body_model: type[BaseModel],
flat_dependant: Dependant,
required: bool
) -> tuple[type[Body], dict[str, Any]]
Get the Body field info and kwargs for a given body model.
Source code in aws_lambda_powertools/event_handler/openapi/dependant.py
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
|
get_dependant ¶
get_dependant(
*,
path: str,
call: Callable[..., Any],
name: str | None = None,
responses: dict[int, OpenAPIResponse] | None = None
) -> Dependant
Returns a dependant model for a handler function. A dependant model is a model that contains the parameters and return value of a handler function.
PARAMETER | DESCRIPTION |
---|---|
path
|
The path template
TYPE:
|
call
|
The handler function |
name
|
The name of the handler function
TYPE:
|
responses
|
The list of extra responses for the handler function |
RETURNS | DESCRIPTION |
---|---|
Dependant
|
The dependant model for the handler function |
Source code in aws_lambda_powertools/event_handler/openapi/dependant.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
|
get_flat_params ¶
get_flat_params(dependant: Dependant) -> list[ModelField]
Get a list of all the parameters from a Dependant object.
PARAMETER | DESCRIPTION |
---|---|
dependant
|
The Dependant object containing the parameters.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list[ModelField]
|
A list of ModelField objects containing the flat parameters from the Dependant object. |
Source code in aws_lambda_powertools/event_handler/openapi/dependant.py
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
|
get_path_param_names ¶
get_path_param_names(path: str) -> set[str]
Returns the path parameter names from a path template. Those are the strings between { and }.
PARAMETER | DESCRIPTION |
---|---|
path
|
The path template
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
set[str]
|
The path parameter names |
Source code in aws_lambda_powertools/event_handler/openapi/dependant.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
|
get_typed_annotation ¶
get_typed_annotation(
annotation: Any, globalns: dict[str, Any]
) -> Any
Evaluates a type annotation, which can be a string or a ForwardRef.
Source code in aws_lambda_powertools/event_handler/openapi/dependant.py
82 83 84 85 86 87 88 89 |
|
get_typed_signature ¶
get_typed_signature(
call: Callable[..., Any],
) -> inspect.Signature
Returns a typed signature for a callable, resolving forward references.
PARAMETER | DESCRIPTION |
---|---|
call
|
The callable to get the signature for |
RETURNS | DESCRIPTION |
---|---|
Signature
|
The typed signature |
Source code in aws_lambda_powertools/event_handler/openapi/dependant.py
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 |
|
is_body_param ¶
is_body_param(
*, param_field: ModelField, is_path_param: bool
) -> bool
Returns whether a parameter is a request body parameter, by checking if it is a scalar field or a body field.
PARAMETER | DESCRIPTION |
---|---|
param_field
|
The parameter field
TYPE:
|
is_path_param
|
Whether the parameter is a path parameter
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether the parameter is a request body parameter |
Source code in aws_lambda_powertools/event_handler/openapi/dependant.py
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
|
encoders ¶
FUNCTION | DESCRIPTION |
---|---|
decimal_encoder |
Encodes a Decimal as int of there's no exponent, otherwise float |
iso_format |
ISO format for date and time |
jsonable_encoder |
JSON encodes an arbitrary Python object into JSON serializable data types. |
decimal_encoder ¶
decimal_encoder(dec_value: Decimal) -> int | float
Encodes a Decimal as int of there's no exponent, otherwise float
This is useful when we use ConstrainedDecimal to represent Numeric(x,0) where an integer (but not int typed) is used. Encoding this as a float results in failed round-tripping between encode and parse.
decimal_encoder(Decimal("1.0")) 1.0
decimal_encoder(Decimal("1")) 1
Source code in aws_lambda_powertools/event_handler/openapi/encoders.py
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
|
iso_format ¶
iso_format(o: datetime.date | datetime.time) -> str
ISO format for date and time
Source code in aws_lambda_powertools/event_handler/openapi/encoders.py
318 319 320 321 322 |
|
jsonable_encoder ¶
jsonable_encoder(
obj: Any,
include: IncEx | None = None,
exclude: IncEx | None = None,
by_alias: bool = True,
exclude_unset: bool = False,
exclude_defaults: bool = False,
exclude_none: bool = False,
custom_serializer: Callable[[Any], str] | None = None,
) -> Any
JSON encodes an arbitrary Python object into JSON serializable data types.
This is a modified version of fastapi.encoders.jsonable_encoder that supports encoding of pydantic.BaseModel objects.
PARAMETER | DESCRIPTION |
---|---|
obj
|
The object to encode
TYPE:
|
include
|
A set or dictionary of strings that specifies which properties should be included, by default None, meaning everything is included
TYPE:
|
exclude
|
A set or dictionary of strings that specifies which properties should be excluded, by default None, meaning nothing is excluded
TYPE:
|
by_alias
|
Whether field aliases should be respected, by default True
TYPE:
|
exclude_unset
|
Whether fields that are not set should be excluded, by default False
TYPE:
|
exclude_defaults
|
Whether fields that are equal to their default value (as specified in the model) should be excluded, by default False
TYPE:
|
exclude_none
|
Whether fields that are equal to None should be excluded, by default False
TYPE:
|
custom_serializer
|
A custom serializer to use for encoding the object, when everything else fails.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Any
|
The JSON serializable data types |
Source code in aws_lambda_powertools/event_handler/openapi/encoders.py
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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
|
exceptions ¶
CLASS | DESCRIPTION |
---|---|
RequestValidationError |
Raised when the request body does not match the OpenAPI schema |
SchemaValidationError |
Raised when the OpenAPI schema validation fails |
SerializationError |
Base exception for all encoding errors |
ValidationException |
Base exception for all validation errors |
RequestValidationError ¶
RequestValidationError(
errors: Sequence[Any], *, body: Any = None
)
Bases: ValidationException
Raised when the request body does not match the OpenAPI schema
Source code in aws_lambda_powertools/event_handler/openapi/exceptions.py
21 22 23 |
|
SchemaValidationError ¶
SchemaValidationError(errors: Sequence[Any])
Bases: ValidationException
Raised when the OpenAPI schema validation fails
Source code in aws_lambda_powertools/event_handler/openapi/exceptions.py
9 10 |
|
models ¶
CLASS | DESCRIPTION |
---|---|
OpenAPIExtensions |
This class serves as a Pydantic proxy model to add OpenAPI extensions. |
ATTRIBUTE | DESCRIPTION |
---|---|
MODEL_CONFIG_IGNORE |
The code defines Pydantic models for the various OpenAPI objects like OpenAPI, PathItem, Operation, Parameter etc.
|
MODEL_CONFIG_IGNORE
module-attribute
¶
MODEL_CONFIG_IGNORE = ConfigDict(extra='ignore')
The code defines Pydantic models for the various OpenAPI objects like OpenAPI, PathItem, Operation, Parameter etc. These models can be used to parse OpenAPI JSON/YAML files into Python objects, or generate OpenAPI from Python data.
OpenAPIExtensions ¶
Bases: BaseModel
This class serves as a Pydantic proxy model to add OpenAPI extensions.
OpenAPI extensions are arbitrary fields, so we remove openapi_extensions when dumping and add only the provided value in the schema.
params ¶
CLASS | DESCRIPTION |
---|---|
Body |
A class used internally to represent a body parameter in a path operation. |
Dependant |
A class used internally to represent a dependency between path operation decorators and the path operation function. |
Header |
A class used internally to represent a header parameter in a path operation. |
Param |
A class used internally to represent a parameter in a path operation. |
Path |
A class used internally to represent a path parameter in a path operation. |
Query |
A class used internally to represent a query parameter in a path operation. |
FUNCTION | DESCRIPTION |
---|---|
analyze_param |
Analyze a parameter annotation and value to determine the type and default value of the parameter. |
create_response_field |
Create a new response field. Raises if type_ is invalid. |
get_field_info_and_type_annotation |
Get the FieldInfo and type annotation from an annotation and value. |
get_field_info_annotated_type |
Get the FieldInfo and type annotation from an Annotated type. |
get_flat_dependant |
Flatten a recursive Dependant model structure. |
Body ¶
Body(
default: Any = Undefined,
*,
default_factory: Callable[[], Any] | None = _Unset,
annotation: Any | None = None,
embed: bool = False,
media_type: str = "application/json",
alias: str | None = None,
alias_priority: int | None = _Unset,
validation_alias: str | None = None,
serialization_alias: str | None = None,
title: str | None = None,
description: str | None = None,
gt: float | None = None,
ge: float | None = None,
lt: float | None = None,
le: float | None = None,
min_length: int | None = None,
max_length: int | None = None,
pattern: str | None = None,
discriminator: str | None = None,
strict: bool | None = _Unset,
multiple_of: float | None = _Unset,
allow_inf_nan: bool | None = _Unset,
max_digits: int | None = _Unset,
decimal_places: int | None = _Unset,
examples: list[Any] | None = None,
deprecated: bool | None = None,
include_in_schema: bool = True,
json_schema_extra: dict[str, Any] | None = None,
**extra: Any
)
Bases: FieldInfo
A class used internally to represent a body parameter in a path operation.
Source code in aws_lambda_powertools/event_handler/openapi/params.py
642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 |
|
Dependant ¶
Dependant(
*,
path_params: list[ModelField] | None = None,
query_params: list[ModelField] | None = None,
header_params: list[ModelField] | None = None,
cookie_params: list[ModelField] | None = None,
body_params: list[ModelField] | None = None,
return_param: ModelField | None = None,
response_extra_models: list[ModelField] | None = None,
name: str | None = None,
call: Callable[..., Any] | None = None,
request_param_name: str | None = None,
websocket_param_name: str | None = None,
http_connection_param_name: str | None = None,
response_param_name: str | None = None,
background_tasks_param_name: str | None = None,
path: str | None = None
)
A class used internally to represent a dependency between path operation decorators and the path operation function.
Source code in aws_lambda_powertools/event_handler/openapi/params.py
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 |
|
Header ¶
Header(
default: Any = Undefined,
*,
default_factory: Callable[[], Any] | None = _Unset,
annotation: Any | None = None,
alias: str | None = None,
alias_priority: int | None = _Unset,
validation_alias: str | None = None,
serialization_alias: str | None = None,
convert_underscores: bool = True,
title: str | None = None,
description: str | None = None,
gt: float | None = None,
ge: float | None = None,
lt: float | None = None,
le: float | None = None,
min_length: int | None = None,
max_length: int | None = None,
pattern: str | None = None,
discriminator: str | None = None,
strict: bool | None = _Unset,
multiple_of: float | None = _Unset,
allow_inf_nan: bool | None = _Unset,
max_digits: int | None = _Unset,
decimal_places: int | None = _Unset,
examples: list[Any] | None = None,
deprecated: bool | None = None,
include_in_schema: bool = True,
json_schema_extra: dict[str, Any] | None = None,
**extra: Any
)
Bases: Param
A class used internally to represent a header parameter in a path operation.
PARAMETER | DESCRIPTION |
---|---|
default
|
The default value of the parameter
TYPE:
|
default_factory
|
Callable that will be called when a default value is needed for this field |
annotation
|
The type annotation of the parameter
TYPE:
|
alias
|
The public name of the field
TYPE:
|
alias_priority
|
Priority of the alias. This affects whether an alias generator is used
TYPE:
|
validation_alias
|
Alias to be used for validation only
TYPE:
|
serialization_alias
|
Alias to be used for serialization only
TYPE:
|
convert_underscores
|
If true convert "_" to "-" See RFC: https://www.rfc-editor.org/rfc/rfc9110.html#name-field-name-registry
TYPE:
|
title
|
The title of the parameter
TYPE:
|
description
|
The description of the parameter
TYPE:
|
gt
|
Only applies to numbers, required the field to be "greater than"
TYPE:
|
ge
|
Only applies to numbers, required the field to be "greater than or equal"
TYPE:
|
lt
|
Only applies to numbers, required the field to be "less than"
TYPE:
|
le
|
Only applies to numbers, required the field to be "less than or equal"
TYPE:
|
min_length
|
Only applies to strings, required the field to have a minimum length
TYPE:
|
max_length
|
Only applies to strings, required the field to have a maximum length
TYPE:
|
pattern
|
Only applies to strings, requires the field match against a regular expression pattern string
TYPE:
|
discriminator
|
Parameter field name for discriminating the type in a tagged union
TYPE:
|
strict
|
Enables Pydantic's strict mode for the field
TYPE:
|
multiple_of
|
Only applies to numbers, requires the field to be a multiple of the given value
TYPE:
|
allow_inf_nan
|
Only applies to numbers, requires the field to allow infinity and NaN values
TYPE:
|
max_digits
|
Only applies to Decimals, requires the field to have a maxmium number of digits within the decimal.
TYPE:
|
decimal_places
|
Only applies to Decimals, requires the field to have at most a number of decimal places
TYPE:
|
examples
|
A list of examples for the parameter |
deprecated
|
If
TYPE:
|
include_in_schema
|
If
TYPE:
|
json_schema_extra
|
Extra values to include in the generated OpenAPI schema |
Source code in aws_lambda_powertools/event_handler/openapi/params.py
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 |
|
Param ¶
Param(
default: Any = Undefined,
*,
default_factory: Callable[[], Any] | None = _Unset,
annotation: Any | None = None,
alias: str | None = None,
alias_priority: int | None = _Unset,
validation_alias: str | None = None,
serialization_alias: str | None = None,
title: str | None = None,
description: str | None = None,
gt: float | None = None,
ge: float | None = None,
lt: float | None = None,
le: float | None = None,
min_length: int | None = None,
max_length: int | None = None,
pattern: str | None = None,
discriminator: str | None = None,
strict: bool | None = _Unset,
multiple_of: float | None = _Unset,
allow_inf_nan: bool | None = _Unset,
max_digits: int | None = _Unset,
decimal_places: int | None = _Unset,
examples: list[Any] | None = None,
deprecated: bool | None = None,
include_in_schema: bool = True,
json_schema_extra: dict[str, Any] | None = None,
**extra: Any
)
Bases: FieldInfo
A class used internally to represent a parameter in a path operation.
PARAMETER | DESCRIPTION |
---|---|
default
|
The default value of the parameter
TYPE:
|
default_factory
|
Callable that will be called when a default value is needed for this field |
annotation
|
The type annotation of the parameter
TYPE:
|
alias
|
The public name of the field
TYPE:
|
alias_priority
|
Priority of the alias. This affects whether an alias generator is used
TYPE:
|
validation_alias
|
Alias to be used for validation only
TYPE:
|
serialization_alias
|
Alias to be used for serialization only
TYPE:
|
title
|
The title of the parameter
TYPE:
|
description
|
The description of the parameter
TYPE:
|
gt
|
Only applies to numbers, required the field to be "greater than"
TYPE:
|
ge
|
Only applies to numbers, required the field to be "greater than or equal"
TYPE:
|
lt
|
Only applies to numbers, required the field to be "less than"
TYPE:
|
le
|
Only applies to numbers, required the field to be "less than or equal"
TYPE:
|
min_length
|
Only applies to strings, required the field to have a minimum length
TYPE:
|
max_length
|
Only applies to strings, required the field to have a maximum length
TYPE:
|
pattern
|
Only applies to strings, requires the field match against a regular expression pattern string
TYPE:
|
discriminator
|
Parameter field name for discriminating the type in a tagged union
TYPE:
|
strict
|
Enables Pydantic's strict mode for the field
TYPE:
|
multiple_of
|
Only applies to numbers, requires the field to be a multiple of the given value
TYPE:
|
allow_inf_nan
|
Only applies to numbers, requires the field to allow infinity and NaN values
TYPE:
|
max_digits
|
Only applies to Decimals, requires the field to have a maxmium number of digits within the decimal.
TYPE:
|
decimal_places
|
Only applies to Decimals, requires the field to have at most a number of decimal places
TYPE:
|
examples
|
A list of examples for the parameter |
deprecated
|
If
TYPE:
|
include_in_schema
|
If
TYPE:
|
json_schema_extra
|
Extra values to include in the generated OpenAPI schema |
Source code in aws_lambda_powertools/event_handler/openapi/params.py
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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|
Path ¶
Path(
default: Any = ...,
*,
default_factory: Callable[[], Any] | None = _Unset,
annotation: Any | None = None,
alias: str | None = None,
alias_priority: int | None = _Unset,
validation_alias: str | None = None,
serialization_alias: str | None = None,
title: str | None = None,
description: str | None = None,
gt: float | None = None,
ge: float | None = None,
lt: float | None = None,
le: float | None = None,
min_length: int | None = None,
max_length: int | None = None,
pattern: str | None = None,
discriminator: str | None = None,
strict: bool | None = _Unset,
multiple_of: float | None = _Unset,
allow_inf_nan: bool | None = _Unset,
max_digits: int | None = _Unset,
decimal_places: int | None = _Unset,
examples: list[Any] | None = None,
deprecated: bool | None = None,
include_in_schema: bool = True,
json_schema_extra: dict[str, Any] | None = None,
**extra: Any
)
Bases: Param
A class used internally to represent a path parameter in a path operation.
PARAMETER | DESCRIPTION |
---|---|
default
|
The default value of the parameter
TYPE:
|
default_factory
|
Callable that will be called when a default value is needed for this field |
annotation
|
The type annotation of the parameter
TYPE:
|
alias
|
The public name of the field
TYPE:
|
alias_priority
|
Priority of the alias. This affects whether an alias generator is used
TYPE:
|
validation_alias
|
Alias to be used for validation only
TYPE:
|
serialization_alias
|
Alias to be used for serialization only
TYPE:
|
title
|
The title of the parameter
TYPE:
|
description
|
The description of the parameter
TYPE:
|
gt
|
Only applies to numbers, required the field to be "greater than"
TYPE:
|
ge
|
Only applies to numbers, required the field to be "greater than or equal"
TYPE:
|
lt
|
Only applies to numbers, required the field to be "less than"
TYPE:
|
le
|
Only applies to numbers, required the field to be "less than or equal"
TYPE:
|
min_length
|
Only applies to strings, required the field to have a minimum length
TYPE:
|
max_length
|
Only applies to strings, required the field to have a maximum length
TYPE:
|
pattern
|
Only applies to strings, requires the field match against a regular expression pattern string
TYPE:
|
discriminator
|
Parameter field name for discriminating the type in a tagged union
TYPE:
|
strict
|
Enables Pydantic's strict mode for the field
TYPE:
|
multiple_of
|
Only applies to numbers, requires the field to be a multiple of the given value
TYPE:
|
allow_inf_nan
|
Only applies to numbers, requires the field to allow infinity and NaN values
TYPE:
|
max_digits
|
Only applies to Decimals, requires the field to have a maxmium number of digits within the decimal.
TYPE:
|
decimal_places
|
Only applies to Decimals, requires the field to have at most a number of decimal places
TYPE:
|
examples
|
A list of examples for the parameter |
deprecated
|
If
TYPE:
|
include_in_schema
|
If
TYPE:
|
json_schema_extra
|
Extra values to include in the generated OpenAPI schema |
Source code in aws_lambda_powertools/event_handler/openapi/params.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
|
Query ¶
Query(
default: Any = _Unset,
*,
default_factory: Callable[[], Any] | None = _Unset,
annotation: Any | None = None,
alias: str | None = None,
alias_priority: int | None = _Unset,
validation_alias: str | None = None,
serialization_alias: str | None = None,
title: str | None = None,
description: str | None = None,
gt: float | None = None,
ge: float | None = None,
lt: float | None = None,
le: float | None = None,
min_length: int | None = None,
max_length: int | None = None,
pattern: str | None = None,
discriminator: str | None = None,
strict: bool | None = _Unset,
multiple_of: float | None = _Unset,
allow_inf_nan: bool | None = _Unset,
max_digits: int | None = _Unset,
decimal_places: int | None = _Unset,
examples: list[Any] | None = None,
deprecated: bool | None = None,
include_in_schema: bool = True,
json_schema_extra: dict[str, Any] | None = None,
**extra: Any
)
Bases: Param
A class used internally to represent a query parameter in a path operation.
PARAMETER | DESCRIPTION |
---|---|
default
|
The default value of the parameter
TYPE:
|
default_factory
|
Callable that will be called when a default value is needed for this field |
annotation
|
The type annotation of the parameter
TYPE:
|
alias
|
The public name of the field
TYPE:
|
alias_priority
|
Priority of the alias. This affects whether an alias generator is used
TYPE:
|
validation_alias
|
Alias to be used for validation only
TYPE:
|
serialization_alias
|
Alias to be used for serialization only
TYPE:
|
title
|
The title of the parameter
TYPE:
|
description
|
The description of the parameter
TYPE:
|
gt
|
Only applies to numbers, required the field to be "greater than"
TYPE:
|
ge
|
Only applies to numbers, required the field to be "greater than or equal"
TYPE:
|
lt
|
Only applies to numbers, required the field to be "less than"
TYPE:
|
le
|
Only applies to numbers, required the field to be "less than or equal"
TYPE:
|
min_length
|
Only applies to strings, required the field to have a minimum length
TYPE:
|
max_length
|
Only applies to strings, required the field to have a maximum length
TYPE:
|
pattern
|
Only applies to strings, requires the field match against a regular expression pattern string
TYPE:
|
discriminator
|
Parameter field name for discriminating the type in a tagged union
TYPE:
|
strict
|
Enables Pydantic's strict mode for the field
TYPE:
|
multiple_of
|
Only applies to numbers, requires the field to be a multiple of the given value
TYPE:
|
allow_inf_nan
|
Only applies to numbers, requires the field to allow infinity and NaN values
TYPE:
|
max_digits
|
Only applies to Decimals, requires the field to have a maxmium number of digits within the decimal.
TYPE:
|
decimal_places
|
Only applies to Decimals, requires the field to have at most a number of decimal places
TYPE:
|
examples
|
A list of examples for the parameter |
deprecated
|
If
TYPE:
|
include_in_schema
|
If
TYPE:
|
json_schema_extra
|
Extra values to include in the generated OpenAPI schema |
Source code in aws_lambda_powertools/event_handler/openapi/params.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 |
|
analyze_param ¶
analyze_param(
*,
param_name: str,
annotation: Any,
value: Any,
is_path_param: bool,
is_response_param: bool
) -> ModelField | None
Analyze a parameter annotation and value to determine the type and default value of the parameter.
PARAMETER | DESCRIPTION |
---|---|
param_name
|
The name of the parameter
TYPE:
|
annotation
|
The annotation of the parameter
TYPE:
|
value
|
The value of the parameter
TYPE:
|
is_path_param
|
Whether the parameter is a path parameter
TYPE:
|
is_response_param
|
Whether the parameter is the return annotation
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ModelField | None
|
The type annotation and the Pydantic field representing the parameter |
Source code in aws_lambda_powertools/event_handler/openapi/params.py
904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 |
|
create_response_field ¶
create_response_field(
name: str,
type_: type[Any],
default: Any | None = Undefined,
required: bool | UndefinedType = Undefined,
model_config: type[BaseConfig] = BaseConfig,
field_info: FieldInfo | None = None,
alias: str | None = None,
mode: Literal[
"validation", "serialization"
] = "validation",
) -> ModelField
Create a new response field. Raises if type_ is invalid.
Source code in aws_lambda_powertools/event_handler/openapi/params.py
1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 |
|
get_field_info_and_type_annotation ¶
get_field_info_and_type_annotation(
annotation,
value,
is_path_param: bool,
is_response_param: bool,
) -> tuple[FieldInfo | None, Any]
Get the FieldInfo and type annotation from an annotation and value.
Source code in aws_lambda_powertools/event_handler/openapi/params.py
965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 |
|
get_field_info_annotated_type ¶
get_field_info_annotated_type(
annotation, value, is_path_param: bool
) -> tuple[FieldInfo | None, Any]
Get the FieldInfo and type annotation from an Annotated type.
Source code in aws_lambda_powertools/event_handler/openapi/params.py
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 |
|
get_flat_dependant ¶
get_flat_dependant(
dependant: Dependant,
visited: list[CacheKey] | None = None,
) -> Dependant
Flatten a recursive Dependant model structure.
This function recursively concatenates the parameter fields of a Dependant model and its dependencies into a flat Dependant structure. This is useful for scenarios like parameter validation where the nested structure is not relevant.
PARAMETER | DESCRIPTION |
---|---|
dependant
|
The dependant model to flatten
TYPE:
|
visited
|
Keeps track of visited Dependents to avoid infinite recursion. Defaults to empty list.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Dependant
|
The flattened Dependant model |
Source code in aws_lambda_powertools/event_handler/openapi/params.py
867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 |
|
swagger_ui ¶
MODULE | DESCRIPTION |
---|---|
html |
|
oauth2 |
|
CLASS | DESCRIPTION |
---|---|
OAuth2Config |
OAuth2 configuration for Swagger UI |
FUNCTION | DESCRIPTION |
---|---|
generate_oauth2_redirect_html |
Generates the HTML content for the OAuth2 redirect page. |
generate_swagger_html |
Generate Swagger UI HTML page |
OAuth2Config ¶
Bases: BaseModel
OAuth2 configuration for Swagger UI
generate_oauth2_redirect_html ¶
generate_oauth2_redirect_html() -> str
Generates the HTML content for the OAuth2 redirect page.
Source: https://github.com/swagger-api/swagger-ui/blob/master/dist/oauth2-redirect.html
Source code in aws_lambda_powertools/event_handler/openapi/swagger_ui/oauth2.py
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 143 144 145 146 147 148 149 150 151 152 153 154 |
|
generate_swagger_html ¶
generate_swagger_html(
spec: str,
swagger_js: str,
swagger_css: str,
swagger_base_url: str,
oauth2_config: OAuth2Config | None,
persist_authorization: bool = False,
) -> str
Generate Swagger UI HTML page
PARAMETER | DESCRIPTION |
---|---|
spec
|
The OpenAPI spec
TYPE:
|
swagger_js
|
Swagger UI JavaScript source code or URL
TYPE:
|
swagger_css
|
Swagger UI CSS source code or URL
TYPE:
|
swagger_base_url
|
The base URL for Swagger UI
TYPE:
|
oauth2_config
|
The OAuth2 configuration.
TYPE:
|
persist_authorization
|
Whether to persist authorization data on browser close/refresh.
TYPE:
|
Source code in aws_lambda_powertools/event_handler/openapi/swagger_ui/html.py
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 |
|
html ¶
FUNCTION | DESCRIPTION |
---|---|
generate_swagger_html |
Generate Swagger UI HTML page |
generate_swagger_html ¶
generate_swagger_html(
spec: str,
swagger_js: str,
swagger_css: str,
swagger_base_url: str,
oauth2_config: OAuth2Config | None,
persist_authorization: bool = False,
) -> str
Generate Swagger UI HTML page
PARAMETER | DESCRIPTION |
---|---|
spec
|
The OpenAPI spec
TYPE:
|
swagger_js
|
Swagger UI JavaScript source code or URL
TYPE:
|
swagger_css
|
Swagger UI CSS source code or URL
TYPE:
|
swagger_base_url
|
The base URL for Swagger UI
TYPE:
|
oauth2_config
|
The OAuth2 configuration.
TYPE:
|
persist_authorization
|
Whether to persist authorization data on browser close/refresh.
TYPE:
|
Source code in aws_lambda_powertools/event_handler/openapi/swagger_ui/html.py
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 |
|
oauth2 ¶
CLASS | DESCRIPTION |
---|---|
OAuth2Config |
OAuth2 configuration for Swagger UI |
FUNCTION | DESCRIPTION |
---|---|
generate_oauth2_redirect_html |
Generates the HTML content for the OAuth2 redirect page. |
OAuth2Config ¶
Bases: BaseModel
OAuth2 configuration for Swagger UI
generate_oauth2_redirect_html ¶
generate_oauth2_redirect_html() -> str
Generates the HTML content for the OAuth2 redirect page.
Source: https://github.com/swagger-api/swagger-ui/blob/master/dist/oauth2-redirect.html
Source code in aws_lambda_powertools/event_handler/openapi/swagger_ui/oauth2.py
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 143 144 145 146 147 148 149 150 151 152 153 154 |
|