datamodel-code-generator
datamodel-code-generator copied to clipboard
`person.json` jsonschema -> model generation example doesn't work
Describe the bug Using the example on the website at this URL: https://koxudaxi.github.io/datamodel-code-generator/jsonschema/
$ datamodel-codegen --input person.json --input-file-type auto --output model.py
Traceback (most recent call last):
File "c:\users\orion.ou\miniconda3\envs\dev\lib\site-packages\datamodel_code_generator\__main__.py", line 480, in main
generate(
File "c:\users\orion.ou\miniconda3\envs\dev\lib\site-packages\datamodel_code_generator\__init__.py", line 353, in generate
results = parser.parse()
File "c:\users\orion.ou\miniconda3\envs\dev\lib\site-packages\datamodel_code_generator\parser\base.py", line 426, in parse
self.parse_raw()
File "c:\users\orion.ou\miniconda3\envs\dev\lib\site-packages\datamodel_code_generator\parser\jsonschema.py", line 1180, in parse_raw
self._parse_file(self.raw_obj, obj_name, path_parts)
File "c:\users\orion.ou\miniconda3\envs\dev\lib\site-packages\datamodel_code_generator\parser\jsonschema.py", line 1241, in _parse_file
root_obj = JsonSchemaObject.parse_obj(raw)
File "pydantic\main.py", line 447, in pydantic.main.BaseModel.parse_obj
File "c:\users\orion.ou\miniconda3\envs\dev\lib\site-packages\datamodel_code_generator\parser\jsonschema.py", line 199, in __init__
super().__init__(**data)
File "pydantic\main.py", line 338, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 6 validation errors for JsonSchemaObject
properties -> firstName
"JsonSchemaObject" object has no field "_raw" (type=value_error)
properties -> lastName
"JsonSchemaObject" object has no field "_raw" (type=value_error)
properties -> age
"JsonSchemaObject" object has no field "_raw" (type=value_error)
properties -> friends
"JsonSchemaObject" object has no field "_raw" (type=value_error)
properties -> comment
"JsonSchemaObject" object has no field "_raw" (type=value_error)
properties -> _raw
"JsonSchemaObject" object has no field "_raw" (type=value_error)
To Reproduce Follow example here https://koxudaxi.github.io/datamodel-code-generator/jsonschema/ Example schema:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Person",
"type": "object",
"properties": {
"firstName": {
"type": "string",
"description": "The person's first name."
},
"lastName": {
"type": "string",
"description": "The person's last name."
},
"age": {
"description": "Age in years which must be equal to or greater than zero.",
"type": "integer",
"minimum": 0
},
"friends": {
"type": "array"
},
"comment": {
"type": "null"
}
}
}
Used commandline:
$ $ datamodel-codegen --input person.json --input-file-type jsonschema --output model.py
Expected behavior Expected the model.py pydantic model to be generated
Version:
- OS: Windows 10
- Python version: 3.8.5
- datamodel-code-generator version: 0.11.12
- pydantic version: 1.5.1
Additional context Add any other context about the problem here.
@omgirok Thank you for creating this issue. I just reproduced the problem with pydantic 1.5.1. If I install pydnatic 1.8.1 then the error does not happen, I will fix it.
@omgirok Thank you for creating this issue. I just reproduced the problem with pydantic 1.5.1. If I install pydnatic 1.8.1 then the error does not happen, I will fix it.
Thank you so much @koxudaxim
@omgirok The fixed just was released as 0.11.13 Thank you!!