"A Parser can not resolve classes" for modular json schema structure
See original GitHub issueDescribe the bug
The parser cannot resolve all classes for a modular json schema structure
Exception: A Parser can not resolve classes: [class: Person references: {'pet.JsonPet'}].
To Reproduce
Example schema:
/schema
person.json
/definitions
pet.json
{
"$id": "person.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Person",
"type": "object",
"properties": {
"first_name": {
"type": "string",
"description": "The person's first name."
},
"last_name": {
"type": "string",
"description": "The person's last name."
},
"age": {
"description": "Age in years.",
"type": "integer",
"minimum": 0
},
"pets": {
"type": "array",
"items": [
{
"$ref": "definitions/pet.json#Pet"
}
]
},
"comment": {
"type": "null"
}
},
"required": [
"first_name",
"last_name"
],
}
{
"$id": "pet.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Pet",
"type": "object",
"properties": {
"name": {
"type": "string"
},
"age": {
"type": "integer"
}
}
}
Used commandline:
$ datamodel-codegen --input schema --input-file-type jsonschema --output test.py
Expected behavior I expected similar output as described in https://pydantic-docs.helpmanual.io/datamodel_code_generator
Version:
- OS: macOS Catalina 10.15.4 (19E287)
- Python version: Python 3.8
- datamodel-code-generator version: datamodel-codegen --version 0.6.2
Additional context Maybe I’m structuring the refs incorrectly, I would love to know how to change them to make this work. Thanks in advance!
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Support generating models from json-schemas defined in ...
This would help with generating models from json-schema (or . ... "A Parser can not resolve classes" for modular json schema structure #267....
Read more >Understanding JSON Schema
JSON Schema is a powerful tool for validating the structure of JSON data. However, learning to use it by reading its.
Read more >Convert a JSON schema to a python class
I would love an answer to this question that had a code generator (compiler) for the classes, rather than the current approaches, which...
Read more >jsonschema
JSON schema validator, which is designed to be fast and simple to use. JSON Schema versions through draft-07 are fully supported. Contributing & ......
Read more >SyntaxError: JSON.parse: bad parsing - JavaScript | MDN
Property names must be double-quoted strings. You cannot use single-quotes around properties, like 'foo'. JSON.parse ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Are you kidding? I listed this yesterday, please don’t feel rushed by my comments. You’re doing an amazing job on this library! 👍
The problem was a mistake in my example, the reference should be
"$ref": "definitions/pet.json#/Pet"
and then it works perfectly!