hypothesis-openapi 0.1.0__tar.gz → 0.2.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.1.0 → hypothesis_openapi-0.2.0}/PKG-INFO +5 -2
- {hypothesis_openapi-0.1.0 → hypothesis_openapi-0.2.0}/README.md +1 -1
- {hypothesis_openapi-0.1.0 → hypothesis_openapi-0.2.0}/pyproject.toml +5 -2
- hypothesis_openapi-0.2.0/src/hypothesis_openapi/_common.py +42 -0
- {hypothesis_openapi-0.1.0 → hypothesis_openapi-0.2.0}/src/hypothesis_openapi/_strategies.py +3 -0
- {hypothesis_openapi-0.1.0 → hypothesis_openapi-0.2.0}/src/hypothesis_openapi/_v2.py +17 -70
- hypothesis_openapi-0.2.0/src/hypothesis_openapi/_v3.py +74 -0
- {hypothesis_openapi-0.1.0 → hypothesis_openapi-0.2.0}/.gitignore +0 -0
- {hypothesis_openapi-0.1.0 → hypothesis_openapi-0.2.0}/LICENSE +0 -0
- {hypothesis_openapi-0.1.0 → hypothesis_openapi-0.2.0}/src/hypothesis_openapi/__init__.py +0 -0
- {hypothesis_openapi-0.1.0 → hypothesis_openapi-0.2.0}/src/hypothesis_openapi/_serialize.py +0 -0
- {hypothesis_openapi-0.1.0 → hypothesis_openapi-0.2.0}/src/hypothesis_openapi/_types.py +0 -0
- {hypothesis_openapi-0.1.0 → hypothesis_openapi-0.2.0}/src/hypothesis_openapi/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: hypothesis-openapi
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.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
|
|
@@ -25,6 +25,8 @@ Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
|
25
25
|
Classifier: Topic :: Software Development :: Testing
|
|
26
26
|
Requires-Python: >=3.10
|
|
27
27
|
Requires-Dist: hypothesis<7.0,>=6.84.3
|
|
28
|
+
Provides-Extra: bench
|
|
29
|
+
Requires-Dist: pytest-codspeed==2.2.1; extra == 'bench'
|
|
28
30
|
Provides-Extra: cov
|
|
29
31
|
Requires-Dist: coverage-enable-subprocess; extra == 'cov'
|
|
30
32
|
Requires-Dist: coverage[toml]>=7; extra == 'cov'
|
|
@@ -33,6 +35,7 @@ Requires-Dist: coverage-enable-subprocess; extra == 'dev'
|
|
|
33
35
|
Requires-Dist: coverage>=7; extra == 'dev'
|
|
34
36
|
Requires-Dist: coverage[toml]>=7; extra == 'dev'
|
|
35
37
|
Requires-Dist: jsonschema>=4.21.0; extra == 'dev'
|
|
38
|
+
Requires-Dist: pytest-codspeed==2.2.1; extra == 'dev'
|
|
36
39
|
Requires-Dist: pytest-xdist<3.0,>=2.5; extra == 'dev'
|
|
37
40
|
Requires-Dist: pytest<8,>=6.2.0; extra == 'dev'
|
|
38
41
|
Provides-Extra: tests
|
|
@@ -44,7 +47,7 @@ Description-Content-Type: text/markdown
|
|
|
44
47
|
|
|
45
48
|
# hypothesis-openapi
|
|
46
49
|
|
|
47
|
-
[](https://github.com/Stranger6667/hypothesis-openapi/actions/workflows/ci.yml)
|
|
48
51
|
[](https://codecov.io/gh/Stranger6667/hypothesis-openapi/branch/main)
|
|
49
52
|
[](https://pypi.org/project/hypothesis-openapi/)
|
|
50
53
|
[](https://pypi.org/project/hypothesis-openapi/)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# hypothesis-openapi
|
|
2
2
|
|
|
3
|
-
[](https://github.com/Stranger6667/hypothesis-openapi/actions/workflows/ci.yml)
|
|
4
4
|
[](https://codecov.io/gh/Stranger6667/hypothesis-openapi/branch/main)
|
|
5
5
|
[](https://pypi.org/project/hypothesis-openapi/)
|
|
6
6
|
[](https://pypi.org/project/hypothesis-openapi/)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "hypothesis-openapi"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.2.0"
|
|
4
4
|
description = "Hypothesis plugin for generating valid Open API documents"
|
|
5
5
|
keywords = ["hypothesis", "openapi", "testing"]
|
|
6
6
|
classifiers = [
|
|
@@ -38,7 +38,10 @@ cov = [
|
|
|
38
38
|
"coverage-enable-subprocess",
|
|
39
39
|
"coverage[toml]>=7",
|
|
40
40
|
]
|
|
41
|
-
|
|
41
|
+
bench = [
|
|
42
|
+
"pytest-codspeed==2.2.1",
|
|
43
|
+
]
|
|
44
|
+
dev = ["hypothesis_openapi[tests,cov,bench]"]
|
|
42
45
|
|
|
43
46
|
[project.urls]
|
|
44
47
|
Changelog = "https://github.com/Stranger6667/hypothesis-openapi/blob/main/CHANGELOG.md"
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# ruff: noqa: F722, F821
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
from typing import Any, Literal
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@dataclass
|
|
7
|
+
class Info:
|
|
8
|
+
version: Literal["1.0.0"]
|
|
9
|
+
title: Literal["Example API"]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass
|
|
13
|
+
class PathItemReference:
|
|
14
|
+
def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
|
|
15
|
+
value["$ref"] = "#/x-paths/Entry"
|
|
16
|
+
return value
|
|
17
|
+
|
|
18
|
+
|
|
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
|
+
@dataclass
|
|
30
|
+
class Response:
|
|
31
|
+
description: Literal["Ok"]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@dataclass
|
|
35
|
+
class ResponseReference:
|
|
36
|
+
def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
|
|
37
|
+
value["$ref"] = "#/responses/Success"
|
|
38
|
+
return value
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
RESPONSE_SUCCESS = {"description": "OK"}
|
|
42
|
+
PATH_ITEM_SAMPLE = {"get": {"responses": {"default": RESPONSE_SUCCESS}}}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
from typing import Any, Literal
|
|
2
2
|
from hypothesis import strategies as st
|
|
3
3
|
from ._v2 import Swagger
|
|
4
|
+
from ._v3 import OpenApi30
|
|
4
5
|
from ._serialize import asdict
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
def openapis(version: Literal["2.0"] | Literal["3.0"] | Literal["3.1"]) -> "st.SearchStrategy[dict[str, Any]]":
|
|
8
9
|
if version == "2.0":
|
|
9
10
|
return st.from_type(Swagger).map(asdict) # type: ignore[arg-type]
|
|
11
|
+
if version == "3.0":
|
|
12
|
+
return st.from_type(OpenApi30).map(asdict) # type: ignore[arg-type]
|
|
10
13
|
raise ValueError(f"Unsupported version: {version}")
|
|
@@ -4,33 +4,19 @@ from __future__ import annotations
|
|
|
4
4
|
from dataclasses import dataclass, field
|
|
5
5
|
from typing import Any, Literal, TypeAlias
|
|
6
6
|
|
|
7
|
+
from ._common import (
|
|
8
|
+
PATH_ITEM_SAMPLE,
|
|
9
|
+
RESPONSE_SUCCESS,
|
|
10
|
+
Info,
|
|
11
|
+
ParameterReference,
|
|
12
|
+
PathItemReference,
|
|
13
|
+
Response,
|
|
14
|
+
ResponseReference,
|
|
15
|
+
)
|
|
7
16
|
from ._types import CombinedDict, Missing, Pattern, UniqueList
|
|
8
17
|
|
|
9
|
-
RESPONSE_SUCCESS = {"description": "OK"}
|
|
10
|
-
PATH_ITEM_SAMPLE = {"get": {"responses": {"default": RESPONSE_SUCCESS}}}
|
|
11
18
|
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
|
-
|
|
19
|
+
ResponseId: TypeAlias = Pattern[r"^([0-9]{3})$|^(default)\Z"] # type: ignore[type-arg,valid-type]
|
|
34
20
|
|
|
35
21
|
MediaType = (
|
|
36
22
|
Literal["application/json"]
|
|
@@ -66,12 +52,6 @@ class Definitions:
|
|
|
66
52
|
pass
|
|
67
53
|
|
|
68
54
|
|
|
69
|
-
@dataclass
|
|
70
|
-
class Info:
|
|
71
|
-
version: Literal["1.0.0"]
|
|
72
|
-
title: Literal["Example API"]
|
|
73
|
-
|
|
74
|
-
|
|
75
55
|
@dataclass
|
|
76
56
|
class PathItem:
|
|
77
57
|
get: Operation | Missing
|
|
@@ -83,11 +63,6 @@ class PathItem:
|
|
|
83
63
|
patch: Operation | Missing
|
|
84
64
|
parameters: ParameterList | Missing
|
|
85
65
|
|
|
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
66
|
|
|
92
67
|
@dataclass
|
|
93
68
|
class Operation:
|
|
@@ -96,41 +71,14 @@ class Operation:
|
|
|
96
71
|
tags: UniqueList[str] | Missing # type: ignore[type-arg,valid-type]
|
|
97
72
|
consumes: MediaTypeList | Missing
|
|
98
73
|
produces: MediaTypeList | Missing
|
|
99
|
-
responses: dict[ResponseId, Response]
|
|
74
|
+
responses: dict[ResponseId, Response | ResponseReference]
|
|
100
75
|
|
|
101
76
|
def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
|
|
102
77
|
if not value["responses"]:
|
|
103
78
|
value["responses"] = {"default": RESPONSE_SUCCESS}
|
|
104
|
-
if "parameters" in value:
|
|
105
|
-
value["parameters"] = deduplicate_parameters(value["parameters"])
|
|
106
79
|
return value
|
|
107
80
|
|
|
108
81
|
|
|
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
82
|
@dataclass
|
|
135
83
|
class BodyParameter:
|
|
136
84
|
name: str
|
|
@@ -141,7 +89,7 @@ class BodyParameter:
|
|
|
141
89
|
return value
|
|
142
90
|
|
|
143
91
|
def __hash__(self) -> int:
|
|
144
|
-
return hash(self.name)
|
|
92
|
+
return hash((self.name, "body"))
|
|
145
93
|
|
|
146
94
|
|
|
147
95
|
@dataclass
|
|
@@ -154,7 +102,7 @@ class QueryParameter:
|
|
|
154
102
|
return value
|
|
155
103
|
|
|
156
104
|
def __hash__(self) -> int:
|
|
157
|
-
return hash(self.name)
|
|
105
|
+
return hash((self.name, "query"))
|
|
158
106
|
|
|
159
107
|
|
|
160
108
|
@dataclass
|
|
@@ -167,7 +115,7 @@ class HeaderParameter:
|
|
|
167
115
|
return value
|
|
168
116
|
|
|
169
117
|
def __hash__(self) -> int:
|
|
170
|
-
return hash(self.name)
|
|
118
|
+
return hash((self.name, "header"))
|
|
171
119
|
|
|
172
120
|
|
|
173
121
|
@dataclass
|
|
@@ -181,7 +129,7 @@ class PathParameter:
|
|
|
181
129
|
return value
|
|
182
130
|
|
|
183
131
|
def __hash__(self) -> int:
|
|
184
|
-
return hash(self.name)
|
|
132
|
+
return hash((self.name, "path"))
|
|
185
133
|
|
|
186
134
|
|
|
187
135
|
@dataclass
|
|
@@ -194,10 +142,9 @@ class FormDataParameter:
|
|
|
194
142
|
return value
|
|
195
143
|
|
|
196
144
|
def __hash__(self) -> int:
|
|
197
|
-
return hash(self.name)
|
|
145
|
+
return hash((self.name, "formData"))
|
|
198
146
|
|
|
199
147
|
|
|
200
148
|
Parameter = BodyParameter | QueryParameter | HeaderParameter | PathParameter | FormDataParameter
|
|
201
|
-
ParameterList =
|
|
149
|
+
ParameterList: TypeAlias = UniqueList[Parameter | ParameterReference] # type: ignore[type-arg]
|
|
202
150
|
MediaTypeList: TypeAlias = UniqueList[MediaType] # type: ignore[type-arg]
|
|
203
|
-
ResponseId: TypeAlias = Pattern["^([0-9]{3})$|^(default)$"] # type: ignore[type-arg,valid-type]
|
|
@@ -0,0 +1,74 @@
|
|
|
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
|
|
File without changes
|