Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursive elements results in wrong model #168

Closed
fzirker opened this issue Jul 7, 2020 · 2 comments
Closed

Recursive elements results in wrong model #168

fzirker opened this issue Jul 7, 2020 · 2 comments
Labels
bug Something isn't working released

Comments

@fzirker
Copy link

fzirker commented Jul 7, 2020

I am generating models from JSON Data which comes from an external source. In my JSON file there is a element which contains a other sub element with the same name.

Example JSON

{
    "recursive": {
        "sub": {
            "recursive": {
                "value": 42.23
            }
        }
    }
}

Used commandline:

$ datamodel-codegen --input jsons/recursive.json --input-file-type json --output models/recursive.py --target-python-version 3.6

Expected behavior
The Model should look like this.

class Recursive(BaseModel):
    sub: 'Sub'

class Recursive2(BaseModel):
    sub: float

class Sub(BaseModel):
    recursive: 'Recursive2'

class Model(BaseModel):
    recursive: 'Recursive'

But it looks like this and has an indirect recursion in Recursive->Sub->Recursive... :

class Recursive(BaseModel):
    sub: 'Sub'

class Sub(BaseModel):
    recursive: 'Recursive'

class Model(BaseModel):
    recursive: 'Recursive'

Version:

  • OS: Ubuntu 20.04
  • Python Verison: 3.6
  • datamodel-code-generator Version 0.5.13
@koxudaxi
Copy link
Owner

koxudaxi commented Jul 9, 2020

@fzirker
OK, I have understood it.
We have to check the contents of models to compare same name models,
I will fix it.

@koxudaxi
Copy link
Owner

@fzirker
In version 0.5.16, this problem is resolved 🎉

https://github.com/koxudaxi/datamodel-code-generator/pull/177/files

@koxudaxi koxudaxi added bug Something isn't working released labels Jul 19, 2020
@koxudaxi koxudaxi closed this as completed Sep 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
Development

No branches or pull requests

2 participants