Skip to content

[Bug]: OAS 3.1 list-style "type" raises in SchemaCaster and StyleDeserializersFactory #1180

@litteratum

Description

@litteratum

Actual Behavior

When a schema uses OpenAPI 3.1's list form for type (e.g. type: ["string", "integer"]), parameter casting and style deserialization fail.

It works okay in version 0.19.5, but does not work in version 0.23.1 (I did not test the versions in between).

Expected Behavior

Per the OpenAPI 3.1 specification, type may be either a string or a non-empty array of strings.

Steps to Reproduce

from openapi_core.casting.schemas import oas31_schema_casters_factory
from jsonschema_path import SchemaPath

spec = {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": ["string", "number", "boolean"]
}

schema = SchemaPath.from_dict(spec)
oas31_schema_casters_factory.create(spec, schema).cast("42")

This snippet raises TypeError: Expected a string value, got <class 'list'>.

OpenAPI Core Version

0.23.1

OpenAPI Core Integration

flask

Affected Area(s)

casting, deserializing.

References

No response

Anything else we need to know?

jsonschema_path.SchemaPath already exposes read_str_or_list. So we should use it.

Would you like to implement a fix?

Yes

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions