Skip to content

Spec now validates three times #714

Closed
@p1c2u

Description

@p1c2u
          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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy