datamodel-code-generator icon indicating copy to clipboard operation
datamodel-code-generator copied to clipboard

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

Open maximilian-tech opened this issue 1 year ago • 0 comments

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 .

maximilian-tech avatar May 11 '24 16:05 maximilian-tech