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

Type annotation falls back to Any if property schema is partially overwridden #2087

Open
simontaurus opened this issue Sep 8, 2024 · 0 comments

Comments

@simontaurus
Copy link

Describe the bug
Importing a schema and partial overwrite it (e.g., set a different default value) leads to lost type information

To Reproduce

schemaA

{
    "type": "object",
    "title": "SchemaA",
    "properties": {
        "test": {
            "title": "test",
            "type": "string",
            "default": "default_value1"
        }
    }
}

schemaB.json

{
    "allOf": [
        {
            "$ref": "SchemaA.json"
        }
    ],
    "type": "object",
    "title": "SchemaB",
    "properties": {
        "test": {
            "default": "default_value2"
        }
    }
}

Used commandline:

$ datamodel-codegen --input schemaB.json --output model.py

Result model.py: type of test in SchemaB is resetted to Any

class SchemaA(BaseModel):
    test: Optional[str] = Field('default_value1', title='test')

class SchemaB(SchemaA):
    test: Optional[Any] = 'default_value2'

Expected behavior
type of test in SchemaB is still str

class SchemaA(BaseModel):
    test: Optional[str] = Field('default_value1', title='test')

class SchemaB(SchemaA):
    test: Optional[str] = 'default_value2'

Version:

  • OS: Windows 10
  • Python version: 3.11 | 3.9
  • datamodel-code-generator version: 0.25.6 | 0.26.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant