Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spec now validates three times #714

Closed
p1c2u opened this issue Nov 3, 2023 · 0 comments
Closed

Spec now validates three times #714

p1c2u opened this issue Nov 3, 2023 · 0 comments

Comments

@p1c2u
Copy link
Collaborator

p1c2u commented Nov 3, 2023

          This seems wasteful since `Spec.from_dict` has already validated the spec. This now validates the spec three times, once in `Spec.from_dict`, once in `validate_request`, and once in `validate_response`:
from openapi_core import Spec, validate_request, validate_response
from openapi_core.testing import MockRequest, MockResponse

spec = Spec.from_dict(
    {
        "openapi": "3.1.0",
        "info": {"title": "Test", "version": "1.0.0"},
        "paths": {"/": {"get": {"responses": {"200": {"description": "OK"}}}}},
    },
)
request = MockRequest("http://localhost", "get", "/")
validate_request(request, spec=spec)
response = MockResponse("")
validate_response(request, response, spec=spec)

This adds a very expensive per-request and per-response overhead when the spec is large.

Moreover, the documented workaround doesn’t work; this still validates the spec (as can be seen by misspelling title, say):

from openapi_core import Spec, validate_request, validate_response
from openapi_core.testing import MockRequest, MockResponse

spec = Spec.from_dict(
    {
        "openapi": "3.1.0",
        "info": {"titel": "Test", "version": "1.0.0"},
        "paths": {"/": {"get": {"responses": {"200": {"description": "OK"}}}}},
    },
    validator=None,
)
request = MockRequest("http://localhost", "get", "/")
validate_request(request, spec=spec, spec_validator_cls=None)
response = MockResponse("")
validate_response(request, response, spec=spec, spec_validator_cls=None)

Originally posted by @andersk in #686 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant