hypothesis-openapi 0.1.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.
@@ -0,0 +1,162 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ .ruff_cache
55
+
56
+ # Translations
57
+ *.mo
58
+ *.pot
59
+
60
+ # Django stuff:
61
+ *.log
62
+ local_settings.py
63
+ db.sqlite3
64
+ db.sqlite3-journal
65
+
66
+ # Flask stuff:
67
+ instance/
68
+ .webassets-cache
69
+
70
+ # Scrapy stuff:
71
+ .scrapy
72
+
73
+ # Sphinx documentation
74
+ docs/_build/
75
+
76
+ # PyBuilder
77
+ .pybuilder/
78
+ target/
79
+
80
+ # Jupyter Notebook
81
+ .ipynb_checkpoints
82
+
83
+ # IPython
84
+ profile_default/
85
+ ipython_config.py
86
+
87
+ # pyenv
88
+ # For a library or package, you might want to ignore these files since the code is
89
+ # intended to run in multiple environments; otherwise, check them in:
90
+ # .python-version
91
+
92
+ # pipenv
93
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
94
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
95
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
96
+ # install all needed dependencies.
97
+ #Pipfile.lock
98
+
99
+ # poetry
100
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
101
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
102
+ # commonly ignored for libraries.
103
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
104
+ #poetry.lock
105
+
106
+ # pdm
107
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
108
+ #pdm.lock
109
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
110
+ # in version control.
111
+ # https://pdm.fming.dev/#use-with-ide
112
+ .pdm.toml
113
+
114
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
115
+ __pypackages__/
116
+
117
+ # Celery stuff
118
+ celerybeat-schedule
119
+ celerybeat.pid
120
+
121
+ # SageMath parsed files
122
+ *.sage.py
123
+
124
+ # Environments
125
+ .env
126
+ .venv
127
+ env/
128
+ venv/
129
+ ENV/
130
+ env.bak/
131
+ venv.bak/
132
+
133
+ # Spyder project settings
134
+ .spyderproject
135
+ .spyproject
136
+
137
+ # Rope project settings
138
+ .ropeproject
139
+
140
+ # mkdocs documentation
141
+ /site
142
+
143
+ # mypy
144
+ .mypy_cache/
145
+ .dmypy.json
146
+ dmypy.json
147
+
148
+ # Pyre type checker
149
+ .pyre/
150
+
151
+ # pytype static type analyzer
152
+ .pytype/
153
+
154
+ # Cython debug symbols
155
+ cython_debug/
156
+
157
+ # PyCharm
158
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
159
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
160
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
161
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
162
+ #.idea/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Dmitry Dygalo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,71 @@
1
+ Metadata-Version: 2.3
2
+ Name: hypothesis-openapi
3
+ Version: 0.1.0
4
+ Summary: Hypothesis plugin for generating valid Open API documents
5
+ Project-URL: Changelog, https://github.com/Stranger6667/hypothesis-openapi/blob/main/CHANGELOG.md
6
+ Project-URL: Bug Tracker, https://github.com/Stranger6667/hypothesis-openapi
7
+ Project-URL: Funding, https://github.com/sponsors/Stranger6667
8
+ Project-URL: Source Code, https://github.com/Stranger6667/hypothesis-openapi
9
+ Author-email: Dmitry Dygalo <dmitry@dygalo.dev>
10
+ Maintainer-email: Dmitry Dygalo <dmitry@dygalo.dev>
11
+ License-Expression: MIT
12
+ License-File: LICENSE
13
+ Keywords: hypothesis,openapi,testing
14
+ Classifier: Development Status :: 3 - Alpha
15
+ Classifier: Environment :: Console
16
+ Classifier: Framework :: Hypothesis
17
+ Classifier: Intended Audience :: Developers
18
+ Classifier: License :: OSI Approved :: MIT License
19
+ Classifier: Operating System :: OS Independent
20
+ Classifier: Programming Language :: Python :: 3 :: Only
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Programming Language :: Python :: Implementation :: CPython
25
+ Classifier: Topic :: Software Development :: Testing
26
+ Requires-Python: >=3.10
27
+ Requires-Dist: hypothesis<7.0,>=6.84.3
28
+ Provides-Extra: cov
29
+ Requires-Dist: coverage-enable-subprocess; extra == 'cov'
30
+ Requires-Dist: coverage[toml]>=7; extra == 'cov'
31
+ Provides-Extra: dev
32
+ Requires-Dist: coverage-enable-subprocess; extra == 'dev'
33
+ Requires-Dist: coverage>=7; extra == 'dev'
34
+ Requires-Dist: coverage[toml]>=7; extra == 'dev'
35
+ Requires-Dist: jsonschema>=4.21.0; extra == 'dev'
36
+ Requires-Dist: pytest-xdist<3.0,>=2.5; extra == 'dev'
37
+ Requires-Dist: pytest<8,>=6.2.0; extra == 'dev'
38
+ Provides-Extra: tests
39
+ Requires-Dist: coverage>=7; extra == 'tests'
40
+ Requires-Dist: jsonschema>=4.21.0; extra == 'tests'
41
+ Requires-Dist: pytest-xdist<3.0,>=2.5; extra == 'tests'
42
+ Requires-Dist: pytest<8,>=6.2.0; extra == 'tests'
43
+ Description-Content-Type: text/markdown
44
+
45
+ # hypothesis-openapi
46
+
47
+ [![Build](https://github.com/Stranger6667/hypothesis-openapi/workflows/build/badge.svg)](https://github.com/Stranger6667/hypothesis-main/actions)
48
+ [![Coverage](https://codecov.io/gh/Stranger6667/hypothesis-openapi/branch/main/graph/badge.svg)](https://codecov.io/gh/Stranger6667/hypothesis-openapi/branch/main)
49
+ [![Version](https://img.shields.io/pypi/v/hypothesis-openapi.svg)](https://pypi.org/project/hypothesis-openapi/)
50
+ [![Python versions](https://img.shields.io/pypi/pyversions/hypothesis-openapi.svg)](https://pypi.org/project/hypothesis-openapi/)
51
+ [![License](https://img.shields.io/pypi/l/hypothesis-openapi.svg)](https://opensource.org/licenses/MIT)
52
+
53
+ Hypothesis plugin for generating valid Open API documents.
54
+
55
+ ## Usage
56
+
57
+ ```python
58
+ from hypothesis import given
59
+ from hypothesis_openapi import openapis
60
+
61
+
62
+ @given(openapis(version="2.0"))
63
+ def test_openapi(spec):
64
+ assert spec["swagger"] == "2.0"
65
+ assert "info" in spec
66
+ ```
67
+
68
+ ## License
69
+
70
+ The code in this project is licensed under [MIT license](https://opensource.org/licenses/MIT).
71
+ By contributing to `hypothesis-openapi`, you agree that your contributions will be licensed under its MIT license.
@@ -0,0 +1,27 @@
1
+ # hypothesis-openapi
2
+
3
+ [![Build](https://github.com/Stranger6667/hypothesis-openapi/workflows/build/badge.svg)](https://github.com/Stranger6667/hypothesis-main/actions)
4
+ [![Coverage](https://codecov.io/gh/Stranger6667/hypothesis-openapi/branch/main/graph/badge.svg)](https://codecov.io/gh/Stranger6667/hypothesis-openapi/branch/main)
5
+ [![Version](https://img.shields.io/pypi/v/hypothesis-openapi.svg)](https://pypi.org/project/hypothesis-openapi/)
6
+ [![Python versions](https://img.shields.io/pypi/pyversions/hypothesis-openapi.svg)](https://pypi.org/project/hypothesis-openapi/)
7
+ [![License](https://img.shields.io/pypi/l/hypothesis-openapi.svg)](https://opensource.org/licenses/MIT)
8
+
9
+ Hypothesis plugin for generating valid Open API documents.
10
+
11
+ ## Usage
12
+
13
+ ```python
14
+ from hypothesis import given
15
+ from hypothesis_openapi import openapis
16
+
17
+
18
+ @given(openapis(version="2.0"))
19
+ def test_openapi(spec):
20
+ assert spec["swagger"] == "2.0"
21
+ assert "info" in spec
22
+ ```
23
+
24
+ ## License
25
+
26
+ The code in this project is licensed under [MIT license](https://opensource.org/licenses/MIT).
27
+ By contributing to `hypothesis-openapi`, you agree that your contributions will be licensed under its MIT license.
@@ -0,0 +1,114 @@
1
+ [project]
2
+ name = "hypothesis-openapi"
3
+ version = "0.1.0"
4
+ description = "Hypothesis plugin for generating valid Open API documents"
5
+ keywords = ["hypothesis", "openapi", "testing"]
6
+ classifiers = [
7
+ "Development Status :: 3 - Alpha",
8
+ "Environment :: Console",
9
+ "Framework :: Hypothesis",
10
+ "Intended Audience :: Developers",
11
+ "License :: OSI Approved :: MIT License",
12
+ "Operating System :: OS Independent",
13
+ "Programming Language :: Python :: 3 :: Only",
14
+ "Programming Language :: Python :: 3.10",
15
+ "Programming Language :: Python :: 3.11",
16
+ "Programming Language :: Python :: 3.12",
17
+ "Programming Language :: Python :: Implementation :: CPython",
18
+ "Topic :: Software Development :: Testing",
19
+ ]
20
+ authors = [{ name = "Dmitry Dygalo", email = "dmitry@dygalo.dev" }]
21
+ maintainers = [{ name = "Dmitry Dygalo", email = "dmitry@dygalo.dev" }]
22
+ readme = "README.md"
23
+ license = "MIT"
24
+ include = ["src/hypothesis_openapi/py.typed"]
25
+ requires-python = ">=3.10"
26
+ dependencies = [
27
+ "hypothesis>=6.84.3,<7.0",
28
+ ]
29
+
30
+ [project.optional-dependencies]
31
+ tests = [
32
+ "coverage>=7",
33
+ "jsonschema>=4.21.0",
34
+ "pytest>=6.2.0,<8",
35
+ "pytest-xdist>=2.5,<3.0",
36
+ ]
37
+ cov = [
38
+ "coverage-enable-subprocess",
39
+ "coverage[toml]>=7",
40
+ ]
41
+ dev = ["hypothesis_openapi[tests,cov]"]
42
+
43
+ [project.urls]
44
+ Changelog = "https://github.com/Stranger6667/hypothesis-openapi/blob/main/CHANGELOG.md"
45
+ "Bug Tracker" = "https://github.com/Stranger6667/hypothesis-openapi"
46
+ Funding = "https://github.com/sponsors/Stranger6667"
47
+ "Source Code" = "https://github.com/Stranger6667/hypothesis-openapi"
48
+
49
+ [tool.hatch.build.targets.sdist]
50
+ include = [
51
+ "/src",
52
+ "/test",
53
+ ]
54
+
55
+ [tool.coverage.run]
56
+ parallel = true
57
+ branch = true
58
+ source_pkgs = ["hypothesis_openapi"]
59
+
60
+ [tool.coverage.paths]
61
+ source = ["src", ".tox/*/site-packages"]
62
+
63
+ [tool.coverage.report]
64
+ show_missing = true
65
+ skip_covered = true
66
+ precision = 2
67
+ exclude_lines = [
68
+ "raise NotImplementedError",
69
+ "if TYPE_CHECKING:",
70
+ "pass"
71
+ ]
72
+
73
+ [tool.ruff]
74
+ line-length = 120
75
+ target-version = "py310"
76
+
77
+ [tool.ruff.lint]
78
+ select = [
79
+ "E", # pycodestyle errors
80
+ "W", # pycodestyle warnings
81
+ "F", # pyflakes
82
+ "C", # flake8-comprehensions
83
+ "B", # flake8-bugbear
84
+ "D", # pydocstyle
85
+ ]
86
+ ignore = [
87
+ "E501", # Line too long
88
+ "B008", # Do not perform function calls in argument defaults
89
+ "C901", # Too complex
90
+ "D100", # Missing docstring in public module
91
+ "D101", # Missing docstring in public class
92
+ "D102", # Missing docstring in public method
93
+ "D103", # Missing docstring in public function
94
+ "D104", # Missing docstring in public package
95
+ "D105", # Missing docstring in magic method
96
+ "D107", # Missing docstring in `__init__`
97
+ "D203", # One blank line before class
98
+ "D213", # Multiline summary second line
99
+ "D401", # Imperative mood
100
+ ]
101
+
102
+ [tool.ruff.format]
103
+ skip-magic-trailing-comma = false
104
+
105
+ [tool.ruff.lint.per-file-ignores]
106
+ "__init__.py" = ["F401"]
107
+
108
+ [tool.ruff.lint.isort]
109
+ known-first-party = ["hypothesis_openapi"]
110
+ known-third-party = ["hypothesis", "pytest"]
111
+
112
+ [build-system]
113
+ requires = ["hatchling"]
114
+ build-backend = "hatchling.build"
@@ -0,0 +1 @@
1
+ from ._strategies import openapis
@@ -0,0 +1,20 @@
1
+ from dataclasses import is_dataclass, fields
2
+
3
+ from ._types import Missing
4
+
5
+
6
+ def asdict(obj: object) -> object:
7
+ if is_dataclass(obj):
8
+ result = {}
9
+ for f in fields(obj):
10
+ value = getattr(obj, f.name)
11
+ if not isinstance(value, Missing):
12
+ result[f.name] = asdict(value)
13
+ if hasattr(obj, "map_value"):
14
+ result = obj.map_value(result)
15
+ return result
16
+ elif isinstance(obj, (list, tuple)):
17
+ return type(obj)(asdict(v) for v in obj)
18
+ elif isinstance(obj, dict):
19
+ return type(obj)((asdict(k), asdict(v)) for k, v in obj.items())
20
+ return obj
@@ -0,0 +1,10 @@
1
+ from typing import Any, Literal
2
+ from hypothesis import strategies as st
3
+ from ._v2 import Swagger
4
+ from ._serialize import asdict
5
+
6
+
7
+ def openapis(version: Literal["2.0"] | Literal["3.0"] | Literal["3.1"]) -> "st.SearchStrategy[dict[str, Any]]":
8
+ if version == "2.0":
9
+ return st.from_type(Swagger).map(asdict) # type: ignore[arg-type]
10
+ raise ValueError(f"Unsupported version: {version}")
@@ -0,0 +1,31 @@
1
+ from typing import Annotated
2
+
3
+ from hypothesis import strategies as st
4
+
5
+
6
+ class Pattern:
7
+ def __class_getitem__(cls, pattern: str) -> object:
8
+ strategy = st.from_regex(pattern)
9
+ return Annotated[str, strategy]
10
+
11
+
12
+ class UniqueList:
13
+ def __class_getitem__(cls, inner: type) -> object:
14
+ strategy = st.lists(st.from_type(inner), unique=True)
15
+ return Annotated[list, strategy]
16
+
17
+
18
+ class CombinedDict:
19
+ def __class_getitem__(cls, args: tuple[type, type, dict]) -> object:
20
+ keys, values, defaults = args
21
+
22
+ def update(data: dict) -> dict:
23
+ data.update(defaults)
24
+ return data
25
+
26
+ strategy = st.dictionaries(st.from_type(keys), st.from_type(values)).map(update)
27
+ return Annotated[dict, strategy]
28
+
29
+
30
+ class Missing:
31
+ pass
@@ -0,0 +1,203 @@
1
+ # ruff: noqa: F722, F821
2
+ from __future__ import annotations
3
+
4
+ from dataclasses import dataclass, field
5
+ from typing import Any, Literal, TypeAlias
6
+
7
+ from ._types import CombinedDict, Missing, Pattern, UniqueList
8
+
9
+ RESPONSE_SUCCESS = {"description": "OK"}
10
+ PATH_ITEM_SAMPLE = {"get": {"responses": {"default": RESPONSE_SUCCESS}}}
11
+ PARAMETER_SAMPLE = {"name": "sample", "in": "query", "type": "string"}
12
+
13
+
14
+ @dataclass
15
+ class PathItemReference:
16
+ def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
17
+ value["$ref"] = "#/x-paths/Entry"
18
+ return value
19
+
20
+
21
+ @dataclass
22
+ class ParameterReference:
23
+ def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
24
+ value["$ref"] = "#/parameters/SampleParameter"
25
+ return value
26
+
27
+
28
+ @dataclass
29
+ class ResponseReference:
30
+ def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
31
+ value["$ref"] = "#/responses/Success"
32
+ return value
33
+
34
+
35
+ MediaType = (
36
+ Literal["application/json"]
37
+ | Literal["application/xml"]
38
+ | Literal["text/plain"]
39
+ | Literal["text/yaml"]
40
+ | Literal["application/x-www-form-urlencoded"]
41
+ | Literal["multipart/form-data"]
42
+ | Literal["application/octet-stream"]
43
+ )
44
+
45
+
46
+ @dataclass
47
+ class Swagger:
48
+ swagger: Literal["2.0"]
49
+ info: Info
50
+ host: Pattern["^[^{}/ :\\\\]+(?::\\d+)?$"] | Missing # type: ignore[type-arg,valid-type]
51
+ basePath: Pattern["^/"] | Missing # type: ignore[type-arg,valid-type]
52
+ paths: dict[Pattern["^/"], PathItem | PathItemReference] # type: ignore[type-arg,valid-type]
53
+ consumes: MediaTypeList | Missing
54
+ produces: MediaTypeList | Missing
55
+ parameters: CombinedDict[str, Parameter, {"SampleParameter": PARAMETER_SAMPLE}] # type: ignore[type-arg,valid-type]
56
+ responses: CombinedDict[ResponseId, Response, {"Success": RESPONSE_SUCCESS}] # type: ignore[type-arg,valid-type]
57
+ definitions: Definitions
58
+
59
+ def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
60
+ value["x-paths"] = {"Entry": PATH_ITEM_SAMPLE}
61
+ return value
62
+
63
+
64
+ @dataclass
65
+ class Definitions:
66
+ pass
67
+
68
+
69
+ @dataclass
70
+ class Info:
71
+ version: Literal["1.0.0"]
72
+ title: Literal["Example API"]
73
+
74
+
75
+ @dataclass
76
+ class PathItem:
77
+ get: Operation | Missing
78
+ put: Operation | Missing
79
+ post: Operation | Missing
80
+ delete: Operation | Missing
81
+ options: Operation | Missing
82
+ head: Operation | Missing
83
+ patch: Operation | Missing
84
+ parameters: ParameterList | Missing
85
+
86
+ def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
87
+ if "parameters" in value:
88
+ value["parameters"] = deduplicate_parameters(value["parameters"])
89
+ return value
90
+
91
+
92
+ @dataclass
93
+ class Operation:
94
+ operationId: str | Missing
95
+ parameters: ParameterList | Missing
96
+ tags: UniqueList[str] | Missing # type: ignore[type-arg,valid-type]
97
+ consumes: MediaTypeList | Missing
98
+ produces: MediaTypeList | Missing
99
+ responses: dict[ResponseId, Response]
100
+
101
+ def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
102
+ if not value["responses"]:
103
+ value["responses"] = {"default": RESPONSE_SUCCESS}
104
+ if "parameters" in value:
105
+ value["parameters"] = deduplicate_parameters(value["parameters"])
106
+ return value
107
+
108
+
109
+ def deduplicate_parameters(parameters: list[dict[str, Any]]) -> list[dict[str, Any]]:
110
+ # TODO: modify in-place
111
+ parameter_names = set()
112
+ deduplicated = []
113
+ has_reference = False
114
+ for parameter in parameters:
115
+ if "$ref" in parameter:
116
+ if has_reference:
117
+ continue
118
+ has_reference = True
119
+ deduplicated.append(parameter)
120
+ else:
121
+ name = parameter["name"]
122
+ if name in parameter_names:
123
+ continue
124
+ parameter_names.add(name)
125
+ deduplicated.append(parameter)
126
+ return deduplicated
127
+
128
+
129
+ @dataclass
130
+ class Response:
131
+ description: Literal["Ok"]
132
+
133
+
134
+ @dataclass
135
+ class BodyParameter:
136
+ name: str
137
+ schema: dict = field(default_factory=dict)
138
+
139
+ def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
140
+ value["in"] = "body"
141
+ return value
142
+
143
+ def __hash__(self) -> int:
144
+ return hash(self.name)
145
+
146
+
147
+ @dataclass
148
+ class QueryParameter:
149
+ name: str
150
+ type: Literal["string", "number", "boolean", "integer", "array"]
151
+
152
+ def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
153
+ value["in"] = "query"
154
+ return value
155
+
156
+ def __hash__(self) -> int:
157
+ return hash(self.name)
158
+
159
+
160
+ @dataclass
161
+ class HeaderParameter:
162
+ name: str
163
+ type: Literal["string", "number", "boolean", "integer", "array"]
164
+
165
+ def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
166
+ value["in"] = "header"
167
+ return value
168
+
169
+ def __hash__(self) -> int:
170
+ return hash(self.name)
171
+
172
+
173
+ @dataclass
174
+ class PathParameter:
175
+ name: str
176
+ type: Literal["string", "number", "boolean", "integer", "array"]
177
+
178
+ def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
179
+ value["in"] = "path"
180
+ value["required"] = True
181
+ return value
182
+
183
+ def __hash__(self) -> int:
184
+ return hash(self.name)
185
+
186
+
187
+ @dataclass
188
+ class FormDataParameter:
189
+ name: str
190
+ type: Literal["string", "number", "boolean", "integer", "array", "file"]
191
+
192
+ def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
193
+ value["in"] = "formData"
194
+ return value
195
+
196
+ def __hash__(self) -> int:
197
+ return hash(self.name)
198
+
199
+
200
+ Parameter = BodyParameter | QueryParameter | HeaderParameter | PathParameter | FormDataParameter
201
+ ParameterList = list[Parameter | ParameterReference]
202
+ MediaTypeList: TypeAlias = UniqueList[MediaType] # type: ignore[type-arg]
203
+ ResponseId: TypeAlias = Pattern["^([0-9]{3})$|^(default)$"] # type: ignore[type-arg,valid-type]