Skip to content

build_json_schema() fails for type defined with type keyword #293

@NiklasRosenstein

Description

@NiklasRosenstein
  • mashumaro version: 3.16
  • Python version: 3.13.5
  • Operating System: Ubuntu 24.04

Description

Mashumaro fails to generate the schema when encountering a field that is annotated with a type that was declared with the type keyword.

What I Did

type B = dict[str, str]
print(build_json_schema(B).to_json())

Traceback:

  File "venv/lib/python3.13/site-packages/mashumaro/jsonschema/builder.py", line 51, in build_json_schema
    schema = get_schema(instance, context, with_dialect_uri=with_dialect_uri)
  File "venv/lib/python3.13/site-packages/mashumaro/jsonschema/schema.py", line 270, in get_schema
    schema = schema_creator(instance, ctx)
  File "venv/lib/python3.13/site-packages/mashumaro/jsonschema/schema.py", line 747, in on_collection
    if not issubclass(instance.origin_type, Collection):
           ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen abc>", line 123, in __subclasscheck__
TypeError: issubclass() arg 1 must be a class

The same error also occurs when using the type in a field for a TypedDict or @dataclass.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions