Skip to content

DeprecationWarning with openapi-schema-validator ≥ 0.4.1: “read property is deprecated. Use OAS30ReadValidator instead.” #507

Description

@andersk

With openapi-core 0.16.5 or current master, and openapi-schema-validator 0.4.1 or later, a DeprecationWarning is thrown due to python-openapi/openapi-schema-validator#59. (It’s visible with python -Wdefault or PYTHONWARNINGS=default.)

from openapi_core import Spec
from openapi_core.testing import MockRequest
from openapi_core.validation.request import openapi_request_validator

spec = Spec.create(
    {
        "openapi": "3.0.3",
        "info": {"title": "test", "version": "0"},
        "paths": {
            "/test": {
                "post": {
                    "parameters": [
                        {
                            "name": "n",
                            "in": "query",
                            "schema": {"type": "number"},
                        },
                    ],
                    "responses": {"200": {"description": ""}},
                },
            },
        },
    },
)
request = MockRequest("http://localhost/", "post", "/test", args={"n": "1"})
result = openapi_request_validator.validate(spec, request)
print(result)
result.raise_for_errors()
$ poetry run python3 -Wdefault test.py
/home/anders/.cache/pypoetry/virtualenvs/openapi-core-XEMBi3Y7-py3.10/lib/python3.10/site-packages/openapi_schema_validator/validators.py:118: DeprecationWarning: write property is deprecated. Use OAS30WriteValidator instead.
  warnings.warn(
RequestValidationResult(errors=[], body=None, parameters=Parameters(query={'n': 1.0}, header={}, cookie={}, path={}), security={})

$ poetry run python3 -Werror test.py 
Traceback (most recent call last):
  File "/home/anders/python/openapi-core/test.py", line 26, in <module>
    result = openapi_request_validator.validate(spec, request)
  File "/home/anders/python/openapi-core/openapi_core/validation/request/proxies.py", line 36, in validate
    return validator.validate(spec, request, base_url=base_url)
  File "/home/anders/python/openapi-core/openapi_core/validation/request/validators.py", line 329, in validate
    params = self._get_parameters(request, path, operation)
  File "/home/anders/python/openapi-core/openapi_core/validation/request/validators.py", line 105, in _get_parameters
    value = self._get_parameter(param, request)
  File "/home/anders/python/openapi-core/openapi_core/validation/request/validators.py", line 138, in _get_parameter
    return self._get_param_or_header_value(param, location)
  File "/home/anders/python/openapi-core/openapi_core/validation/validators.py", line 107, in _get_param_or_header_value
    unmarshalled = self._unmarshal(schema, casted)
  File "/home/anders/python/openapi-core/openapi_core/validation/validators.py", line 75, in _unmarshal
    unmarshaller = self.schema_unmarshallers_factory.create(schema)
  File "/home/anders/python/openapi-core/openapi_core/unmarshalling/schemas/factories.py", line 134, in create
    validator = self.validators_factory.create(schema)
  File "/home/anders/python/openapi-core/openapi_core/unmarshalling/schemas/factories.py", line 82, in create
    return self.schema_validator_class(schema_dict, **kwargs)
  File "/home/anders/.cache/pypoetry/virtualenvs/openapi-core-XEMBi3Y7-py3.10/lib/python3.10/site-packages/openapi_schema_validator/validators.py", line 118, in __init__
    warnings.warn(
DeprecationWarning: write property is deprecated. Use OAS30WriteValidator instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions