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