Dataclasses with Python 3.10-compatible typing cause warning when trying to create JSON schema for the class
How to reproduce
Assume the following definition
from typing import Optional
from dataclasses import dataclass
from dataclasses_jsonschema import JsonSchemaMixin
from dataclasses_jsonschema import SchemaType
@dataclass
class A(JsonSchemaMixin):
id: str | None
@dataclass
class B(JsonSchemaMixin):
id: Optional[str] = None
@staticmethod
def _get_field_type_name(field_type: Any) -> str:
try:
return field_type.__name__
except AttributeError:
# The types in the 'typing' module lack the __name__ attribute
match = re.match(r'typing\.([A-Za-z]+)', str(field_type))
return str(field_type) if match is None else match.group(1)
Setup
Python: v3.10
dataclasses_jsonschema: version 2.14.1 (but tried with the latest version as well.
Problem
Dataclasses with Python 3.10-compatible typing cause warning when trying to create JSON schema for the class
How to reproduce
Assume the following definition
Running this
causes the following error:
while if I run this
I get this w/o warning
The issue seems to be caused by this bit of code: https://github.com/s-knibbs/dataclasses-jsonschema/blob/82ea3d892b70e6922ec4cbf604ccdf37198a9f55/dataclasses_jsonschema/__init__.py#L887
Setup
Python: v3.10 dataclasses_jsonschema: version 2.14.1 (but tried with the latest version as well.