hypothesis-openapi 0.2.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: hypothesis-openapi
3
- Version: 0.2.0
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
@@ -38,11 +38,13 @@ Requires-Dist: jsonschema>=4.21.0; extra == 'dev'
38
38
  Requires-Dist: pytest-codspeed==2.2.1; extra == 'dev'
39
39
  Requires-Dist: pytest-xdist<3.0,>=2.5; extra == 'dev'
40
40
  Requires-Dist: pytest<8,>=6.2.0; extra == 'dev'
41
+ Requires-Dist: referencing>=0.35; extra == 'dev'
41
42
  Provides-Extra: tests
42
43
  Requires-Dist: coverage>=7; extra == 'tests'
43
44
  Requires-Dist: jsonschema>=4.21.0; extra == 'tests'
44
45
  Requires-Dist: pytest-xdist<3.0,>=2.5; extra == 'tests'
45
46
  Requires-Dist: pytest<8,>=6.2.0; extra == 'tests'
47
+ Requires-Dist: referencing>=0.35; extra == 'tests'
46
48
  Description-Content-Type: text/markdown
47
49
 
48
50
  # hypothesis-openapi
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "hypothesis-openapi"
3
- version = "0.2.0"
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
  ]
@@ -1,6 +1,6 @@
1
1
  # ruff: noqa: F722, F821
2
2
  from dataclasses import dataclass
3
- from typing import Any, Literal
3
+ from typing import Any, Literal, Type
4
4
 
5
5
 
6
6
  @dataclass
@@ -16,26 +16,22 @@ class PathItemReference:
16
16
  return value
17
17
 
18
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
19
  @dataclass
30
20
  class Response:
31
21
  description: Literal["Ok"]
32
22
 
33
23
 
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
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
39
35
 
40
36
 
41
37
  RESPONSE_SUCCESS = {"description": "OK"}
@@ -11,7 +11,7 @@ class Pattern:
11
11
 
12
12
  class UniqueList:
13
13
  def __class_getitem__(cls, inner: type) -> object:
14
- strategy = st.lists(st.from_type(inner), unique=True)
14
+ strategy = st.lists(st.from_type(inner), unique_by=hash)
15
15
  return Annotated[list, strategy]
16
16
 
17
17
 
@@ -8,15 +8,16 @@ from ._common import (
8
8
  PATH_ITEM_SAMPLE,
9
9
  RESPONSE_SUCCESS,
10
10
  Info,
11
- ParameterReference,
11
+ reference,
12
12
  PathItemReference,
13
13
  Response,
14
- ResponseReference,
15
14
  )
16
15
  from ._types import CombinedDict, Missing, Pattern, UniqueList
17
16
 
18
17
  PARAMETER_SAMPLE = {"name": "sample", "in": "query", "type": "string"}
19
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")
20
21
 
21
22
  MediaType = (
22
23
  Literal["application/json"]
@@ -71,7 +72,7 @@ class Operation:
71
72
  tags: UniqueList[str] | Missing # type: ignore[type-arg,valid-type]
72
73
  consumes: MediaTypeList | Missing
73
74
  produces: MediaTypeList | Missing
74
- responses: dict[ResponseId, Response | ResponseReference]
75
+ responses: dict[ResponseId, Response | ResponseReference] # type: ignore[valid-type]
75
76
 
76
77
  def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
77
78
  if not value["responses"]:
@@ -146,5 +147,5 @@ class FormDataParameter:
146
147
 
147
148
 
148
149
  Parameter = BodyParameter | QueryParameter | HeaderParameter | PathParameter | FormDataParameter
149
- ParameterList: TypeAlias = UniqueList[Parameter | ParameterReference] # type: ignore[type-arg]
150
+ ParameterList: TypeAlias = UniqueList[Parameter | ParameterReference] # type: ignore[type-arg, valid-type]
150
151
  MediaTypeList: TypeAlias = UniqueList[MediaType] # type: ignore[type-arg]
@@ -7,22 +7,33 @@ from typing import Any, Literal, TypeAlias
7
7
  from ._common import (
8
8
  RESPONSE_SUCCESS,
9
9
  Info,
10
- ParameterReference,
10
+ reference,
11
+ PATH_ITEM_SAMPLE,
11
12
  PathItemReference,
12
13
  Response,
13
- ResponseReference,
14
14
  )
15
15
  from ._types import Missing, Pattern, UniqueList
16
16
 
17
+ PARAMETER_SAMPLE = {"name": "sample", "in": "query", "schema": {"type": "string"}}
17
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")
18
21
 
19
22
 
20
23
  @dataclass
21
24
  class OpenApi30:
22
- openapi: Pattern["^3\\.0\\.\\d$"] # type: ignore[type-arg,valid-type]
25
+ openapi: Pattern[r"^3\.0\.[0-9]\Z"] # type: ignore[type-arg,valid-type]
23
26
  info: Info
24
27
  paths: dict[Pattern["^/"], PathItem | PathItemReference] # type: ignore[type-arg,valid-type]
25
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
+
26
37
 
27
38
  @dataclass
28
39
  class PathItem:
@@ -42,7 +53,7 @@ class Operation:
42
53
  operationId: str | Missing
43
54
  parameters: ParameterList | Missing
44
55
  tags: UniqueList[str] | Missing # type: ignore[type-arg,valid-type]
45
- responses: dict[ResponseId, Response | ResponseReference]
56
+ responses: dict[ResponseId, Response | ResponseReference] # type: ignore[valid-type]
46
57
 
47
58
  def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
48
59
  if not value["responses"]:
@@ -71,4 +82,4 @@ class Parameter:
71
82
  return hash((self.name, self.in_))
72
83
 
73
84
 
74
- ParameterList: TypeAlias = UniqueList[Parameter | ParameterReference] # type: ignore[type-arg]
85
+ ParameterList: TypeAlias = UniqueList[Parameter | ParameterReference] # type: ignore[type-arg,valid-type]