Closed ialarmedalien closed 7 months ago
I am getting a bit different errors,
First of all use the xsdata --output pydantic
command, I am not sure if the schema_json_of
works with normal dataclasses.
Then I get this error
File "/Users/chris/projects/xsdata-pydantic/scripts.py", line 6, in <module>
print(pydantic.schema_json_of(md.Resource, title="Resource", indent=2))
File "pydantic/tools.py", line 92, in pydantic.tools.schema_json_of
File "pydantic/main.py", line 675, in pydantic.main.BaseModel.schema_json
File "pydantic/main.py", line 664, in pydantic.main.BaseModel.schema
File "pydantic/schema.py", line 186, in pydantic.schema.model_schema
File "pydantic/schema.py", line 580, in pydantic.schema.model_process_schema
File "pydantic/schema.py", line 621, in pydantic.schema.model_type_schema
File "pydantic/schema.py", line 254, in pydantic.schema.field_schema
File "pydantic/schema.py", line 526, in pydantic.schema.field_type_schema
File "pydantic/schema.py", line 924, in pydantic.schema.field_singleton_schema
File "pydantic/schema.py", line 580, in pydantic.schema.model_process_schema
File "pydantic/schema.py", line 621, in pydantic.schema.model_type_schema
File "pydantic/schema.py", line 254, in pydantic.schema.field_schema
File "pydantic/schema.py", line 526, in pydantic.schema.field_type_schema
File "pydantic/schema.py", line 924, in pydantic.schema.field_singleton_schema
File "pydantic/schema.py", line 580, in pydantic.schema.model_process_schema
File "pydantic/schema.py", line 621, in pydantic.schema.model_type_schema
File "pydantic/schema.py", line 254, in pydantic.schema.field_schema
File "pydantic/schema.py", line 461, in pydantic.schema.field_type_schema
File "pydantic/schema.py", line 847, in pydantic.schema.field_singleton_schema
File "pydantic/schema.py", line 698, in pydantic.schema.field_singleton_sub_fields_schema
File "pydantic/schema.py", line 526, in pydantic.schema.field_type_schema
File "pydantic/schema.py", line 921, in pydantic.schema.field_singleton_schema
File "/Users/chris/.pyenv/versions/3.10.5/lib/python3.10/abc.py", line 123, in __subclasscheck__
return _abc_subclasscheck(cls, subclass)
TypeError: issubclass() arg 1 must be a class
Which is know because of this https://github.com/pydantic/pydantic/issues/3695 we have to tell xsdata to unnest all inner classes.
xsdata --unnest-classes --output pydantic
But then I am getting this
Traceback (most recent call last):
File "/Users/chris/projects/xsdata-pydantic/scripts.py", line 6, in <module>
print(pydantic.schema_json_of(md.Resource, title="Resource", indent=2))
File "pydantic/tools.py", line 92, in pydantic.tools.schema_json_of
File "pydantic/main.py", line 674, in pydantic.main.BaseModel.schema_json
File "/Users/chris/.pyenv/versions/3.10.5/lib/python3.10/json/__init__.py", line 238, in dumps
**kw).encode(obj)
File "/Users/chris/.pyenv/versions/3.10.5/lib/python3.10/json/encoder.py", line 201, in encode
chunks = list(chunks)
File "/Users/chris/.pyenv/versions/3.10.5/lib/python3.10/json/encoder.py", line 431, in _iterencode
yield from _iterencode_dict(o, _current_indent_level)
File "/Users/chris/.pyenv/versions/3.10.5/lib/python3.10/json/encoder.py", line 405, in _iterencode_dict
yield from chunks
File "/Users/chris/.pyenv/versions/3.10.5/lib/python3.10/json/encoder.py", line 405, in _iterencode_dict
yield from chunks
File "/Users/chris/.pyenv/versions/3.10.5/lib/python3.10/json/encoder.py", line 405, in _iterencode_dict
yield from chunks
[Previous line repeated 2 more times]
File "/Users/chris/.pyenv/versions/3.10.5/lib/python3.10/json/encoder.py", line 325, in _iterencode_list
yield from chunks
File "/Users/chris/.pyenv/versions/3.10.5/lib/python3.10/json/encoder.py", line 405, in _iterencode_dict
yield from chunks
File "/Users/chris/.pyenv/versions/3.10.5/lib/python3.10/json/encoder.py", line 438, in _iterencode
o = _default(o)
File "pydantic/json.py", line 80, in pydantic.json.pydantic_encoder
File "/Users/chris/.pyenv/versions/3.10.5/lib/python3.10/dataclasses.py", line 1238, in asdict
raise TypeError("asdict() should be called on dataclass instances")
TypeError: asdict() should be called on dataclass instances
Which as far as I can tell it tries to pass the Meta class for some reason.
This sounds like a pydantic issue to be honest
Not sure if this is still applicable, I am hoping with the upcoming release, this is also resolved
Attempting to dump the JSONschema from the pydantic class generated by xsdata-pydantic results in a type error due to field ordering: "TypeError: non-default argument 'name_identifier' follows default argument"
To reproduce:
Source file: https://github.com/datacite/schema/blob/master/source/meta/kernel-4.4/metadata.xsd (plus associated files)
then run the following python code:
Output: