Datamodel-code-generator: error when generating citation-style-language/schema

Created on 20 Nov 2020  ยท  4Comments  ยท  Source: koxudaxi/datamodel-code-generator

Describe the bug
error when generating citation-style-language/schema

To Reproduce

Example schema:

https://raw.githubusercontent.com/citation-style-language/schema/v1.0.1/csl-data.json

Used commandline:

โฏ datamodel-codegen --input ~/Documents/csl-data.json --output model.py
Traceback (most recent call last):
  File "/usr/local/Caskroom/miniconda/base/lib/python3.8/site-packages/datamodel_code_generator/__main__.py", line 258, in main
    generate(
  File "/usr/local/Caskroom/miniconda/base/lib/python3.8/site-packages/datamodel_code_generator/__init__.py", line 213, in generate
    results = parser.parse()
  File "/usr/local/Caskroom/miniconda/base/lib/python3.8/site-packages/datamodel_code_generator/parser/base.py", line 253, in parse
    self.parse_raw()
  File "/usr/local/Caskroom/miniconda/base/lib/python3.8/site-packages/datamodel_code_generator/parser/jsonschema.py", line 834, in parse_raw
    root_obj = JsonSchemaObject.parse_obj(self.raw_obj)
  File "pydantic/main.py", line 515, in pydantic.main.BaseModel.parse_obj
  File "pydantic/main.py", line 362, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 10 validation errors for JsonSchemaObject
items
  value is not a valid list (type=type_error.list)
items -> properties -> type -> required
  value is not a valid list (type=type_error.list)
items -> properties -> id -> required
  value is not a valid list (type=type_error.list)
items -> properties -> author -> items
  value is not a valid list (type=type_error.list)
items -> properties -> author -> items -> type
  str type expected (type=type_error.str)
items -> properties -> author -> items -> type -> 0
  str type expected (type=type_error.str)
items -> properties -> author -> items -> type -> 1
  str type expected (type=type_error.str)
items -> properties -> accessed -> type
  str type expected (type=type_error.str)
items -> properties -> accessed -> type -> 0
  str type expected (type=type_error.str)
items -> properties -> accessed -> type -> 1
  str type expected (type=type_error.str)

Expected behavior

no exceptions reported.

Version:

  • OS: macOS 10.15.7 (19H15)
  • Python version: 3.8.3
  • datamodel-code-generator version: 0.6.7

Additional context
Add any other context about the problem here.

All 4 comments

Thank you for creating this issue.
I have reproduced the problem. I will fix it.

@elonzh
I have checked the schema.
I think this schema is invalid.

  1. required has boolean. I expect a string or a list of string https://json-schema.org/understanding-json-schema/reference/object.html#required-properties
  2. type: [{...}] is not valid. I guess items: [{...}] is correct.
            "author": {
                "type": "array",
                "items": {
                    "id": "name-variable",
                    "type": [
                        {
                            "properties": {
                                "family" : {
                                    "type": "string" 
   "description": "JSON schema (draft 3) for CSL input data"

Also, this schema version may be draft 3 . but, I didn't check about the version.

The schema is valid with the draft 3 version, maybe we need to document the minimum supported version.

You can validate the schema at https://www.jsonschemavalidator.net/.

Still, I will report this issue to the CSL project.

I agree. I add the minimum supported version in the document.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

philipbjorge picture philipbjorge  ยท  4Comments

ofek picture ofek  ยท  6Comments

ioggstream picture ioggstream  ยท  6Comments

scottcarr picture scottcarr  ยท  3Comments

fzirker picture fzirker  ยท  6Comments