Skip to content

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

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

Closed
andersk opened this issue Feb 9, 2023 · 1 comment

Comments

@andersk
Copy link
Contributor

andersk commented Feb 9, 2023

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.
@p1c2u
Copy link
Collaborator

p1c2u commented Apr 13, 2023

openapi-core 0.17.x uses OAS30WriteValidator hence closing

@p1c2u p1c2u closed this as completed Apr 13, 2023
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

2 participants