hypothesis-openapi 0.2.0__tar.gz → 0.3.0__tar.gz
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.
- {hypothesis_openapi-0.2.0 → hypothesis_openapi-0.3.0}/PKG-INFO +13 -9
- {hypothesis_openapi-0.2.0 → hypothesis_openapi-0.3.0}/pyproject.toml +36 -24
- {hypothesis_openapi-0.2.0 → hypothesis_openapi-0.3.0}/src/hypothesis_openapi/_common.py +27 -12
- {hypothesis_openapi-0.2.0 → hypothesis_openapi-0.3.0}/src/hypothesis_openapi/_serialize.py +1 -1
- {hypothesis_openapi-0.2.0 → hypothesis_openapi-0.3.0}/src/hypothesis_openapi/_strategies.py +3 -1
- {hypothesis_openapi-0.2.0 → hypothesis_openapi-0.3.0}/src/hypothesis_openapi/_types.py +1 -1
- {hypothesis_openapi-0.2.0 → hypothesis_openapi-0.3.0}/src/hypothesis_openapi/_v2.py +35 -6
- hypothesis_openapi-0.3.0/src/hypothesis_openapi/_v3.py +143 -0
- hypothesis_openapi-0.2.0/src/hypothesis_openapi/_v3.py +0 -74
- {hypothesis_openapi-0.2.0 → hypothesis_openapi-0.3.0}/.gitignore +0 -0
- {hypothesis_openapi-0.2.0 → hypothesis_openapi-0.3.0}/LICENSE +0 -0
- {hypothesis_openapi-0.2.0 → hypothesis_openapi-0.3.0}/README.md +0 -0
- {hypothesis_openapi-0.2.0 → hypothesis_openapi-0.3.0}/src/hypothesis_openapi/__init__.py +0 -0
- {hypothesis_openapi-0.2.0 → hypothesis_openapi-0.3.0}/src/hypothesis_openapi/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: hypothesis-openapi
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Hypothesis plugin for generating valid Open API documents
|
|
5
5
|
Project-URL: Changelog, https://github.com/Stranger6667/hypothesis-openapi/blob/main/CHANGELOG.md
|
|
6
6
|
Project-URL: Bug Tracker, https://github.com/Stranger6667/hypothesis-openapi
|
|
@@ -21,12 +21,14 @@ Classifier: Programming Language :: Python :: 3 :: Only
|
|
|
21
21
|
Classifier: Programming Language :: Python :: 3.10
|
|
22
22
|
Classifier: Programming Language :: Python :: 3.11
|
|
23
23
|
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
24
26
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
25
27
|
Classifier: Topic :: Software Development :: Testing
|
|
26
28
|
Requires-Python: >=3.10
|
|
27
|
-
Requires-Dist: hypothesis<7
|
|
29
|
+
Requires-Dist: hypothesis<7,>=6.108.0
|
|
28
30
|
Provides-Extra: bench
|
|
29
|
-
Requires-Dist: pytest-codspeed==
|
|
31
|
+
Requires-Dist: pytest-codspeed==4.2.0; extra == 'bench'
|
|
30
32
|
Provides-Extra: cov
|
|
31
33
|
Requires-Dist: coverage-enable-subprocess; extra == 'cov'
|
|
32
34
|
Requires-Dist: coverage[toml]>=7; extra == 'cov'
|
|
@@ -35,14 +37,16 @@ Requires-Dist: coverage-enable-subprocess; extra == 'dev'
|
|
|
35
37
|
Requires-Dist: coverage>=7; extra == 'dev'
|
|
36
38
|
Requires-Dist: coverage[toml]>=7; extra == 'dev'
|
|
37
39
|
Requires-Dist: jsonschema>=4.21.0; extra == 'dev'
|
|
38
|
-
Requires-Dist: pytest-codspeed==
|
|
39
|
-
Requires-Dist: pytest-xdist<
|
|
40
|
-
Requires-Dist: pytest<8
|
|
40
|
+
Requires-Dist: pytest-codspeed==4.2.0; extra == 'dev'
|
|
41
|
+
Requires-Dist: pytest-xdist<4.0,>=3; extra == 'dev'
|
|
42
|
+
Requires-Dist: pytest<10,>=8; extra == 'dev'
|
|
43
|
+
Requires-Dist: referencing>=0.35; extra == 'dev'
|
|
41
44
|
Provides-Extra: tests
|
|
42
45
|
Requires-Dist: coverage>=7; extra == 'tests'
|
|
43
46
|
Requires-Dist: jsonschema>=4.21.0; extra == 'tests'
|
|
44
|
-
Requires-Dist: pytest-xdist<
|
|
45
|
-
Requires-Dist: pytest<8
|
|
47
|
+
Requires-Dist: pytest-xdist<4.0,>=3; extra == 'tests'
|
|
48
|
+
Requires-Dist: pytest<10,>=8; extra == 'tests'
|
|
49
|
+
Requires-Dist: referencing>=0.35; extra == 'tests'
|
|
46
50
|
Description-Content-Type: text/markdown
|
|
47
51
|
|
|
48
52
|
# hypothesis-openapi
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "hypothesis-openapi"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.3.0"
|
|
4
4
|
description = "Hypothesis plugin for generating valid Open API documents"
|
|
5
5
|
keywords = ["hypothesis", "openapi", "testing"]
|
|
6
6
|
classifiers = [
|
|
@@ -14,6 +14,8 @@ classifiers = [
|
|
|
14
14
|
"Programming Language :: Python :: 3.10",
|
|
15
15
|
"Programming Language :: Python :: 3.11",
|
|
16
16
|
"Programming Language :: Python :: 3.12",
|
|
17
|
+
"Programming Language :: Python :: 3.13",
|
|
18
|
+
"Programming Language :: Python :: 3.14",
|
|
17
19
|
"Programming Language :: Python :: Implementation :: CPython",
|
|
18
20
|
"Topic :: Software Development :: Testing",
|
|
19
21
|
]
|
|
@@ -24,22 +26,23 @@ license = "MIT"
|
|
|
24
26
|
include = ["src/hypothesis_openapi/py.typed"]
|
|
25
27
|
requires-python = ">=3.10"
|
|
26
28
|
dependencies = [
|
|
27
|
-
"hypothesis>=6.
|
|
29
|
+
"hypothesis>=6.108.0,<7",
|
|
28
30
|
]
|
|
29
31
|
|
|
30
32
|
[project.optional-dependencies]
|
|
31
33
|
tests = [
|
|
32
34
|
"coverage>=7",
|
|
33
35
|
"jsonschema>=4.21.0",
|
|
34
|
-
"
|
|
35
|
-
"pytest
|
|
36
|
+
"referencing>=0.35",
|
|
37
|
+
"pytest>=8,<10",
|
|
38
|
+
"pytest-xdist>=3,<4.0",
|
|
36
39
|
]
|
|
37
40
|
cov = [
|
|
38
41
|
"coverage-enable-subprocess",
|
|
39
42
|
"coverage[toml]>=7",
|
|
40
43
|
]
|
|
41
44
|
bench = [
|
|
42
|
-
"pytest-codspeed==
|
|
45
|
+
"pytest-codspeed==4.2.0",
|
|
43
46
|
]
|
|
44
47
|
dev = ["hypothesis_openapi[tests,cov,bench]"]
|
|
45
48
|
|
|
@@ -79,27 +82,32 @@ target-version = "py310"
|
|
|
79
82
|
|
|
80
83
|
[tool.ruff.lint]
|
|
81
84
|
select = [
|
|
82
|
-
"E",
|
|
83
|
-
"W",
|
|
84
|
-
"F",
|
|
85
|
-
"C",
|
|
86
|
-
"B",
|
|
87
|
-
"D",
|
|
85
|
+
"E", # pycodestyle errors
|
|
86
|
+
"W", # pycodestyle warnings
|
|
87
|
+
"F", # pyflakes
|
|
88
|
+
"C", # flake8-comprehensions
|
|
89
|
+
"B", # flake8-bugbear
|
|
90
|
+
"D", # pydocstyle
|
|
91
|
+
"I", # isort
|
|
92
|
+
"UP", # pyupgrade
|
|
93
|
+
"FURB", # refurb
|
|
94
|
+
"PGH003", # blanket-type-ignore
|
|
88
95
|
]
|
|
89
96
|
ignore = [
|
|
90
|
-
"E501",
|
|
91
|
-
"B008",
|
|
92
|
-
"C901",
|
|
93
|
-
"D100",
|
|
94
|
-
"D101",
|
|
95
|
-
"D102",
|
|
96
|
-
"D103",
|
|
97
|
-
"D104",
|
|
98
|
-
"D105",
|
|
99
|
-
"D107",
|
|
100
|
-
"D203",
|
|
101
|
-
"D213",
|
|
102
|
-
"D401",
|
|
97
|
+
"E501", # Line too long
|
|
98
|
+
"B008", # Do not perform function calls in argument defaults
|
|
99
|
+
"C901", # Too complex
|
|
100
|
+
"D100", # Missing docstring in public module
|
|
101
|
+
"D101", # Missing docstring in public class
|
|
102
|
+
"D102", # Missing docstring in public method
|
|
103
|
+
"D103", # Missing docstring in public function
|
|
104
|
+
"D104", # Missing docstring in public package
|
|
105
|
+
"D105", # Missing docstring in magic method
|
|
106
|
+
"D107", # Missing docstring in `__init__`
|
|
107
|
+
"D203", # One blank line before class
|
|
108
|
+
"D213", # Multiline summary second line
|
|
109
|
+
"D401", # Imperative mood
|
|
110
|
+
"COM812", # trailing comma
|
|
103
111
|
]
|
|
104
112
|
|
|
105
113
|
[tool.ruff.format]
|
|
@@ -107,6 +115,10 @@ skip-magic-trailing-comma = false
|
|
|
107
115
|
|
|
108
116
|
[tool.ruff.lint.per-file-ignores]
|
|
109
117
|
"__init__.py" = ["F401"]
|
|
118
|
+
# _v2.py/_v3.py use dict literals inside type annotations as a Hypothesis strategy trick;
|
|
119
|
+
# FURB rules can corrupt these by removing quotes from string keys.
|
|
120
|
+
"_v2.py" = ["FURB"]
|
|
121
|
+
"_v3.py" = ["FURB"]
|
|
110
122
|
|
|
111
123
|
[tool.ruff.lint.isort]
|
|
112
124
|
known-first-party = ["hypothesis_openapi"]
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
from dataclasses import dataclass
|
|
3
3
|
from typing import Any, Literal
|
|
4
4
|
|
|
5
|
+
DEFAULT_SECURITY_SCHEME = "DefaultApiKey"
|
|
6
|
+
|
|
5
7
|
|
|
6
8
|
@dataclass
|
|
7
9
|
class Info:
|
|
@@ -16,27 +18,40 @@ class PathItemReference:
|
|
|
16
18
|
return value
|
|
17
19
|
|
|
18
20
|
|
|
19
|
-
@dataclass
|
|
20
|
-
class ParameterReference:
|
|
21
|
-
def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
|
|
22
|
-
value["$ref"] = "#/parameters/SampleParameter"
|
|
23
|
-
return value
|
|
24
|
-
|
|
25
|
-
def __hash__(self) -> int:
|
|
26
|
-
return hash(("$ref", "#/parameters/SampleParameter"))
|
|
27
|
-
|
|
28
|
-
|
|
29
21
|
@dataclass
|
|
30
22
|
class Response:
|
|
31
23
|
description: Literal["Ok"]
|
|
32
24
|
|
|
33
25
|
|
|
34
26
|
@dataclass
|
|
35
|
-
class
|
|
27
|
+
class ApiKeyScheme:
|
|
28
|
+
name: str
|
|
29
|
+
in_: Literal["header", "query"]
|
|
30
|
+
|
|
36
31
|
def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
|
|
37
|
-
value["
|
|
32
|
+
value["type"] = "apiKey"
|
|
33
|
+
value["in"] = value.pop("in_")
|
|
38
34
|
return value
|
|
39
35
|
|
|
40
36
|
|
|
37
|
+
@dataclass
|
|
38
|
+
class OperationSecurityRequirement:
|
|
39
|
+
def map_value(self, value: dict[str, Any]) -> list:
|
|
40
|
+
return [{DEFAULT_SECURITY_SCHEME: []}]
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def reference(ref: str) -> type:
|
|
44
|
+
@dataclass
|
|
45
|
+
class ReferenceValue:
|
|
46
|
+
def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
|
|
47
|
+
value["$ref"] = ref
|
|
48
|
+
return value
|
|
49
|
+
|
|
50
|
+
def __hash__(self) -> int:
|
|
51
|
+
return hash(("$ref", ref))
|
|
52
|
+
|
|
53
|
+
return ReferenceValue
|
|
54
|
+
|
|
55
|
+
|
|
41
56
|
RESPONSE_SUCCESS = {"description": "OK"}
|
|
42
57
|
PATH_ITEM_SAMPLE = {"get": {"responses": {"default": RESPONSE_SUCCESS}}}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
from typing import Any, Literal
|
|
2
|
+
|
|
2
3
|
from hypothesis import strategies as st
|
|
4
|
+
|
|
5
|
+
from ._serialize import asdict
|
|
3
6
|
from ._v2 import Swagger
|
|
4
7
|
from ._v3 import OpenApi30
|
|
5
|
-
from ._serialize import asdict
|
|
6
8
|
|
|
7
9
|
|
|
8
10
|
def openapis(version: Literal["2.0"] | Literal["3.0"] | Literal["3.1"]) -> "st.SearchStrategy[dict[str, Any]]":
|
|
@@ -5,18 +5,30 @@ from dataclasses import dataclass, field
|
|
|
5
5
|
from typing import Any, Literal, TypeAlias
|
|
6
6
|
|
|
7
7
|
from ._common import (
|
|
8
|
+
DEFAULT_SECURITY_SCHEME,
|
|
8
9
|
PATH_ITEM_SAMPLE,
|
|
9
10
|
RESPONSE_SUCCESS,
|
|
11
|
+
ApiKeyScheme,
|
|
10
12
|
Info,
|
|
11
|
-
|
|
13
|
+
OperationSecurityRequirement,
|
|
12
14
|
PathItemReference,
|
|
13
15
|
Response,
|
|
14
|
-
|
|
16
|
+
reference,
|
|
15
17
|
)
|
|
16
18
|
from ._types import CombinedDict, Missing, Pattern, UniqueList
|
|
17
19
|
|
|
18
20
|
PARAMETER_SAMPLE = {"name": "sample", "in": "query", "type": "string"}
|
|
19
21
|
ResponseId: TypeAlias = Pattern[r"^([0-9]{3})$|^(default)\Z"] # type: ignore[type-arg,valid-type]
|
|
22
|
+
ParameterReference = reference("#/parameters/SampleParameter")
|
|
23
|
+
ResponseReference = reference("#/responses/Success")
|
|
24
|
+
|
|
25
|
+
# Named dicts used as CombinedDict defaults — must NOT be inline dict literals inside
|
|
26
|
+
# annotations, as ruff transforms {"Key": val} → {Key: val} (undefined name) in that context.
|
|
27
|
+
_PARAMETER_DEFAULTS = {"SampleParameter": PARAMETER_SAMPLE}
|
|
28
|
+
_RESPONSE_DEFAULTS = {"Success": RESPONSE_SUCCESS}
|
|
29
|
+
_SECURITY_DEFAULTS = {DEFAULT_SECURITY_SCHEME: {"type": "apiKey", "name": "X-Api-Key", "in": "header"}}
|
|
30
|
+
|
|
31
|
+
SecurityScheme = ApiKeyScheme
|
|
20
32
|
|
|
21
33
|
MediaType = (
|
|
22
34
|
Literal["application/json"]
|
|
@@ -38,9 +50,10 @@ class Swagger:
|
|
|
38
50
|
paths: dict[Pattern["^/"], PathItem | PathItemReference] # type: ignore[type-arg,valid-type]
|
|
39
51
|
consumes: MediaTypeList | Missing
|
|
40
52
|
produces: MediaTypeList | Missing
|
|
41
|
-
parameters: CombinedDict[str, Parameter,
|
|
42
|
-
responses: CombinedDict[ResponseId, Response,
|
|
53
|
+
parameters: CombinedDict[str, Parameter, _PARAMETER_DEFAULTS] # type: ignore[type-arg,valid-type]
|
|
54
|
+
responses: CombinedDict[ResponseId, Response, _RESPONSE_DEFAULTS] # type: ignore[type-arg,valid-type]
|
|
43
55
|
definitions: Definitions
|
|
56
|
+
securityDefinitions: CombinedDict[str, SecurityScheme, _SECURITY_DEFAULTS] | Missing # type: ignore[type-arg,valid-type]
|
|
44
57
|
|
|
45
58
|
def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
|
|
46
59
|
value["x-paths"] = {"Entry": PATH_ITEM_SAMPLE}
|
|
@@ -71,7 +84,9 @@ class Operation:
|
|
|
71
84
|
tags: UniqueList[str] | Missing # type: ignore[type-arg,valid-type]
|
|
72
85
|
consumes: MediaTypeList | Missing
|
|
73
86
|
produces: MediaTypeList | Missing
|
|
74
|
-
responses: dict[ResponseId, Response | ResponseReference]
|
|
87
|
+
responses: dict[ResponseId, Response | ResponseReference] # type: ignore[valid-type]
|
|
88
|
+
security: OperationSecurityRequirement | Missing
|
|
89
|
+
deprecated: bool | Missing
|
|
75
90
|
|
|
76
91
|
def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
|
|
77
92
|
if not value["responses"]:
|
|
@@ -96,9 +111,14 @@ class BodyParameter:
|
|
|
96
111
|
class QueryParameter:
|
|
97
112
|
name: str
|
|
98
113
|
type: Literal["string", "number", "boolean", "integer", "array"]
|
|
114
|
+
collectionFormat: Literal["csv", "ssv", "tsv", "pipes"] | Missing
|
|
99
115
|
|
|
100
116
|
def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
|
|
101
117
|
value["in"] = "query"
|
|
118
|
+
if value["type"] == "array":
|
|
119
|
+
value["items"] = {"type": "string"}
|
|
120
|
+
elif "collectionFormat" in value:
|
|
121
|
+
del value["collectionFormat"]
|
|
102
122
|
return value
|
|
103
123
|
|
|
104
124
|
def __hash__(self) -> int:
|
|
@@ -112,6 +132,8 @@ class HeaderParameter:
|
|
|
112
132
|
|
|
113
133
|
def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
|
|
114
134
|
value["in"] = "header"
|
|
135
|
+
if value["type"] == "array":
|
|
136
|
+
value["items"] = {"type": "string"}
|
|
115
137
|
return value
|
|
116
138
|
|
|
117
139
|
def __hash__(self) -> int:
|
|
@@ -126,6 +148,8 @@ class PathParameter:
|
|
|
126
148
|
def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
|
|
127
149
|
value["in"] = "path"
|
|
128
150
|
value["required"] = True
|
|
151
|
+
if value["type"] == "array":
|
|
152
|
+
value["items"] = {"type": "string"}
|
|
129
153
|
return value
|
|
130
154
|
|
|
131
155
|
def __hash__(self) -> int:
|
|
@@ -136,9 +160,14 @@ class PathParameter:
|
|
|
136
160
|
class FormDataParameter:
|
|
137
161
|
name: str
|
|
138
162
|
type: Literal["string", "number", "boolean", "integer", "array", "file"]
|
|
163
|
+
collectionFormat: Literal["csv", "ssv", "tsv", "pipes"] | Missing
|
|
139
164
|
|
|
140
165
|
def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
|
|
141
166
|
value["in"] = "formData"
|
|
167
|
+
if value["type"] == "array":
|
|
168
|
+
value["items"] = {"type": "string"}
|
|
169
|
+
elif "collectionFormat" in value:
|
|
170
|
+
del value["collectionFormat"]
|
|
142
171
|
return value
|
|
143
172
|
|
|
144
173
|
def __hash__(self) -> int:
|
|
@@ -146,5 +175,5 @@ class FormDataParameter:
|
|
|
146
175
|
|
|
147
176
|
|
|
148
177
|
Parameter = BodyParameter | QueryParameter | HeaderParameter | PathParameter | FormDataParameter
|
|
149
|
-
ParameterList: TypeAlias = UniqueList[Parameter | ParameterReference] # type: ignore[type-arg]
|
|
178
|
+
ParameterList: TypeAlias = UniqueList[Parameter | ParameterReference] # type: ignore[type-arg, valid-type]
|
|
150
179
|
MediaTypeList: TypeAlias = UniqueList[MediaType] # type: ignore[type-arg]
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# ruff: noqa: F722, F821
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
from typing import Any, Literal, TypeAlias
|
|
6
|
+
|
|
7
|
+
from ._common import (
|
|
8
|
+
DEFAULT_SECURITY_SCHEME,
|
|
9
|
+
PATH_ITEM_SAMPLE,
|
|
10
|
+
RESPONSE_SUCCESS,
|
|
11
|
+
Info,
|
|
12
|
+
OperationSecurityRequirement,
|
|
13
|
+
PathItemReference,
|
|
14
|
+
Response,
|
|
15
|
+
reference,
|
|
16
|
+
)
|
|
17
|
+
from ._types import CombinedDict, Missing, Pattern, UniqueList
|
|
18
|
+
|
|
19
|
+
PARAMETER_SAMPLE = {"name": "sample", "in": "query", "schema": {"type": "string"}}
|
|
20
|
+
ResponseId: TypeAlias = Pattern[r"^[1-5](?:[0-9]{2}|XX)$|^(default)\Z"] # type: ignore[type-arg,valid-type]
|
|
21
|
+
ParameterReference = reference("#/components/parameters/SampleParameter")
|
|
22
|
+
ResponseReference = reference("#/components/responses/Success")
|
|
23
|
+
|
|
24
|
+
RequestBodyMediaType = (
|
|
25
|
+
Literal["application/json"] | Literal["application/x-www-form-urlencoded"] | Literal["multipart/form-data"]
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
_REQUEST_BODY_DEFAULTS: dict[str, dict] = {"application/json": {"schema": {}}}
|
|
29
|
+
|
|
30
|
+
_VALID_STYLES: dict[str, frozenset] = {
|
|
31
|
+
"query": frozenset({"form", "spaceDelimited", "pipeDelimited", "deepObject"}),
|
|
32
|
+
"path": frozenset({"simple", "label", "matrix"}),
|
|
33
|
+
"header": frozenset({"simple"}),
|
|
34
|
+
"cookie": frozenset({"form"}),
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@dataclass
|
|
39
|
+
class MediaTypeObject:
|
|
40
|
+
def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
|
|
41
|
+
value["schema"] = {}
|
|
42
|
+
return value
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@dataclass
|
|
46
|
+
class RequestBody:
|
|
47
|
+
required: bool | Missing
|
|
48
|
+
content: CombinedDict[RequestBodyMediaType, MediaTypeObject, _REQUEST_BODY_DEFAULTS] # type: ignore[type-arg,valid-type]
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@dataclass
|
|
52
|
+
class StringSchema:
|
|
53
|
+
def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
|
|
54
|
+
return {"type": "string"}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@dataclass
|
|
58
|
+
class ArraySchema:
|
|
59
|
+
def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
|
|
60
|
+
return {"type": "array", "items": {"type": "string"}}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@dataclass
|
|
64
|
+
class ObjectSchema:
|
|
65
|
+
def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
|
|
66
|
+
return {"type": "object", "additionalProperties": {"type": "string"}}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
ParameterSchema = StringSchema | ArraySchema | ObjectSchema
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@dataclass
|
|
73
|
+
class OpenApi30:
|
|
74
|
+
openapi: Pattern[r"^3\.0\.[0-9]\Z"] # type: ignore[type-arg,valid-type]
|
|
75
|
+
info: Info
|
|
76
|
+
paths: dict[Pattern["^/"], PathItem | PathItemReference] # type: ignore[type-arg,valid-type]
|
|
77
|
+
|
|
78
|
+
def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
|
|
79
|
+
value["x-paths"] = {"Entry": PATH_ITEM_SAMPLE}
|
|
80
|
+
value["components"] = {
|
|
81
|
+
"parameters": {"SampleParameter": PARAMETER_SAMPLE},
|
|
82
|
+
"responses": {"Success": RESPONSE_SUCCESS},
|
|
83
|
+
"securitySchemes": {DEFAULT_SECURITY_SCHEME: {"type": "apiKey", "name": "X-Api-Key", "in": "header"}},
|
|
84
|
+
}
|
|
85
|
+
return value
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
@dataclass
|
|
89
|
+
class PathItem:
|
|
90
|
+
get: Operation | Missing
|
|
91
|
+
put: Operation | Missing
|
|
92
|
+
post: Operation | Missing
|
|
93
|
+
delete: Operation | Missing
|
|
94
|
+
options: Operation | Missing
|
|
95
|
+
head: Operation | Missing
|
|
96
|
+
patch: Operation | Missing
|
|
97
|
+
trace: Operation | Missing
|
|
98
|
+
parameters: ParameterList | Missing
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
@dataclass
|
|
102
|
+
class Operation:
|
|
103
|
+
operationId: str | Missing
|
|
104
|
+
parameters: ParameterList | Missing
|
|
105
|
+
tags: UniqueList[str] | Missing # type: ignore[type-arg,valid-type]
|
|
106
|
+
responses: dict[ResponseId, Response | ResponseReference] # type: ignore[valid-type]
|
|
107
|
+
requestBody: RequestBody | Missing
|
|
108
|
+
security: OperationSecurityRequirement | Missing
|
|
109
|
+
deprecated: bool | Missing
|
|
110
|
+
|
|
111
|
+
def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
|
|
112
|
+
if not value["responses"]:
|
|
113
|
+
value["responses"] = {"default": RESPONSE_SUCCESS}
|
|
114
|
+
return value
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
@dataclass
|
|
118
|
+
class Parameter:
|
|
119
|
+
name: str
|
|
120
|
+
in_: Literal["query", "header", "path", "cookie"]
|
|
121
|
+
required: bool
|
|
122
|
+
deprecated: bool
|
|
123
|
+
allowEmptyValue: bool
|
|
124
|
+
allowReserved: bool
|
|
125
|
+
explode: bool
|
|
126
|
+
style: Literal["form", "simple", "label", "matrix", "spaceDelimited", "pipeDelimited", "deepObject"] | Missing
|
|
127
|
+
schema: ParameterSchema
|
|
128
|
+
|
|
129
|
+
def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
|
|
130
|
+
in_ = value.pop("in_")
|
|
131
|
+
value["in"] = in_
|
|
132
|
+
if in_ == "path":
|
|
133
|
+
value["required"] = True
|
|
134
|
+
style = value.get("style")
|
|
135
|
+
if style is not None and style not in _VALID_STYLES.get(in_, frozenset()):
|
|
136
|
+
del value["style"]
|
|
137
|
+
return value
|
|
138
|
+
|
|
139
|
+
def __hash__(self) -> int:
|
|
140
|
+
return hash((self.name, self.in_))
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
ParameterList: TypeAlias = UniqueList[Parameter | ParameterReference] # type: ignore[type-arg,valid-type]
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
# ruff: noqa: F722, F821
|
|
2
|
-
from __future__ import annotations
|
|
3
|
-
|
|
4
|
-
from dataclasses import dataclass
|
|
5
|
-
from typing import Any, Literal, TypeAlias
|
|
6
|
-
|
|
7
|
-
from ._common import (
|
|
8
|
-
RESPONSE_SUCCESS,
|
|
9
|
-
Info,
|
|
10
|
-
ParameterReference,
|
|
11
|
-
PathItemReference,
|
|
12
|
-
Response,
|
|
13
|
-
ResponseReference,
|
|
14
|
-
)
|
|
15
|
-
from ._types import Missing, Pattern, UniqueList
|
|
16
|
-
|
|
17
|
-
ResponseId: TypeAlias = Pattern[r"^[1-5](?:[0-9]{2}|XX)$|^(default)\Z"] # type: ignore[type-arg,valid-type]
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
@dataclass
|
|
21
|
-
class OpenApi30:
|
|
22
|
-
openapi: Pattern["^3\\.0\\.\\d$"] # type: ignore[type-arg,valid-type]
|
|
23
|
-
info: Info
|
|
24
|
-
paths: dict[Pattern["^/"], PathItem | PathItemReference] # type: ignore[type-arg,valid-type]
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
@dataclass
|
|
28
|
-
class PathItem:
|
|
29
|
-
get: Operation | Missing
|
|
30
|
-
put: Operation | Missing
|
|
31
|
-
post: Operation | Missing
|
|
32
|
-
delete: Operation | Missing
|
|
33
|
-
options: Operation | Missing
|
|
34
|
-
head: Operation | Missing
|
|
35
|
-
patch: Operation | Missing
|
|
36
|
-
trace: Operation | Missing
|
|
37
|
-
parameters: ParameterList | Missing
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
@dataclass
|
|
41
|
-
class Operation:
|
|
42
|
-
operationId: str | Missing
|
|
43
|
-
parameters: ParameterList | Missing
|
|
44
|
-
tags: UniqueList[str] | Missing # type: ignore[type-arg,valid-type]
|
|
45
|
-
responses: dict[ResponseId, Response | ResponseReference]
|
|
46
|
-
|
|
47
|
-
def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
|
|
48
|
-
if not value["responses"]:
|
|
49
|
-
value["responses"] = {"default": RESPONSE_SUCCESS}
|
|
50
|
-
return value
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
@dataclass
|
|
54
|
-
class Parameter:
|
|
55
|
-
name: str
|
|
56
|
-
in_: Literal["query", "header", "path", "cookie"]
|
|
57
|
-
required: bool
|
|
58
|
-
deprecated: bool
|
|
59
|
-
allowEmptyValue: bool
|
|
60
|
-
allowReserved: bool
|
|
61
|
-
explode: bool
|
|
62
|
-
|
|
63
|
-
def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
|
|
64
|
-
value["in"] = value.pop("in_")
|
|
65
|
-
value["schema"] = {"type": "string"}
|
|
66
|
-
if value["in"] == "path":
|
|
67
|
-
value["required"] = True
|
|
68
|
-
return value
|
|
69
|
-
|
|
70
|
-
def __hash__(self) -> int:
|
|
71
|
-
return hash((self.name, self.in_))
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
ParameterList: TypeAlias = UniqueList[Parameter | ParameterReference] # type: ignore[type-arg]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|