openapi-python-client 0.28.4__py3-none-any.whl → 0.29.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- openapi_python_client/__init__.py +26 -17
- openapi_python_client/cli.py +1 -2
- openapi_python_client/config.py +5 -3
- openapi_python_client/parser/bodies.py +14 -23
- openapi_python_client/parser/openapi.py +58 -48
- openapi_python_client/parser/properties/__init__.py +34 -33
- openapi_python_client/parser/properties/any.py +11 -10
- openapi_python_client/parser/properties/boolean.py +13 -13
- openapi_python_client/parser/properties/const.py +11 -10
- openapi_python_client/parser/properties/date.py +15 -14
- openapi_python_client/parser/properties/datetime.py +15 -14
- openapi_python_client/parser/properties/enum_property.py +23 -20
- openapi_python_client/parser/properties/file.py +11 -10
- openapi_python_client/parser/properties/float.py +13 -13
- openapi_python_client/parser/properties/int.py +11 -11
- openapi_python_client/parser/properties/list_property.py +22 -22
- openapi_python_client/parser/properties/literal_enum_property.py +20 -20
- openapi_python_client/parser/properties/merge_properties.py +9 -6
- openapi_python_client/parser/properties/model_property.py +34 -33
- openapi_python_client/parser/properties/none.py +11 -11
- openapi_python_client/parser/properties/protocol.py +42 -32
- openapi_python_client/parser/properties/schemas.py +30 -23
- openapi_python_client/parser/properties/string.py +10 -11
- openapi_python_client/parser/properties/union.py +24 -22
- openapi_python_client/parser/properties/uuid.py +11 -11
- openapi_python_client/parser/responses.py +30 -23
- openapi_python_client/schema/__init__.py +2 -1
- openapi_python_client/schema/data_type.py +2 -2
- openapi_python_client/schema/openapi_schema_pydantic/callback.py +3 -1
- openapi_python_client/schema/openapi_schema_pydantic/components.py +10 -9
- openapi_python_client/schema/openapi_schema_pydantic/contact.py +5 -3
- openapi_python_client/schema/openapi_schema_pydantic/discriminator.py +4 -2
- openapi_python_client/schema/openapi_schema_pydantic/encoding.py +4 -3
- openapi_python_client/schema/openapi_schema_pydantic/example.py +5 -3
- openapi_python_client/schema/openapi_schema_pydantic/external_documentation.py +4 -2
- openapi_python_client/schema/openapi_schema_pydantic/header.py +20 -6
- openapi_python_client/schema/openapi_schema_pydantic/info.py +5 -4
- openapi_python_client/schema/openapi_schema_pydantic/license.py +4 -2
- openapi_python_client/schema/openapi_schema_pydantic/link.py +5 -4
- openapi_python_client/schema/openapi_schema_pydantic/media_type.py +3 -2
- openapi_python_client/schema/openapi_schema_pydantic/oauth_flow.py +6 -4
- openapi_python_client/schema/openapi_schema_pydantic/open_api.py +5 -3
- openapi_python_client/schema/openapi_schema_pydantic/operation.py +6 -5
- openapi_python_client/schema/openapi_schema_pydantic/parameter.py +6 -5
- openapi_python_client/schema/openapi_schema_pydantic/path_item.py +5 -3
- openapi_python_client/schema/openapi_schema_pydantic/paths.py +2 -1
- openapi_python_client/schema/openapi_schema_pydantic/reference.py +3 -1
- openapi_python_client/schema/openapi_schema_pydantic/request_body.py +3 -2
- openapi_python_client/schema/openapi_schema_pydantic/response.py +5 -4
- openapi_python_client/schema/openapi_schema_pydantic/responses.py +2 -1
- openapi_python_client/schema/openapi_schema_pydantic/schema.py +7 -6
- openapi_python_client/schema/openapi_schema_pydantic/security_requirement.py +3 -1
- openapi_python_client/schema/openapi_schema_pydantic/security_scheme.py +8 -7
- openapi_python_client/schema/openapi_schema_pydantic/server.py +4 -3
- openapi_python_client/schema/openapi_schema_pydantic/server_variable.py +5 -3
- openapi_python_client/schema/openapi_schema_pydantic/tag.py +3 -2
- openapi_python_client/schema/openapi_schema_pydantic/xml.py +5 -3
- openapi_python_client/schema/parameter_location.py +7 -22
- openapi_python_client/schema/ref.py +52 -0
- openapi_python_client/schema/untrusted_string.py +56 -0
- openapi_python_client/strings.py +245 -0
- openapi_python_client/templates/README.md.jinja +3 -3
- openapi_python_client/templates/client.py.jinja +5 -5
- openapi_python_client/templates/endpoint_macros.py.jinja +18 -18
- openapi_python_client/templates/endpoint_module.py.jinja +20 -14
- openapi_python_client/templates/helpers.jinja +3 -7
- openapi_python_client/templates/literal_enum.py.jinja +3 -3
- openapi_python_client/templates/model.py.jinja +18 -18
- openapi_python_client/templates/package_init.py.jinja +2 -2
- openapi_python_client/templates/property_templates/const_property.py.jinja +3 -3
- openapi_python_client/templates/property_templates/date_property.py.jinja +2 -2
- openapi_python_client/templates/property_templates/datetime_property.py.jinja +2 -2
- openapi_python_client/templates/property_templates/enum_property.py.jinja +1 -1
- openapi_python_client/templates/property_templates/file_property.py.jinja +1 -1
- openapi_python_client/templates/property_templates/list_property.py.jinja +3 -3
- openapi_python_client/templates/property_templates/literal_enum_property.py.jinja +2 -2
- openapi_python_client/templates/property_templates/model_property.py.jinja +1 -1
- openapi_python_client/templates/property_templates/property_macros.py.jinja +1 -1
- openapi_python_client/templates/property_templates/union_property.py.jinja +9 -9
- openapi_python_client/templates/property_templates/uuid_property.py.jinja +1 -1
- openapi_python_client/templates/pyproject_pdm.toml.jinja +4 -5
- openapi_python_client/templates/pyproject_poetry.toml.jinja +4 -5
- openapi_python_client/templates/pyproject_uv.toml.jinja +5 -6
- openapi_python_client/templates/setup.py.jinja +4 -4
- openapi_python_client/templates/str_enum.py.jinja +2 -2
- {openapi_python_client-0.28.4.dist-info → openapi_python_client-0.29.1.dist-info}/METADATA +6 -9
- openapi_python_client-0.29.1.dist-info/RECORD +115 -0
- {openapi_python_client-0.28.4.dist-info → openapi_python_client-0.29.1.dist-info}/WHEEL +1 -1
- openapi_python_client/utils.py +0 -122
- openapi_python_client-0.28.4.dist-info/RECORD +0 -113
- {openapi_python_client-0.28.4.dist-info → openapi_python_client-0.29.1.dist-info}/entry_points.txt +0 -0
- {openapi_python_client-0.28.4.dist-info → openapi_python_client-0.29.1.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from pydantic import BaseModel, ConfigDict, field_validator
|
|
2
2
|
|
|
3
|
+
from ..untrusted_string import UntrustedString
|
|
3
4
|
from .components import Components
|
|
4
5
|
from .external_documentation import ExternalDocumentation
|
|
5
6
|
from .info import Info
|
|
@@ -26,7 +27,7 @@ class OpenAPI(BaseModel):
|
|
|
26
27
|
security: list[SecurityRequirement] | None = None
|
|
27
28
|
tags: list[Tag] | None = None
|
|
28
29
|
externalDocs: ExternalDocumentation | None = None
|
|
29
|
-
openapi:
|
|
30
|
+
openapi: UntrustedString
|
|
30
31
|
model_config = ConfigDict(
|
|
31
32
|
# `Components` is not build yet, will rebuild in `__init__.py`:
|
|
32
33
|
defer_build=True,
|
|
@@ -35,8 +36,9 @@ class OpenAPI(BaseModel):
|
|
|
35
36
|
|
|
36
37
|
@field_validator("openapi")
|
|
37
38
|
@classmethod
|
|
38
|
-
def check_openapi_version(cls,
|
|
39
|
+
def check_openapi_version(cls, untrusted: UntrustedString) -> UntrustedString:
|
|
39
40
|
"""Validates that the declared OpenAPI version is a supported one"""
|
|
41
|
+
value = untrusted.get_untrusted_value()
|
|
40
42
|
parts = value.split(".")
|
|
41
43
|
if len(parts) != NUM_SEMVER_PARTS:
|
|
42
44
|
raise ValueError(f"Invalid OpenAPI version {value}")
|
|
@@ -44,4 +46,4 @@ class OpenAPI(BaseModel):
|
|
|
44
46
|
raise ValueError(f"Only OpenAPI versions 3.* are supported, got {value}")
|
|
45
47
|
if int(parts[1]) > 1:
|
|
46
48
|
raise ValueError(f"Only OpenAPI versions 3.1.* are supported, got {value}")
|
|
47
|
-
return
|
|
49
|
+
return untrusted
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from pydantic import BaseModel, ConfigDict, Field
|
|
2
2
|
|
|
3
|
+
from ..untrusted_string import UntrustedString
|
|
3
4
|
from .callback import Callback
|
|
4
5
|
from .external_documentation import ExternalDocumentation
|
|
5
6
|
from .parameter import Parameter
|
|
@@ -18,15 +19,15 @@ class Operation(BaseModel):
|
|
|
18
19
|
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#operationObject
|
|
19
20
|
"""
|
|
20
21
|
|
|
21
|
-
tags: list[
|
|
22
|
-
summary:
|
|
23
|
-
description:
|
|
22
|
+
tags: list[UntrustedString] | None = None
|
|
23
|
+
summary: UntrustedString | None = None
|
|
24
|
+
description: UntrustedString | None = None
|
|
24
25
|
externalDocs: ExternalDocumentation | None = None
|
|
25
|
-
operationId:
|
|
26
|
+
operationId: UntrustedString | None = None
|
|
26
27
|
parameters: list[ReferenceOr[Parameter]] | None = None
|
|
27
28
|
request_body: ReferenceOr[RequestBody] | None = Field(None, alias="requestBody")
|
|
28
29
|
responses: Responses
|
|
29
|
-
callbacks: dict[
|
|
30
|
+
callbacks: dict[UntrustedString, Callback] | None = None
|
|
30
31
|
|
|
31
32
|
deprecated: bool = False
|
|
32
33
|
security: list[SecurityRequirement] | None = None
|
|
@@ -3,6 +3,7 @@ from typing import Any
|
|
|
3
3
|
from pydantic import BaseModel, ConfigDict, Field
|
|
4
4
|
|
|
5
5
|
from ..parameter_location import ParameterLocation
|
|
6
|
+
from ..untrusted_string import UntrustedString
|
|
6
7
|
from .example import Example
|
|
7
8
|
from .media_type import MediaType
|
|
8
9
|
from .reference import ReferenceOr
|
|
@@ -21,19 +22,19 @@ class Parameter(BaseModel):
|
|
|
21
22
|
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterObject
|
|
22
23
|
"""
|
|
23
24
|
|
|
24
|
-
name:
|
|
25
|
+
name: UntrustedString
|
|
25
26
|
param_in: ParameterLocation = Field(alias="in")
|
|
26
|
-
description:
|
|
27
|
+
description: UntrustedString | None = None
|
|
27
28
|
required: bool = False
|
|
28
29
|
deprecated: bool = False
|
|
29
30
|
allowEmptyValue: bool = False
|
|
30
|
-
style:
|
|
31
|
+
style: UntrustedString | None = None
|
|
31
32
|
explode: bool = False
|
|
32
33
|
allowReserved: bool = False
|
|
33
34
|
param_schema: ReferenceOr[Schema] | None = Field(default=None, alias="schema")
|
|
34
35
|
example: Any | None = None
|
|
35
|
-
examples: dict[
|
|
36
|
-
content: dict[
|
|
36
|
+
examples: dict[UntrustedString, ReferenceOr[Example]] | None = None
|
|
37
|
+
content: dict[UntrustedString, MediaType] | None = None
|
|
37
38
|
model_config = ConfigDict(
|
|
38
39
|
# `MediaType` is not build yet, will rebuild in `__init__.py`:
|
|
39
40
|
defer_build=True,
|
|
@@ -2,6 +2,8 @@ from typing import TYPE_CHECKING
|
|
|
2
2
|
|
|
3
3
|
from pydantic import BaseModel, ConfigDict, Field
|
|
4
4
|
|
|
5
|
+
from ..ref import Ref
|
|
6
|
+
from ..untrusted_string import UntrustedString
|
|
5
7
|
from .parameter import Parameter
|
|
6
8
|
from .reference import ReferenceOr
|
|
7
9
|
from .server import Server
|
|
@@ -22,9 +24,9 @@ class PathItem(BaseModel):
|
|
|
22
24
|
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#pathItemObject
|
|
23
25
|
"""
|
|
24
26
|
|
|
25
|
-
ref:
|
|
26
|
-
summary:
|
|
27
|
-
description:
|
|
27
|
+
ref: Ref | None = Field(default=None, alias="$ref")
|
|
28
|
+
summary: UntrustedString | None = None
|
|
29
|
+
description: UntrustedString | None = None
|
|
28
30
|
get: "Operation | None" = None
|
|
29
31
|
put: "Operation | None" = None
|
|
30
32
|
post: "Operation | None" = None
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
from ..untrusted_string import UntrustedString
|
|
1
2
|
from .path_item import PathItem
|
|
2
3
|
|
|
3
|
-
Paths = dict[
|
|
4
|
+
Paths = dict[UntrustedString, PathItem]
|
|
4
5
|
"""
|
|
5
6
|
Holds the relative paths to the individual endpoints and their operations.
|
|
6
7
|
The path is appended to the URL from the [`Server Object`](#serverObject) in order to construct the full URL.
|
|
@@ -2,6 +2,8 @@ from typing import Annotated, Any, Literal, TypeAlias, TypeVar
|
|
|
2
2
|
|
|
3
3
|
from pydantic import BaseModel, ConfigDict, Discriminator, Field, Tag
|
|
4
4
|
|
|
5
|
+
from openapi_python_client.schema.ref import Ref
|
|
6
|
+
|
|
5
7
|
|
|
6
8
|
class Reference(BaseModel):
|
|
7
9
|
"""
|
|
@@ -18,7 +20,7 @@ class Reference(BaseModel):
|
|
|
18
20
|
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#referenceObject
|
|
19
21
|
"""
|
|
20
22
|
|
|
21
|
-
ref:
|
|
23
|
+
ref: Ref = Field(alias="$ref")
|
|
22
24
|
model_config = ConfigDict(
|
|
23
25
|
extra="allow",
|
|
24
26
|
populate_by_name=True,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from pydantic import BaseModel, ConfigDict
|
|
2
2
|
|
|
3
|
+
from ..untrusted_string import UntrustedString
|
|
3
4
|
from .media_type import MediaType
|
|
4
5
|
|
|
5
6
|
|
|
@@ -11,8 +12,8 @@ class RequestBody(BaseModel):
|
|
|
11
12
|
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#requestBodyObject
|
|
12
13
|
"""
|
|
13
14
|
|
|
14
|
-
description:
|
|
15
|
-
content: dict[
|
|
15
|
+
description: UntrustedString | None = None
|
|
16
|
+
content: dict[UntrustedString, MediaType]
|
|
16
17
|
required: bool = False
|
|
17
18
|
model_config = ConfigDict(
|
|
18
19
|
# `MediaType` is not build yet, will rebuild in `__init__.py`:
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from pydantic import BaseModel, ConfigDict
|
|
2
2
|
|
|
3
|
+
from ..untrusted_string import UntrustedString
|
|
3
4
|
from .header import Header
|
|
4
5
|
from .link import Link
|
|
5
6
|
from .media_type import MediaType
|
|
@@ -16,10 +17,10 @@ class Response(BaseModel):
|
|
|
16
17
|
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#responseObject
|
|
17
18
|
"""
|
|
18
19
|
|
|
19
|
-
description:
|
|
20
|
-
headers: dict[
|
|
21
|
-
content: dict[
|
|
22
|
-
links: dict[
|
|
20
|
+
description: UntrustedString
|
|
21
|
+
headers: dict[UntrustedString, ReferenceOr[Header]] | None = None
|
|
22
|
+
content: dict[UntrustedString, MediaType] | None = None
|
|
23
|
+
links: dict[UntrustedString, ReferenceOr[Link]] | None = None
|
|
23
24
|
model_config = ConfigDict(
|
|
24
25
|
# `MediaType` is not build yet, will rebuild in `__init__.py`:
|
|
25
26
|
defer_build=True,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
from ..untrusted_string import UntrustedString
|
|
1
2
|
from .reference import ReferenceOr
|
|
2
3
|
from .response import Response
|
|
3
4
|
|
|
4
|
-
Responses = dict[
|
|
5
|
+
Responses = dict[UntrustedString, ReferenceOr[Response]]
|
|
5
6
|
"""
|
|
6
7
|
A container for the expected responses of an operation.
|
|
7
8
|
The container maps a HTTP response code to the expected response.
|
|
@@ -3,6 +3,7 @@ from typing import Any
|
|
|
3
3
|
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictFloat, StrictInt, StrictStr, model_validator
|
|
4
4
|
|
|
5
5
|
from ..data_type import DataType
|
|
6
|
+
from ..untrusted_string import UntrustedString
|
|
6
7
|
from .discriminator import Discriminator
|
|
7
8
|
from .external_documentation import ExternalDocumentation
|
|
8
9
|
from .reference import ReferenceOr
|
|
@@ -20,7 +21,7 @@ class Schema(BaseModel):
|
|
|
20
21
|
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schemaObject
|
|
21
22
|
"""
|
|
22
23
|
|
|
23
|
-
title:
|
|
24
|
+
title: UntrustedString | None = None
|
|
24
25
|
multipleOf: float | None = Field(default=None, gt=0.0)
|
|
25
26
|
maximum: float | None = None
|
|
26
27
|
exclusiveMaximum: bool | float | None = None
|
|
@@ -28,13 +29,13 @@ class Schema(BaseModel):
|
|
|
28
29
|
exclusiveMinimum: bool | float | None = None
|
|
29
30
|
maxLength: int | None = Field(default=None, ge=0)
|
|
30
31
|
minLength: int | None = Field(default=None, ge=0)
|
|
31
|
-
pattern:
|
|
32
|
+
pattern: UntrustedString | None = None
|
|
32
33
|
maxItems: int | None = Field(default=None, ge=0)
|
|
33
34
|
minItems: int | None = Field(default=None, ge=0)
|
|
34
35
|
uniqueItems: bool | None = None
|
|
35
36
|
maxProperties: int | None = Field(default=None, ge=0)
|
|
36
37
|
minProperties: int | None = Field(default=None, ge=0)
|
|
37
|
-
required: list[
|
|
38
|
+
required: list[UntrustedString] | None = Field(default=None)
|
|
38
39
|
enum: None | list[Any] = Field(default=None, min_length=1)
|
|
39
40
|
const: None | StrictStr | StrictInt | StrictFloat | StrictBool = None
|
|
40
41
|
type: DataType | list[DataType] | None = Field(default=None)
|
|
@@ -44,10 +45,10 @@ class Schema(BaseModel):
|
|
|
44
45
|
schema_not: ReferenceOr["Schema"] | None = Field(default=None, alias="not")
|
|
45
46
|
items: ReferenceOr["Schema"] | None = None
|
|
46
47
|
prefixItems: list[ReferenceOr["Schema"]] = Field(default_factory=list)
|
|
47
|
-
properties: dict[
|
|
48
|
+
properties: dict[UntrustedString, ReferenceOr["Schema"]] | None = None
|
|
48
49
|
additionalProperties: bool | ReferenceOr["Schema"] | None = None
|
|
49
|
-
description:
|
|
50
|
-
schema_format:
|
|
50
|
+
description: UntrustedString | None = None
|
|
51
|
+
schema_format: UntrustedString | None = Field(default=None, alias="format")
|
|
51
52
|
default: Any | None = None
|
|
52
53
|
nullable: bool = Field(default=False)
|
|
53
54
|
discriminator: Discriminator | None = None
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
from ..untrusted_string import UntrustedString
|
|
2
|
+
|
|
3
|
+
SecurityRequirement = dict[UntrustedString, list[UntrustedString]]
|
|
2
4
|
"""
|
|
3
5
|
Lists the required security schemes to execute this operation.
|
|
4
6
|
The name used for each property MUST correspond to a security scheme declared in the
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from pydantic import BaseModel, ConfigDict, Field
|
|
2
2
|
|
|
3
|
+
from ..untrusted_string import UntrustedString
|
|
3
4
|
from .oauth_flows import OAuthFlows
|
|
4
5
|
|
|
5
6
|
|
|
@@ -17,14 +18,14 @@ class SecurityScheme(BaseModel):
|
|
|
17
18
|
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#componentsObject
|
|
18
19
|
"""
|
|
19
20
|
|
|
20
|
-
type:
|
|
21
|
-
description:
|
|
22
|
-
name:
|
|
23
|
-
security_scheme_in:
|
|
24
|
-
scheme:
|
|
25
|
-
bearerFormat:
|
|
21
|
+
type: UntrustedString
|
|
22
|
+
description: UntrustedString | None = None
|
|
23
|
+
name: UntrustedString | None = None
|
|
24
|
+
security_scheme_in: UntrustedString | None = Field(default=None, alias="in")
|
|
25
|
+
scheme: UntrustedString | None = None
|
|
26
|
+
bearerFormat: UntrustedString | None = None
|
|
26
27
|
flows: OAuthFlows | None = None
|
|
27
|
-
openIdConnectUrl:
|
|
28
|
+
openIdConnectUrl: UntrustedString | None = None
|
|
28
29
|
model_config = ConfigDict(
|
|
29
30
|
extra="allow",
|
|
30
31
|
populate_by_name=True,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from pydantic import BaseModel, ConfigDict
|
|
2
2
|
|
|
3
|
+
from ..untrusted_string import UntrustedString
|
|
3
4
|
from .server_variable import ServerVariable
|
|
4
5
|
|
|
5
6
|
|
|
@@ -11,9 +12,9 @@ class Server(BaseModel):
|
|
|
11
12
|
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#serverObject
|
|
12
13
|
"""
|
|
13
14
|
|
|
14
|
-
url:
|
|
15
|
-
description:
|
|
16
|
-
variables: dict[
|
|
15
|
+
url: UntrustedString
|
|
16
|
+
description: UntrustedString | None = None
|
|
17
|
+
variables: dict[UntrustedString, ServerVariable] | None = None
|
|
17
18
|
model_config = ConfigDict(
|
|
18
19
|
extra="allow",
|
|
19
20
|
json_schema_extra={
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
from pydantic import BaseModel, ConfigDict
|
|
2
2
|
|
|
3
|
+
from ..untrusted_string import UntrustedString
|
|
4
|
+
|
|
3
5
|
|
|
4
6
|
class ServerVariable(BaseModel):
|
|
5
7
|
"""An object representing a Server Variable for server URL template substitution.
|
|
@@ -9,7 +11,7 @@ class ServerVariable(BaseModel):
|
|
|
9
11
|
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#serverVariableObject
|
|
10
12
|
"""
|
|
11
13
|
|
|
12
|
-
enum: list[
|
|
13
|
-
default:
|
|
14
|
-
description:
|
|
14
|
+
enum: list[UntrustedString] | None = None
|
|
15
|
+
default: UntrustedString
|
|
16
|
+
description: UntrustedString | None = None
|
|
15
17
|
model_config = ConfigDict(extra="allow")
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from pydantic import BaseModel, ConfigDict
|
|
2
2
|
|
|
3
|
+
from ..untrusted_string import UntrustedString
|
|
3
4
|
from .external_documentation import ExternalDocumentation
|
|
4
5
|
|
|
5
6
|
|
|
@@ -13,8 +14,8 @@ class Tag(BaseModel):
|
|
|
13
14
|
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#tagObject
|
|
14
15
|
"""
|
|
15
16
|
|
|
16
|
-
name:
|
|
17
|
-
description:
|
|
17
|
+
name: UntrustedString
|
|
18
|
+
description: UntrustedString | None = None
|
|
18
19
|
externalDocs: ExternalDocumentation | None = None
|
|
19
20
|
model_config = ConfigDict(
|
|
20
21
|
extra="allow", json_schema_extra={"examples": [{"name": "pet", "description": "Pets operations"}]}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
from pydantic import BaseModel, ConfigDict
|
|
2
2
|
|
|
3
|
+
from ..untrusted_string import UntrustedString
|
|
4
|
+
|
|
3
5
|
|
|
4
6
|
class XML(BaseModel):
|
|
5
7
|
"""
|
|
@@ -14,9 +16,9 @@ class XML(BaseModel):
|
|
|
14
16
|
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#xmlObject
|
|
15
17
|
"""
|
|
16
18
|
|
|
17
|
-
name:
|
|
18
|
-
namespace:
|
|
19
|
-
prefix:
|
|
19
|
+
name: UntrustedString | None = None
|
|
20
|
+
namespace: UntrustedString | None = None
|
|
21
|
+
prefix: UntrustedString | None = None
|
|
20
22
|
attribute: bool = False
|
|
21
23
|
wrapped: bool = False
|
|
22
24
|
model_config = ConfigDict(
|
|
@@ -1,25 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
# Unless this gets fixed, we need to have two implementations :(
|
|
3
|
-
import sys
|
|
1
|
+
from enum import StrEnum
|
|
4
2
|
|
|
5
|
-
if sys.version_info >= (3, 11):
|
|
6
|
-
from enum import StrEnum
|
|
7
3
|
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
class ParameterLocation(StrEnum):
|
|
5
|
+
"""The places Parameters can be put when calling an Endpoint"""
|
|
10
6
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
else:
|
|
17
|
-
from enum import Enum
|
|
18
|
-
|
|
19
|
-
class ParameterLocation(str, Enum):
|
|
20
|
-
"""The places Parameters can be put when calling an Endpoint"""
|
|
21
|
-
|
|
22
|
-
QUERY = "query"
|
|
23
|
-
PATH = "path"
|
|
24
|
-
HEADER = "header"
|
|
25
|
-
COOKIE = "cookie"
|
|
7
|
+
QUERY = "query"
|
|
8
|
+
PATH = "path"
|
|
9
|
+
HEADER = "header"
|
|
10
|
+
COOKIE = "cookie"
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
from pydantic import GetCoreSchemaHandler
|
|
4
|
+
from pydantic_core import core_schema
|
|
5
|
+
|
|
6
|
+
from .untrusted_string import UntrustedString
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Ref:
|
|
10
|
+
"""A $ref in the schema, the raw value is protected to make sure we don't accidentally place it in the generated code."""
|
|
11
|
+
|
|
12
|
+
def __init__(self, value: str | UntrustedString) -> None:
|
|
13
|
+
if isinstance(value, UntrustedString):
|
|
14
|
+
value = value.get_untrusted_value()
|
|
15
|
+
self._value = value
|
|
16
|
+
|
|
17
|
+
@classmethod
|
|
18
|
+
def __get_pydantic_core_schema__(cls, _source_type: Any, _handler: GetCoreSchemaHandler) -> core_schema.CoreSchema:
|
|
19
|
+
return core_schema.no_info_after_validator_function(
|
|
20
|
+
cls,
|
|
21
|
+
core_schema.str_schema(),
|
|
22
|
+
serialization=core_schema.plain_serializer_function_ser_schema(
|
|
23
|
+
cls._serialize, info_arg=True, return_schema=core_schema.any_schema()
|
|
24
|
+
),
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
@staticmethod
|
|
28
|
+
def _serialize(value: "Ref", info: core_schema.SerializationInfo) -> Any:
|
|
29
|
+
# Only unwrap in JSON mode (used for error messages); Python mode keeps the wrapper so it
|
|
30
|
+
# can't leak into generated code. Returning the wrapper also avoids serializer warnings.
|
|
31
|
+
if info.mode == "json":
|
|
32
|
+
return value.get_untrusted_value()
|
|
33
|
+
return value
|
|
34
|
+
|
|
35
|
+
def get_untrusted_value(self) -> str:
|
|
36
|
+
"""
|
|
37
|
+
Get the raw $ref value.
|
|
38
|
+
|
|
39
|
+
DO NOT place this in generated code.
|
|
40
|
+
"""
|
|
41
|
+
return self._value
|
|
42
|
+
|
|
43
|
+
def endswith(self, suffix: str) -> bool:
|
|
44
|
+
return self._value.endswith(suffix)
|
|
45
|
+
|
|
46
|
+
def __hash__(self) -> int:
|
|
47
|
+
return hash(self._value)
|
|
48
|
+
|
|
49
|
+
def __eq__(self, other: object) -> bool:
|
|
50
|
+
if isinstance(other, Ref):
|
|
51
|
+
return self._value == other._value
|
|
52
|
+
return False # pragma: no cover
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
from typing import Any, TypeVar
|
|
2
|
+
|
|
3
|
+
from pydantic import GetCoreSchemaHandler
|
|
4
|
+
from pydantic_core import CoreSchema, core_schema
|
|
5
|
+
|
|
6
|
+
T = TypeVar("T")
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class UntrustedString:
|
|
10
|
+
"""A raw string in the OpenAPI document which should not be directly placed in the generated code."""
|
|
11
|
+
|
|
12
|
+
def __init__(self, value: str) -> None:
|
|
13
|
+
self._value = value
|
|
14
|
+
|
|
15
|
+
@classmethod
|
|
16
|
+
def __get_pydantic_core_schema__(cls, _source_type: Any, _handler: GetCoreSchemaHandler) -> CoreSchema:
|
|
17
|
+
return core_schema.no_info_after_validator_function(
|
|
18
|
+
cls,
|
|
19
|
+
core_schema.str_schema(),
|
|
20
|
+
serialization=core_schema.plain_serializer_function_ser_schema(
|
|
21
|
+
cls._serialize, info_arg=True, return_schema=core_schema.any_schema()
|
|
22
|
+
),
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
@staticmethod
|
|
26
|
+
def _serialize(value: "UntrustedString", info: core_schema.SerializationInfo) -> Any:
|
|
27
|
+
# Only unwrap in JSON mode (used for error messages); Python mode keeps the wrapper so it
|
|
28
|
+
# can't leak into generated code. Returning the wrapper also avoids serializer warnings.
|
|
29
|
+
if info.mode == "json":
|
|
30
|
+
return value.get_untrusted_value()
|
|
31
|
+
return value
|
|
32
|
+
|
|
33
|
+
def get_untrusted_value(self) -> str:
|
|
34
|
+
"""
|
|
35
|
+
Return the raw string with no transformations.
|
|
36
|
+
|
|
37
|
+
DO NOT use this for generating code directly. It can result in arbitrary code generation.
|
|
38
|
+
"""
|
|
39
|
+
return self._value
|
|
40
|
+
|
|
41
|
+
def startswith(self, prefix: str) -> bool:
|
|
42
|
+
return self._value.startswith(prefix)
|
|
43
|
+
|
|
44
|
+
def __bool__(self) -> bool:
|
|
45
|
+
"""Whether the raw value is non-empty. Emptiness is not sensitive, so this is safe to expose."""
|
|
46
|
+
return bool(self._value)
|
|
47
|
+
|
|
48
|
+
def __hash__(self) -> int:
|
|
49
|
+
return hash(self._value)
|
|
50
|
+
|
|
51
|
+
def __eq__(self, other: object) -> bool:
|
|
52
|
+
if isinstance(other, UntrustedString):
|
|
53
|
+
return self._value == other._value
|
|
54
|
+
if isinstance(other, str):
|
|
55
|
+
return self._value == other
|
|
56
|
+
return False
|