forked from openapi-generators/openapi-python-client
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathheader.py
More file actions
38 lines (30 loc) · 1.54 KB
/
header.py
File metadata and controls
38 lines (30 loc) · 1.54 KB
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
from pydantic import ConfigDict, Field
from ..parameter_location import ParameterLocation
from .parameter import Parameter
class Header(Parameter):
"""
The Header Object follows the structure of the [Parameter Object](#parameterObject) with the following changes:
1. `name` MUST NOT be specified, it is given in the corresponding `headers` map.
2. `in` MUST NOT be specified, it is implicitly in `header`.
3. All traits that are affected by the location MUST be applicable to a location of `header`
(for example, [`style`](#parameterStyle)).
References:
- https://swagger.io/docs/specification/describing-parameters/#header-parameters
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#headerObject
"""
name: str = Field(default="")
param_in: ParameterLocation = Field(default=ParameterLocation.HEADER, alias="in")
model_config = ConfigDict(
extra="allow",
populate_by_name=True,
json_schema_extra={
"examples": [
{"description": "The number of allowed requests in the current period", "schema": {"type": "integer"}}
]
},
)
# Calling model_rebuild() here helps Pydantic to resolve the forward references that were used
# in defining Parameter and Encoding. Without this call, any subtle change to the loading order
# of schema submodules could result in an error like "Parameter is not fully defined".
# See: https://docs.pydantic.dev/latest/concepts/models/#rebuilding-model-schema
Parameter.model_rebuild()