hypothesis-openapi 0.2.1__tar.gz → 0.4.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.
@@ -1,9 +1,9 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.5
2
2
  Name: hypothesis-openapi
3
- Version: 0.2.1
3
+ Version: 0.4.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
- Project-URL: Bug Tracker, https://github.com/Stranger6667/hypothesis-openapi
6
+ Project-URL: Bug Tracker, https://github.com/Stranger6667/hypothesis-openapi/issues
7
7
  Project-URL: Funding, https://github.com/sponsors/Stranger6667
8
8
  Project-URL: Source Code, https://github.com/Stranger6667/hypothesis-openapi
9
9
  Author-email: Dmitry Dygalo <dmitry@dygalo.dev>
@@ -18,38 +18,35 @@ Classifier: Intended Audience :: Developers
18
18
  Classifier: License :: OSI Approved :: MIT License
19
19
  Classifier: Operating System :: OS Independent
20
20
  Classifier: Programming Language :: Python :: 3 :: Only
21
- Classifier: Programming Language :: Python :: 3.10
22
21
  Classifier: Programming Language :: Python :: 3.11
23
22
  Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3.13
24
+ Classifier: Programming Language :: Python :: 3.14
25
+ Classifier: Programming Language :: Python :: 3.15
24
26
  Classifier: Programming Language :: Python :: Implementation :: CPython
27
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
25
28
  Classifier: Topic :: Software Development :: Testing
26
- Requires-Python: >=3.10
27
- Requires-Dist: hypothesis<7.0,>=6.84.3
29
+ Classifier: Typing :: Typed
30
+ Requires-Python: >=3.11
31
+ Requires-Dist: hypothesis<7,>=6.108.0
28
32
  Provides-Extra: bench
29
- Requires-Dist: pytest-codspeed==2.2.1; extra == 'bench'
30
- Provides-Extra: cov
31
- Requires-Dist: coverage-enable-subprocess; extra == 'cov'
32
- Requires-Dist: coverage[toml]>=7; extra == 'cov'
33
+ Requires-Dist: pytest-codspeed==4.2.0; extra == 'bench'
33
34
  Provides-Extra: dev
34
- Requires-Dist: coverage-enable-subprocess; extra == 'dev'
35
- Requires-Dist: coverage>=7; extra == 'dev'
36
- Requires-Dist: coverage[toml]>=7; extra == 'dev'
35
+ Requires-Dist: coverage[toml]>=7.2; extra == 'dev'
37
36
  Requires-Dist: jsonschema>=4.21.0; extra == 'dev'
38
- Requires-Dist: pytest-codspeed==2.2.1; extra == 'dev'
39
- Requires-Dist: pytest-xdist<3.0,>=2.5; extra == 'dev'
40
- Requires-Dist: pytest<8,>=6.2.0; extra == 'dev'
37
+ Requires-Dist: pytest-codspeed==4.2.0; extra == 'dev'
38
+ Requires-Dist: pytest>=8; extra == 'dev'
41
39
  Requires-Dist: referencing>=0.35; extra == 'dev'
42
40
  Provides-Extra: tests
43
- Requires-Dist: coverage>=7; extra == 'tests'
41
+ Requires-Dist: coverage[toml]>=7.2; extra == 'tests'
44
42
  Requires-Dist: jsonschema>=4.21.0; extra == 'tests'
45
- Requires-Dist: pytest-xdist<3.0,>=2.5; extra == 'tests'
46
- Requires-Dist: pytest<8,>=6.2.0; extra == 'tests'
43
+ Requires-Dist: pytest>=8; extra == 'tests'
47
44
  Requires-Dist: referencing>=0.35; extra == 'tests'
48
45
  Description-Content-Type: text/markdown
49
46
 
50
47
  # hypothesis-openapi
51
48
 
52
- [![CI](https://github.com/Stranger6667/hypothesis-openapi/actions/workflows/ci.yml/badge.svg)](https://github.com/Stranger6667/hypothesis-openapi/actions/workflows/ci.yml)
49
+ [![Build](https://github.com/Stranger6667/hypothesis-openapi/actions/workflows/build.yml/badge.svg)](https://github.com/Stranger6667/hypothesis-openapi/actions/workflows/build.yml)
53
50
  [![Coverage](https://codecov.io/gh/Stranger6667/hypothesis-openapi/branch/main/graph/badge.svg)](https://codecov.io/gh/Stranger6667/hypothesis-openapi/branch/main)
54
51
  [![Version](https://img.shields.io/pypi/v/hypothesis-openapi.svg)](https://pypi.org/project/hypothesis-openapi/)
55
52
  [![Python versions](https://img.shields.io/pypi/pyversions/hypothesis-openapi.svg)](https://pypi.org/project/hypothesis-openapi/)
@@ -1,6 +1,6 @@
1
1
  # hypothesis-openapi
2
2
 
3
- [![CI](https://github.com/Stranger6667/hypothesis-openapi/actions/workflows/ci.yml/badge.svg)](https://github.com/Stranger6667/hypothesis-openapi/actions/workflows/ci.yml)
3
+ [![Build](https://github.com/Stranger6667/hypothesis-openapi/actions/workflows/build.yml/badge.svg)](https://github.com/Stranger6667/hypothesis-openapi/actions/workflows/build.yml)
4
4
  [![Coverage](https://codecov.io/gh/Stranger6667/hypothesis-openapi/branch/main/graph/badge.svg)](https://codecov.io/gh/Stranger6667/hypothesis-openapi/branch/main)
5
5
  [![Version](https://img.shields.io/pypi/v/hypothesis-openapi.svg)](https://pypi.org/project/hypothesis-openapi/)
6
6
  [![Python versions](https://img.shields.io/pypi/pyversions/hypothesis-openapi.svg)](https://pypi.org/project/hypothesis-openapi/)
@@ -0,0 +1,136 @@
1
+ [project]
2
+ name = "hypothesis-openapi"
3
+ dynamic = ["version"]
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.11",
15
+ "Programming Language :: Python :: 3.12",
16
+ "Programming Language :: Python :: 3.13",
17
+ "Programming Language :: Python :: 3.14",
18
+ "Programming Language :: Python :: 3.15",
19
+ "Programming Language :: Python :: Implementation :: CPython",
20
+ "Programming Language :: Python :: Implementation :: PyPy",
21
+ "Topic :: Software Development :: Testing",
22
+ "Typing :: Typed",
23
+ ]
24
+ authors = [{ name = "Dmitry Dygalo", email = "dmitry@dygalo.dev" }]
25
+ maintainers = [{ name = "Dmitry Dygalo", email = "dmitry@dygalo.dev" }]
26
+ readme = "README.md"
27
+ license = "MIT"
28
+ requires-python = ">=3.11"
29
+ dependencies = [
30
+ "hypothesis>=6.108.0,<7",
31
+ ]
32
+
33
+ [project.optional-dependencies]
34
+ tests = [
35
+ "coverage[toml]>=7.2",
36
+ "jsonschema>=4.21.0",
37
+ "referencing>=0.35",
38
+ "pytest>=8",
39
+ ]
40
+ bench = [
41
+ "pytest-codspeed==4.2.0",
42
+ ]
43
+ dev = ["hypothesis_openapi[tests,bench]"]
44
+
45
+ [project.urls]
46
+ Changelog = "https://github.com/Stranger6667/hypothesis-openapi/blob/main/CHANGELOG.md"
47
+ "Bug Tracker" = "https://github.com/Stranger6667/hypothesis-openapi/issues"
48
+ Funding = "https://github.com/sponsors/Stranger6667"
49
+ "Source Code" = "https://github.com/Stranger6667/hypothesis-openapi"
50
+
51
+ [tool.hatch.version]
52
+ path = "src/hypothesis_openapi/__init__.py"
53
+
54
+ [tool.hatch.build.targets.sdist]
55
+ include = ["/src", "/tests"]
56
+
57
+ [tool.pytest.ini_options]
58
+ addopts = ["-ra", "--strict-markers", "--strict-config"]
59
+ xfail_strict = true
60
+ testpaths = ["tests"]
61
+
62
+ [tool.coverage.run]
63
+ parallel = true
64
+ branch = true
65
+ source_pkgs = ["hypothesis_openapi"]
66
+
67
+ [tool.coverage.paths]
68
+ source = ["src", ".tox/*/site-packages", ".tox/*/lib/*/site-packages", ".tox/*/Lib/site-packages"]
69
+
70
+ [tool.coverage.report]
71
+ show_missing = true
72
+ skip_covered = true
73
+ precision = 2
74
+ fail_under = 100
75
+ exclude_lines = [
76
+ "raise NotImplementedError",
77
+ "if TYPE_CHECKING:",
78
+ "pass"
79
+ ]
80
+
81
+ [tool.ruff]
82
+ line-length = 120
83
+ target-version = "py311"
84
+
85
+ [tool.ruff.lint]
86
+ select = [
87
+ "E", # pycodestyle errors
88
+ "W", # pycodestyle warnings
89
+ "F", # pyflakes
90
+ "C", # flake8-comprehensions
91
+ "B", # flake8-bugbear
92
+ "D", # pydocstyle
93
+ "T201", # flake8-print
94
+ "I", # isort
95
+ "FURB", # refurb
96
+ "PGH003", # blanket-type-ignore
97
+ "UP", # pyupgrade
98
+ "SIM", # flake8-simplify
99
+ ]
100
+ ignore = [
101
+ "E501", # Line too long
102
+ "B008", # Do not perform function calls in argument defaults
103
+ "C901", # Too complex
104
+ "D100", # Missing docstring in public module
105
+ "D101", # Missing docstring in public class
106
+ "D102", # Missing docstring in public method
107
+ "D103", # Missing docstring in public function
108
+ "D104", # Missing docstring in public package
109
+ "D105", # Missing docstring in magic method
110
+ "D106", # Missing docstring in public nested class
111
+ "D107", # Missing docstring in `__init__`
112
+ "D202", # No blank lines allowed after function docstring
113
+ "D203", # One blank line before class
114
+ "D213", # Multiline summary second line
115
+ "D401", # Imperative mood
116
+ "D407", # Missing dashed underline after section
117
+ "COM812", # trailing comma
118
+ ]
119
+
120
+ [tool.ruff.format]
121
+ skip-magic-trailing-comma = false
122
+
123
+ [tool.ruff.lint.per-file-ignores]
124
+ "__init__.py" = ["F401"]
125
+ # _v2.py/_v3.py use dict literals inside type annotations as a Hypothesis strategy trick;
126
+ # FURB rules can corrupt these by removing quotes from string keys.
127
+ "_v2.py" = ["FURB"]
128
+ "_v3.py" = ["FURB"]
129
+
130
+ [tool.ruff.lint.isort]
131
+ known-first-party = ["hypothesis_openapi"]
132
+ known-third-party = ["hypothesis", "pytest"]
133
+
134
+ [build-system]
135
+ requires = ["hatchling"]
136
+ build-backend = "hatchling.build"
@@ -1 +1,3 @@
1
1
  from ._strategies import openapis
2
+
3
+ __version__ = "0.4.0"
@@ -1,6 +1,8 @@
1
1
  # ruff: noqa: F722, F821
2
2
  from dataclasses import dataclass
3
- from typing import Any, Literal, Type
3
+ from typing import Any, Literal
4
+
5
+ DEFAULT_SECURITY_SCHEME = "DefaultApiKey"
4
6
 
5
7
 
6
8
  @dataclass
@@ -21,7 +23,24 @@ class Response:
21
23
  description: Literal["Ok"]
22
24
 
23
25
 
24
- def reference(ref: str) -> Type:
26
+ @dataclass
27
+ class ApiKeyScheme:
28
+ name: str
29
+ in_: Literal["header", "query"]
30
+
31
+ def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
32
+ value["type"] = "apiKey"
33
+ value["in"] = value.pop("in_")
34
+ return value
35
+
36
+
37
+ @dataclass
38
+ class OperationSecurityRequirement:
39
+ def map_value(self, value: dict[str, Any]) -> list[dict[str, list[str]]]:
40
+ return [{DEFAULT_SECURITY_SCHEME: []}]
41
+
42
+
43
+ def reference(ref: str) -> type:
25
44
  @dataclass
26
45
  class ReferenceValue:
27
46
  def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
@@ -1,4 +1,4 @@
1
- from dataclasses import is_dataclass, fields
1
+ from dataclasses import fields, is_dataclass
2
2
 
3
3
  from ._types import Missing
4
4
 
@@ -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]]":
@@ -1,4 +1,4 @@
1
- from typing import Annotated
1
+ from typing import Annotated, Any
2
2
 
3
3
  from hypothesis import strategies as st
4
4
 
@@ -12,19 +12,19 @@ class Pattern:
12
12
  class UniqueList:
13
13
  def __class_getitem__(cls, inner: type) -> object:
14
14
  strategy = st.lists(st.from_type(inner), unique_by=hash)
15
- return Annotated[list, strategy]
15
+ return Annotated[list[Any], strategy]
16
16
 
17
17
 
18
18
  class CombinedDict:
19
- def __class_getitem__(cls, args: tuple[type, type, dict]) -> object:
19
+ def __class_getitem__(cls, args: tuple[type, type, dict[Any, Any]]) -> object:
20
20
  keys, values, defaults = args
21
21
 
22
- def update(data: dict) -> dict:
22
+ def update(data: dict[Any, Any]) -> dict[Any, Any]:
23
23
  data.update(defaults)
24
24
  return data
25
25
 
26
26
  strategy = st.dictionaries(st.from_type(keys), st.from_type(values)).map(update)
27
- return Annotated[dict, strategy]
27
+ return Annotated[dict[Any, Any], strategy]
28
28
 
29
29
 
30
30
  class Missing:
@@ -2,15 +2,20 @@
2
2
  from __future__ import annotations
3
3
 
4
4
  from dataclasses import dataclass, field
5
- from typing import Any, Literal, TypeAlias
5
+ from typing import Annotated, Any, Literal, TypeAlias
6
+
7
+ from hypothesis import strategies as st
6
8
 
7
9
  from ._common import (
10
+ DEFAULT_SECURITY_SCHEME,
8
11
  PATH_ITEM_SAMPLE,
9
12
  RESPONSE_SUCCESS,
13
+ ApiKeyScheme,
10
14
  Info,
11
- reference,
15
+ OperationSecurityRequirement,
12
16
  PathItemReference,
13
17
  Response,
18
+ reference,
14
19
  )
15
20
  from ._types import CombinedDict, Missing, Pattern, UniqueList
16
21
 
@@ -19,6 +24,14 @@ ResponseId: TypeAlias = Pattern[r"^([0-9]{3})$|^(default)\Z"] # type: ignore[ty
19
24
  ParameterReference = reference("#/parameters/SampleParameter")
20
25
  ResponseReference = reference("#/responses/Success")
21
26
 
27
+ # Named dicts used as CombinedDict defaults — must NOT be inline dict literals inside
28
+ # annotations, as ruff transforms {"Key": val} → {Key: val} (undefined name) in that context.
29
+ _PARAMETER_DEFAULTS = {"SampleParameter": PARAMETER_SAMPLE}
30
+ _RESPONSE_DEFAULTS = {"Success": RESPONSE_SUCCESS}
31
+ _SECURITY_DEFAULTS = {DEFAULT_SECURITY_SCHEME: {"type": "apiKey", "name": "X-Api-Key", "in": "header"}}
32
+
33
+ SecurityScheme = ApiKeyScheme
34
+
22
35
  MediaType = (
23
36
  Literal["application/json"]
24
37
  | Literal["application/xml"]
@@ -39,9 +52,10 @@ class Swagger:
39
52
  paths: dict[Pattern["^/"], PathItem | PathItemReference] # type: ignore[type-arg,valid-type]
40
53
  consumes: MediaTypeList | Missing
41
54
  produces: MediaTypeList | Missing
42
- parameters: CombinedDict[str, Parameter, {"SampleParameter": PARAMETER_SAMPLE}] # type: ignore[type-arg,valid-type]
43
- responses: CombinedDict[ResponseId, Response, {"Success": RESPONSE_SUCCESS}] # type: ignore[type-arg,valid-type]
55
+ parameters: CombinedDict[str, Parameter, _PARAMETER_DEFAULTS] # type: ignore[type-arg,valid-type]
56
+ responses: CombinedDict[ResponseId, Response, _RESPONSE_DEFAULTS] # type: ignore[type-arg,valid-type]
44
57
  definitions: Definitions
58
+ securityDefinitions: CombinedDict[str, SecurityScheme, _SECURITY_DEFAULTS] | Missing # type: ignore[type-arg,valid-type]
45
59
 
46
60
  def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
47
61
  value["x-paths"] = {"Entry": PATH_ITEM_SAMPLE}
@@ -69,10 +83,12 @@ class PathItem:
69
83
  class Operation:
70
84
  operationId: str | Missing
71
85
  parameters: ParameterList | Missing
72
- tags: UniqueList[str] | Missing # type: ignore[type-arg,valid-type]
86
+ tags: UniqueList[str] | Missing # type: ignore[type-arg]
73
87
  consumes: MediaTypeList | Missing
74
88
  produces: MediaTypeList | Missing
75
89
  responses: dict[ResponseId, Response | ResponseReference] # type: ignore[valid-type]
90
+ security: OperationSecurityRequirement | Missing
91
+ deprecated: bool | Missing
76
92
 
77
93
  def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
78
94
  if not value["responses"]:
@@ -83,7 +99,8 @@ class Operation:
83
99
  @dataclass
84
100
  class BodyParameter:
85
101
  name: str
86
- schema: dict = field(default_factory=dict)
102
+ # Bare `dict` resolves to `builds(dict)`, i.e. always an empty schema
103
+ schema: Annotated[dict[str, Any], st.builds(dict)] = field(default_factory=dict)
87
104
 
88
105
  def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
89
106
  value["in"] = "body"
@@ -97,9 +114,14 @@ class BodyParameter:
97
114
  class QueryParameter:
98
115
  name: str
99
116
  type: Literal["string", "number", "boolean", "integer", "array"]
117
+ collectionFormat: Literal["csv", "ssv", "tsv", "pipes"] | Missing
100
118
 
101
119
  def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
102
120
  value["in"] = "query"
121
+ if value["type"] == "array":
122
+ value["items"] = {"type": "string"}
123
+ elif "collectionFormat" in value:
124
+ del value["collectionFormat"]
103
125
  return value
104
126
 
105
127
  def __hash__(self) -> int:
@@ -113,6 +135,8 @@ class HeaderParameter:
113
135
 
114
136
  def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
115
137
  value["in"] = "header"
138
+ if value["type"] == "array":
139
+ value["items"] = {"type": "string"}
116
140
  return value
117
141
 
118
142
  def __hash__(self) -> int:
@@ -127,6 +151,8 @@ class PathParameter:
127
151
  def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
128
152
  value["in"] = "path"
129
153
  value["required"] = True
154
+ if value["type"] == "array":
155
+ value["items"] = {"type": "string"}
130
156
  return value
131
157
 
132
158
  def __hash__(self) -> int:
@@ -137,9 +163,14 @@ class PathParameter:
137
163
  class FormDataParameter:
138
164
  name: str
139
165
  type: Literal["string", "number", "boolean", "integer", "array", "file"]
166
+ collectionFormat: Literal["csv", "ssv", "tsv", "pipes"] | Missing
140
167
 
141
168
  def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
142
169
  value["in"] = "formData"
170
+ if value["type"] == "array":
171
+ value["items"] = {"type": "string"}
172
+ elif "collectionFormat" in value:
173
+ del value["collectionFormat"]
143
174
  return value
144
175
 
145
176
  def __hash__(self) -> int:
@@ -5,20 +5,69 @@ from dataclasses import dataclass
5
5
  from typing import Any, Literal, TypeAlias
6
6
 
7
7
  from ._common import (
8
+ DEFAULT_SECURITY_SCHEME,
9
+ PATH_ITEM_SAMPLE,
8
10
  RESPONSE_SUCCESS,
9
11
  Info,
10
- reference,
11
- PATH_ITEM_SAMPLE,
12
+ OperationSecurityRequirement,
12
13
  PathItemReference,
13
14
  Response,
15
+ reference,
14
16
  )
15
- from ._types import Missing, Pattern, UniqueList
17
+ from ._types import CombinedDict, Missing, Pattern, UniqueList
16
18
 
17
19
  PARAMETER_SAMPLE = {"name": "sample", "in": "query", "schema": {"type": "string"}}
18
20
  ResponseId: TypeAlias = Pattern[r"^[1-5](?:[0-9]{2}|XX)$|^(default)\Z"] # type: ignore[type-arg,valid-type]
19
21
  ParameterReference = reference("#/components/parameters/SampleParameter")
20
22
  ResponseReference = reference("#/components/responses/Success")
21
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[str, Any]] = {"application/json": {"schema": {}}}
29
+
30
+ _VALID_STYLES: dict[str, frozenset[str]] = {
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
+
22
71
 
23
72
  @dataclass
24
73
  class OpenApi30:
@@ -31,6 +80,7 @@ class OpenApi30:
31
80
  value["components"] = {
32
81
  "parameters": {"SampleParameter": PARAMETER_SAMPLE},
33
82
  "responses": {"Success": RESPONSE_SUCCESS},
83
+ "securitySchemes": {DEFAULT_SECURITY_SCHEME: {"type": "apiKey", "name": "X-Api-Key", "in": "header"}},
34
84
  }
35
85
  return value
36
86
 
@@ -52,8 +102,11 @@ class PathItem:
52
102
  class Operation:
53
103
  operationId: str | Missing
54
104
  parameters: ParameterList | Missing
55
- tags: UniqueList[str] | Missing # type: ignore[type-arg,valid-type]
105
+ tags: UniqueList[str] | Missing # type: ignore[type-arg]
56
106
  responses: dict[ResponseId, Response | ResponseReference] # type: ignore[valid-type]
107
+ requestBody: RequestBody | Missing
108
+ security: OperationSecurityRequirement | Missing
109
+ deprecated: bool | Missing
57
110
 
58
111
  def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
59
112
  if not value["responses"]:
@@ -70,12 +123,17 @@ class Parameter:
70
123
  allowEmptyValue: bool
71
124
  allowReserved: bool
72
125
  explode: bool
126
+ style: Literal["form", "simple", "label", "matrix", "spaceDelimited", "pipeDelimited", "deepObject"] | Missing
127
+ schema: ParameterSchema
73
128
 
74
129
  def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
75
- value["in"] = value.pop("in_")
76
- value["schema"] = {"type": "string"}
77
- if value["in"] == "path":
130
+ in_ = value.pop("in_")
131
+ value["in"] = in_
132
+ if in_ == "path":
78
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"]
79
137
  return value
80
138
 
81
139
  def __hash__(self) -> int:
File without changes
@@ -0,0 +1,46 @@
1
+ import pytest
2
+ from hypothesis import HealthCheck, given, settings
3
+ from referencing import Registry, Resource
4
+ from referencing.jsonschema import DRAFT4
5
+
6
+ from hypothesis_openapi import openapis
7
+
8
+ from .v2 import VALIDATOR as SWAGGER_VALIDATOR
9
+ from .v3 import VALIDATOR as OPENAPI_30_VALIDATOR
10
+
11
+
12
+ def assert_resolvable_references(spec, specification):
13
+ resource = Resource(contents=spec, specification=specification)
14
+ registry = Registry().with_resource(uri="urn:root", resource=resource)
15
+ _assert_resolvable_references(registry, spec)
16
+
17
+
18
+ def _assert_resolvable_references(registry, spec):
19
+ if isinstance(spec, dict):
20
+ for key, value in spec.items():
21
+ if key == "$ref":
22
+ registry.resolver().lookup(f"urn:root{value}")
23
+ else:
24
+ _assert_resolvable_references(registry, value)
25
+ elif isinstance(spec, list):
26
+ for item in spec:
27
+ _assert_resolvable_references(registry, item)
28
+
29
+
30
+ @given(openapis(version="2.0"))
31
+ @settings(deadline=None, suppress_health_check=[HealthCheck.too_slow])
32
+ def test_swagger(spec):
33
+ SWAGGER_VALIDATOR.validate(spec)
34
+ assert_resolvable_references(spec, DRAFT4)
35
+
36
+
37
+ @given(openapis(version="3.0"))
38
+ @settings(deadline=None, suppress_health_check=[HealthCheck.too_slow])
39
+ def test_openapi_30(spec):
40
+ OPENAPI_30_VALIDATOR.validate(spec)
41
+ assert_resolvable_references(spec, DRAFT4)
42
+
43
+
44
+ def test_unsupported_version():
45
+ with pytest.raises(ValueError):
46
+ openapis(version="45.0")