Skip to content

Casts default values of type number (scientific notation) to str #1955

Open
@maximilian-tech

Description

@maximilian-tech

Describe the bug
Bug in parsing number in scientific notation

To Reproduce

Example schema:

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "properties": {
        "test": {
            "type": "number",
            "title": "Test",
            "description": "Testcase",
            "default": 1e-5
        }
    }
}

Used commandline:

$  datamodel-codegen --input test_codegen.json --output model_test_codegen.py --output-model-type pydantic_v2.BaseModel --input-file-type jsonschema

Observed behavior

class Model(BaseModel):
    test: Optional[float] = Field('1e-5', description='Testcase', title='Test')

Expected behavior

class Model(BaseModel):
    test: Optional[float] = Field(1e-5, description='Testcase', title='Test')

Version:

  • OS: Linux
  • Python version: 3.10.12
  • datamodel-code-generator version: 0.25.6

Maybe related to #1952 .

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions