Debian Codegraph @

debian/patches/remove_openapi_spec_validator_reference.patch

raw
1 Description: Remove openapi_spec_validator reference
2 Remove references to openapi_spec_validator from tests/utils.py because
3 this module is not in Debian yet.
4 Author: Emmanuel Arias <[email protected]>
5 Forwarded: not-needed
6 Last-Update: 2024-04-11
7 ---
8 This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
9 --- a/tests/utils.py
10 +++ b/tests/utils.py
11 @@ -1,8 +1,5 @@
12 """Utilities to get elements of generated spec"""
13
14 -import openapi_spec_validator
15 -from openapi_spec_validator.exceptions import OpenAPISpecValidatorError
16 -
17 from apispec import exceptions
18 from apispec.core import APISpec
19 from apispec.utils import build_reference
20 @@ -48,18 +45,3 @@
21
22 def build_ref(spec, component_type, obj):
23 return build_reference(component_type, spec.openapi_version.major, obj)
24 -
25 -
26 -def validate_spec(spec: APISpec) -> bool:
27 - """Validate the output of an :class:`APISpec` object against the
28 - OpenAPI specification.
29 -
30 - :raise: apispec.exceptions.OpenAPIError if validation fails.
31 - """
32 - try:
33 - # Coerce to dict to satisfy Pyright
34 - openapi_spec_validator.validate(dict(spec.to_dict()))
35 - except OpenAPISpecValidatorError as err:
36 - raise exceptions.OpenAPIError(*err.args) from err
37 - else:
38 - return True
39 --- a/tests/test_ext_marshmallow_openapi.py
40 +++ b/tests/test_ext_marshmallow_openapi.py
41 @@ -9,7 +9,7 @@
42 from apispec.ext.marshmallow import MarshmallowPlugin, OpenAPIConverter
43
44 from .schemas import CustomList, CustomStringField
45 -from .utils import build_ref, get_schemas, validate_spec
46 +from .utils import build_ref, get_schemas
47
48 MA_VERSION = Version(importlib.metadata.version("marshmallow"))
49
50 @@ -521,134 +521,6 @@
51 assert "breed" not in category_props
52
53
54 -def test_openapi_tools_validate_v2():
55 - ma_plugin = MarshmallowPlugin()
56 - spec = APISpec(
57 - title="Pets", version="0.1", plugins=(ma_plugin,), openapi_version="2.0"
58 - )
59 - openapi = ma_plugin.converter
60 - assert openapi is not None
61 -
62 - spec.components.schema("Category", schema=CategorySchema)
63 - spec.components.schema("Pet", {"discriminator": "name"}, schema=PetSchema)
64 -
65 - spec.path(
66 - view=None,
67 - path="/category/{category_id}",
68 - operations={
69 - "get": {
70 - "parameters": [
71 - {"name": "q", "in": "query", "type": "string"},
72 - {
73 - "name": "category_id",
74 - "in": "path",
75 - "required": True,
76 - "type": "string",
77 - },
78 - openapi._field2parameter(
79 - field=fields.List(
80 - fields.Str(),
81 - validate=validate.OneOf(["freddie", "roger"]),
82 - ),
83 - location="query",
84 - name="body",
85 - ),
86 - ]
87 - + openapi.schema2parameters(PageSchema, location="query"),
88 - "responses": {200: {"schema": PetSchema, "description": "A pet"}},
89 - },
90 - "post": {
91 - "parameters": (
92 - [
93 - {
94 - "name": "category_id",
95 - "in": "path",
96 - "required": True,
97 - "type": "string",
98 - }
99 - ]
100 - + openapi.schema2parameters(CategorySchema, location="body")
101 - ),
102 - "responses": {201: {"schema": PetSchema, "description": "A pet"}},
103 - },
104 - },
105 - )
106 - try:
107 - validate_spec(spec)
108 - except exceptions.OpenAPIError as error:
109 - pytest.fail(str(error))
110 -
111 -
112 -def test_openapi_tools_validate_v3():
113 - ma_plugin = MarshmallowPlugin()
114 - spec = APISpec(
115 - title="Pets", version="0.1", plugins=(ma_plugin,), openapi_version="3.0.0"
116 - )
117 - openapi = ma_plugin.converter
118 - assert openapi is not None
119 -
120 - spec.components.schema("Category", schema=CategorySchema)
121 - spec.components.schema("Pet", schema=PetSchema)
122 -
123 - spec.path(
124 - view=None,
125 - path="/category/{category_id}",
126 - operations={
127 - "get": {
128 - "parameters": [
129 - {"name": "q", "in": "query", "schema": {"type": "string"}},
130 - {
131 - "name": "category_id",
132 - "in": "path",
133 - "required": True,
134 - "schema": {"type": "string"},
135 - },
136 - openapi._field2parameter(
137 - field=fields.List(
138 - fields.Str(),
139 - validate=validate.OneOf(["freddie", "roger"]),
140 - ),
141 - location="query",
142 - name="body",
143 - ),
144 - ]
145 - + openapi.schema2parameters(PageSchema, location="query"),
146 - "responses": {
147 - 200: {
148 - "description": "success",
149 - "content": {"application/json": {"schema": PetSchema}},
150 - }
151 - },
152 - },
153 - "post": {
154 - "parameters": (
155 - [
156 - {
157 - "name": "category_id",
158 - "in": "path",
159 - "required": True,
160 - "schema": {"type": "string"},
161 - }
162 - ]
163 - ),
164 - "requestBody": {
165 - "content": {"application/json": {"schema": CategorySchema}}
166 - },
167 - "responses": {
168 - 201: {
169 - "description": "created",
170 - "content": {"application/json": {"schema": PetSchema}},
171 - }
172 - },
173 - },
174 - },
175 - )
176 - try:
177 - validate_spec(spec)
178 - except exceptions.OpenAPIError as error:
179 - pytest.fail(str(error))
180 -
181 -
182 def test_openapi_converter_openapi_version_types():
183 spec = APISpec(title="Pets", version="0.1", openapi_version="2.0")
184 converter_with_version = OpenAPIConverter(Version("3.1"), None, spec)