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

Open
#1,180 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
58/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
python
Domain
api

Research direction

Start with the reproduced call to oas31_schema_casters_factory.create and inspect SchemaCaster and StyleDeserializersFactory, especially where SchemaPath values are read. Check how SchemaPath.read_str_or_list can support both string and list-form type values, then rerun the provided casting example and verify style deserialization also handles the OpenAPI 3.1 form.

Written by the indexing model from the issue text.

Description

kind/bug kind/bug/confirmed
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

Dominant language
Python
Stars
368
Forks
140
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from python-openapi/openapi-core

All issues in python-openapi/openapi-core

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.