hypothesis-openapi 0.2.1__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.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: hypothesis-openapi
3
- Version: 0.2.1
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.0,>=6.84.3
29
+ Requires-Dist: hypothesis<7,>=6.108.0
28
30
  Provides-Extra: bench
29
- Requires-Dist: pytest-codspeed==2.2.1; extra == 'bench'
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,15 +37,15 @@ 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==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'
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'
41
43
  Requires-Dist: referencing>=0.35; extra == 'dev'
42
44
  Provides-Extra: tests
43
45
  Requires-Dist: coverage>=7; extra == 'tests'
44
46
  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'
47
+ Requires-Dist: pytest-xdist<4.0,>=3; extra == 'tests'
48
+ Requires-Dist: pytest<10,>=8; extra == 'tests'
47
49
  Requires-Dist: referencing>=0.35; extra == 'tests'
48
50
  Description-Content-Type: text/markdown
49
51
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "hypothesis-openapi"
3
- version = "0.2.1"
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,7 +26,7 @@ license = "MIT"
24
26
  include = ["src/hypothesis_openapi/py.typed"]
25
27
  requires-python = ">=3.10"
26
28
  dependencies = [
27
- "hypothesis>=6.84.3,<7.0",
29
+ "hypothesis>=6.108.0,<7",
28
30
  ]
29
31
 
30
32
  [project.optional-dependencies]
@@ -32,15 +34,15 @@ tests = [
32
34
  "coverage>=7",
33
35
  "jsonschema>=4.21.0",
34
36
  "referencing>=0.35",
35
- "pytest>=6.2.0,<8",
36
- "pytest-xdist>=2.5,<3.0",
37
+ "pytest>=8,<10",
38
+ "pytest-xdist>=3,<4.0",
37
39
  ]
38
40
  cov = [
39
41
  "coverage-enable-subprocess",
40
42
  "coverage[toml]>=7",
41
43
  ]
42
44
  bench = [
43
- "pytest-codspeed==2.2.1",
45
+ "pytest-codspeed==4.2.0",
44
46
  ]
45
47
  dev = ["hypothesis_openapi[tests,cov,bench]"]
46
48
 
@@ -80,27 +82,32 @@ target-version = "py310"
80
82
 
81
83
  [tool.ruff.lint]
82
84
  select = [
83
- "E", # pycodestyle errors
84
- "W", # pycodestyle warnings
85
- "F", # pyflakes
86
- "C", # flake8-comprehensions
87
- "B", # flake8-bugbear
88
- "D", # pydocstyle
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
89
95
  ]
90
96
  ignore = [
91
- "E501", # Line too long
92
- "B008", # Do not perform function calls in argument defaults
93
- "C901", # Too complex
94
- "D100", # Missing docstring in public module
95
- "D101", # Missing docstring in public class
96
- "D102", # Missing docstring in public method
97
- "D103", # Missing docstring in public function
98
- "D104", # Missing docstring in public package
99
- "D105", # Missing docstring in magic method
100
- "D107", # Missing docstring in `__init__`
101
- "D203", # One blank line before class
102
- "D213", # Multiline summary second line
103
- "D401", # Imperative mood
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
104
111
  ]
105
112
 
106
113
  [tool.ruff.format]
@@ -108,6 +115,10 @@ skip-magic-trailing-comma = false
108
115
 
109
116
  [tool.ruff.lint.per-file-ignores]
110
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"]
111
122
 
112
123
  [tool.ruff.lint.isort]
113
124
  known-first-party = ["hypothesis_openapi"]
@@ -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:
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]]":
@@ -5,12 +5,15 @@ 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
- reference,
13
+ OperationSecurityRequirement,
12
14
  PathItemReference,
13
15
  Response,
16
+ reference,
14
17
  )
15
18
  from ._types import CombinedDict, Missing, Pattern, UniqueList
16
19
 
@@ -19,6 +22,14 @@ ResponseId: TypeAlias = Pattern[r"^([0-9]{3})$|^(default)\Z"] # type: ignore[ty
19
22
  ParameterReference = reference("#/parameters/SampleParameter")
20
23
  ResponseReference = reference("#/responses/Success")
21
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
32
+
22
33
  MediaType = (
23
34
  Literal["application/json"]
24
35
  | Literal["application/xml"]
@@ -39,9 +50,10 @@ class Swagger:
39
50
  paths: dict[Pattern["^/"], PathItem | PathItemReference] # type: ignore[type-arg,valid-type]
40
51
  consumes: MediaTypeList | Missing
41
52
  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]
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]
44
55
  definitions: Definitions
56
+ securityDefinitions: CombinedDict[str, SecurityScheme, _SECURITY_DEFAULTS] | Missing # type: ignore[type-arg,valid-type]
45
57
 
46
58
  def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
47
59
  value["x-paths"] = {"Entry": PATH_ITEM_SAMPLE}
@@ -73,6 +85,8 @@ class Operation:
73
85
  consumes: MediaTypeList | Missing
74
86
  produces: MediaTypeList | Missing
75
87
  responses: dict[ResponseId, Response | ResponseReference] # type: ignore[valid-type]
88
+ security: OperationSecurityRequirement | Missing
89
+ deprecated: bool | Missing
76
90
 
77
91
  def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
78
92
  if not value["responses"]:
@@ -97,9 +111,14 @@ class BodyParameter:
97
111
  class QueryParameter:
98
112
  name: str
99
113
  type: Literal["string", "number", "boolean", "integer", "array"]
114
+ collectionFormat: Literal["csv", "ssv", "tsv", "pipes"] | Missing
100
115
 
101
116
  def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
102
117
  value["in"] = "query"
118
+ if value["type"] == "array":
119
+ value["items"] = {"type": "string"}
120
+ elif "collectionFormat" in value:
121
+ del value["collectionFormat"]
103
122
  return value
104
123
 
105
124
  def __hash__(self) -> int:
@@ -113,6 +132,8 @@ class HeaderParameter:
113
132
 
114
133
  def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
115
134
  value["in"] = "header"
135
+ if value["type"] == "array":
136
+ value["items"] = {"type": "string"}
116
137
  return value
117
138
 
118
139
  def __hash__(self) -> int:
@@ -127,6 +148,8 @@ class PathParameter:
127
148
  def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
128
149
  value["in"] = "path"
129
150
  value["required"] = True
151
+ if value["type"] == "array":
152
+ value["items"] = {"type": "string"}
130
153
  return value
131
154
 
132
155
  def __hash__(self) -> int:
@@ -137,9 +160,14 @@ class PathParameter:
137
160
  class FormDataParameter:
138
161
  name: str
139
162
  type: Literal["string", "number", "boolean", "integer", "array", "file"]
163
+ collectionFormat: Literal["csv", "ssv", "tsv", "pipes"] | Missing
140
164
 
141
165
  def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
142
166
  value["in"] = "formData"
167
+ if value["type"] == "array":
168
+ value["items"] = {"type": "string"}
169
+ elif "collectionFormat" in value:
170
+ del value["collectionFormat"]
143
171
  return value
144
172
 
145
173
  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] = {"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
+
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
 
@@ -54,6 +104,9 @@ class Operation:
54
104
  parameters: ParameterList | Missing
55
105
  tags: UniqueList[str] | Missing # type: ignore[type-arg,valid-type]
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: