hypothesis-openapi 0.3.0__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.4
1
+ Metadata-Version: 2.5
2
2
  Name: hypothesis-openapi
3
- Version: 0.3.0
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,40 +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
24
23
  Classifier: Programming Language :: Python :: 3.13
25
24
  Classifier: Programming Language :: Python :: 3.14
25
+ Classifier: Programming Language :: Python :: 3.15
26
26
  Classifier: Programming Language :: Python :: Implementation :: CPython
27
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
27
28
  Classifier: Topic :: Software Development :: Testing
28
- Requires-Python: >=3.10
29
+ Classifier: Typing :: Typed
30
+ Requires-Python: >=3.11
29
31
  Requires-Dist: hypothesis<7,>=6.108.0
30
32
  Provides-Extra: bench
31
33
  Requires-Dist: pytest-codspeed==4.2.0; extra == 'bench'
32
- Provides-Extra: cov
33
- Requires-Dist: coverage-enable-subprocess; extra == 'cov'
34
- Requires-Dist: coverage[toml]>=7; extra == 'cov'
35
34
  Provides-Extra: dev
36
- Requires-Dist: coverage-enable-subprocess; extra == 'dev'
37
- Requires-Dist: coverage>=7; extra == 'dev'
38
- Requires-Dist: coverage[toml]>=7; extra == 'dev'
35
+ Requires-Dist: coverage[toml]>=7.2; extra == 'dev'
39
36
  Requires-Dist: jsonschema>=4.21.0; extra == 'dev'
40
37
  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'
38
+ Requires-Dist: pytest>=8; extra == 'dev'
43
39
  Requires-Dist: referencing>=0.35; extra == 'dev'
44
40
  Provides-Extra: tests
45
- Requires-Dist: coverage>=7; extra == 'tests'
41
+ Requires-Dist: coverage[toml]>=7.2; extra == 'tests'
46
42
  Requires-Dist: jsonschema>=4.21.0; extra == 'tests'
47
- Requires-Dist: pytest-xdist<4.0,>=3; extra == 'tests'
48
- Requires-Dist: pytest<10,>=8; extra == 'tests'
43
+ Requires-Dist: pytest>=8; extra == 'tests'
49
44
  Requires-Dist: referencing>=0.35; extra == 'tests'
50
45
  Description-Content-Type: text/markdown
51
46
 
52
47
  # hypothesis-openapi
53
48
 
54
- [![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)
55
50
  [![Coverage](https://codecov.io/gh/Stranger6667/hypothesis-openapi/branch/main/graph/badge.svg)](https://codecov.io/gh/Stranger6667/hypothesis-openapi/branch/main)
56
51
  [![Version](https://img.shields.io/pypi/v/hypothesis-openapi.svg)](https://pypi.org/project/hypothesis-openapi/)
57
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/)
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "hypothesis-openapi"
3
- version = "0.3.0"
3
+ dynamic = ["version"]
4
4
  description = "Hypothesis plugin for generating valid Open API documents"
5
5
  keywords = ["hypothesis", "openapi", "testing"]
6
6
  classifiers = [
@@ -11,52 +11,53 @@ classifiers = [
11
11
  "License :: OSI Approved :: MIT License",
12
12
  "Operating System :: OS Independent",
13
13
  "Programming Language :: Python :: 3 :: Only",
14
- "Programming Language :: Python :: 3.10",
15
14
  "Programming Language :: Python :: 3.11",
16
15
  "Programming Language :: Python :: 3.12",
17
16
  "Programming Language :: Python :: 3.13",
18
17
  "Programming Language :: Python :: 3.14",
18
+ "Programming Language :: Python :: 3.15",
19
19
  "Programming Language :: Python :: Implementation :: CPython",
20
+ "Programming Language :: Python :: Implementation :: PyPy",
20
21
  "Topic :: Software Development :: Testing",
22
+ "Typing :: Typed",
21
23
  ]
22
24
  authors = [{ name = "Dmitry Dygalo", email = "dmitry@dygalo.dev" }]
23
25
  maintainers = [{ name = "Dmitry Dygalo", email = "dmitry@dygalo.dev" }]
24
26
  readme = "README.md"
25
27
  license = "MIT"
26
- include = ["src/hypothesis_openapi/py.typed"]
27
- requires-python = ">=3.10"
28
+ requires-python = ">=3.11"
28
29
  dependencies = [
29
30
  "hypothesis>=6.108.0,<7",
30
31
  ]
31
32
 
32
33
  [project.optional-dependencies]
33
34
  tests = [
34
- "coverage>=7",
35
+ "coverage[toml]>=7.2",
35
36
  "jsonschema>=4.21.0",
36
37
  "referencing>=0.35",
37
- "pytest>=8,<10",
38
- "pytest-xdist>=3,<4.0",
39
- ]
40
- cov = [
41
- "coverage-enable-subprocess",
42
- "coverage[toml]>=7",
38
+ "pytest>=8",
43
39
  ]
44
40
  bench = [
45
41
  "pytest-codspeed==4.2.0",
46
42
  ]
47
- dev = ["hypothesis_openapi[tests,cov,bench]"]
43
+ dev = ["hypothesis_openapi[tests,bench]"]
48
44
 
49
45
  [project.urls]
50
46
  Changelog = "https://github.com/Stranger6667/hypothesis-openapi/blob/main/CHANGELOG.md"
51
- "Bug Tracker" = "https://github.com/Stranger6667/hypothesis-openapi"
47
+ "Bug Tracker" = "https://github.com/Stranger6667/hypothesis-openapi/issues"
52
48
  Funding = "https://github.com/sponsors/Stranger6667"
53
49
  "Source Code" = "https://github.com/Stranger6667/hypothesis-openapi"
54
50
 
51
+ [tool.hatch.version]
52
+ path = "src/hypothesis_openapi/__init__.py"
53
+
55
54
  [tool.hatch.build.targets.sdist]
56
- include = [
57
- "/src",
58
- "/test",
59
- ]
55
+ include = ["/src", "/tests"]
56
+
57
+ [tool.pytest.ini_options]
58
+ addopts = ["-ra", "--strict-markers", "--strict-config"]
59
+ xfail_strict = true
60
+ testpaths = ["tests"]
60
61
 
61
62
  [tool.coverage.run]
62
63
  parallel = true
@@ -64,12 +65,13 @@ branch = true
64
65
  source_pkgs = ["hypothesis_openapi"]
65
66
 
66
67
  [tool.coverage.paths]
67
- source = ["src", ".tox/*/site-packages"]
68
+ source = ["src", ".tox/*/site-packages", ".tox/*/lib/*/site-packages", ".tox/*/Lib/site-packages"]
68
69
 
69
70
  [tool.coverage.report]
70
71
  show_missing = true
71
72
  skip_covered = true
72
73
  precision = 2
74
+ fail_under = 100
73
75
  exclude_lines = [
74
76
  "raise NotImplementedError",
75
77
  "if TYPE_CHECKING:",
@@ -78,7 +80,7 @@ exclude_lines = [
78
80
 
79
81
  [tool.ruff]
80
82
  line-length = 120
81
- target-version = "py310"
83
+ target-version = "py311"
82
84
 
83
85
  [tool.ruff.lint]
84
86
  select = [
@@ -88,10 +90,12 @@ select = [
88
90
  "C", # flake8-comprehensions
89
91
  "B", # flake8-bugbear
90
92
  "D", # pydocstyle
93
+ "T201", # flake8-print
91
94
  "I", # isort
92
- "UP", # pyupgrade
93
95
  "FURB", # refurb
94
96
  "PGH003", # blanket-type-ignore
97
+ "UP", # pyupgrade
98
+ "SIM", # flake8-simplify
95
99
  ]
96
100
  ignore = [
97
101
  "E501", # Line too long
@@ -103,10 +107,13 @@ ignore = [
103
107
  "D103", # Missing docstring in public function
104
108
  "D104", # Missing docstring in public package
105
109
  "D105", # Missing docstring in magic method
110
+ "D106", # Missing docstring in public nested class
106
111
  "D107", # Missing docstring in `__init__`
112
+ "D202", # No blank lines allowed after function docstring
107
113
  "D203", # One blank line before class
108
114
  "D213", # Multiline summary second line
109
115
  "D401", # Imperative mood
116
+ "D407", # Missing dashed underline after section
110
117
  "COM812", # trailing comma
111
118
  ]
112
119
 
@@ -1 +1,3 @@
1
1
  from ._strategies import openapis
2
+
3
+ __version__ = "0.4.0"
@@ -36,7 +36,7 @@ class ApiKeyScheme:
36
36
 
37
37
  @dataclass
38
38
  class OperationSecurityRequirement:
39
- def map_value(self, value: dict[str, Any]) -> list:
39
+ def map_value(self, value: dict[str, Any]) -> list[dict[str, list[str]]]:
40
40
  return [{DEFAULT_SECURITY_SCHEME: []}]
41
41
 
42
42
 
@@ -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,7 +2,9 @@
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 (
8
10
  DEFAULT_SECURITY_SCHEME,
@@ -81,7 +83,7 @@ class PathItem:
81
83
  class Operation:
82
84
  operationId: str | Missing
83
85
  parameters: ParameterList | Missing
84
- tags: UniqueList[str] | Missing # type: ignore[type-arg,valid-type]
86
+ tags: UniqueList[str] | Missing # type: ignore[type-arg]
85
87
  consumes: MediaTypeList | Missing
86
88
  produces: MediaTypeList | Missing
87
89
  responses: dict[ResponseId, Response | ResponseReference] # type: ignore[valid-type]
@@ -97,7 +99,8 @@ class Operation:
97
99
  @dataclass
98
100
  class BodyParameter:
99
101
  name: str
100
- 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)
101
104
 
102
105
  def map_value(self, value: dict[str, Any]) -> dict[str, Any]:
103
106
  value["in"] = "body"
@@ -25,9 +25,9 @@ RequestBodyMediaType = (
25
25
  Literal["application/json"] | Literal["application/x-www-form-urlencoded"] | Literal["multipart/form-data"]
26
26
  )
27
27
 
28
- _REQUEST_BODY_DEFAULTS: dict[str, dict] = {"application/json": {"schema": {}}}
28
+ _REQUEST_BODY_DEFAULTS: dict[str, dict[str, Any]] = {"application/json": {"schema": {}}}
29
29
 
30
- _VALID_STYLES: dict[str, frozenset] = {
30
+ _VALID_STYLES: dict[str, frozenset[str]] = {
31
31
  "query": frozenset({"form", "spaceDelimited", "pipeDelimited", "deepObject"}),
32
32
  "path": frozenset({"simple", "label", "matrix"}),
33
33
  "header": frozenset({"simple"}),
@@ -102,7 +102,7 @@ class PathItem:
102
102
  class Operation:
103
103
  operationId: str | Missing
104
104
  parameters: ParameterList | Missing
105
- tags: UniqueList[str] | Missing # type: ignore[type-arg,valid-type]
105
+ tags: UniqueList[str] | Missing # type: ignore[type-arg]
106
106
  responses: dict[ResponseId, Response | ResponseReference] # type: ignore[valid-type]
107
107
  requestBody: RequestBody | Missing
108
108
  security: OperationSecurityRequirement | Missing
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")