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