From 6dc943661dee4f979d4608a6dd8ec4c4aaaed2ee Mon Sep 17 00:00:00 2001 From: Niels Dewulf <87133686+nielsbox@users.noreply.github.com> Date: Thu, 7 Dec 2023 14:54:40 +0100 Subject: [PATCH] Specification use raw spec on clone (#1830) Fixes #1829. Changes proposed in this pull request: - Use _raw_spec when cloning --------- Co-authored-by: Robbe Sneyders --- connexion/spec.py | 2 +- tests/api/conftest.py | 12 ++++++++++++ tests/api/test_swagger_ui.py | 4 ++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 tests/api/test_swagger_ui.py diff --git a/connexion/spec.py b/connexion/spec.py index 91ff3cd93..be5d653e5 100644 --- a/connexion/spec.py +++ b/connexion/spec.py @@ -196,7 +196,7 @@ def enforce_string_keys(obj): return OpenAPISpecification(spec, base_uri=base_uri) def clone(self): - return type(self)(copy.deepcopy(self._spec)) + return type(self)(copy.deepcopy(self._raw_spec)) @classmethod def load(cls, spec, *, arguments=None): diff --git a/tests/api/conftest.py b/tests/api/conftest.py index 0eb14ba54..9249e6126 100644 --- a/tests/api/conftest.py +++ b/tests/api/conftest.py @@ -2,6 +2,7 @@ import pytest from connexion.middleware import MiddlewarePosition +from connexion.options import SwaggerUIOptions from starlette.middleware.cors import CORSMiddleware from starlette.types import Receive, Scope, Send @@ -22,6 +23,17 @@ def simple_openapi_app(app_class): ) +@pytest.fixture(scope="session") +def swagger_ui_app(app_class): + return build_app_from_fixture( + "simple", + app_class=app_class, + spec_file=OPENAPI3_SPEC, + validate_responses=True, + swagger_ui_options=SwaggerUIOptions(spec_path="/spec.json"), + ) + + @pytest.fixture(scope="session") def cors_openapi_app(app_class): app = build_app_from_fixture( diff --git a/tests/api/test_swagger_ui.py b/tests/api/test_swagger_ui.py new file mode 100644 index 000000000..1d787c65a --- /dev/null +++ b/tests/api/test_swagger_ui.py @@ -0,0 +1,4 @@ +def test_simple(swagger_ui_app): + app_client = swagger_ui_app.test_client() + response = app_client.get("/v1.0/spec.json") + assert response.status_code == 200