Closed
Description
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)
Metadata
Metadata
Assignees
Labels
No labels