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

default values are not picked, if properties are referenced (for OpenAPI yaml) #2256

Open
mplatzer opened this issue Jan 11, 2025 · 0 comments

Comments

@mplatzer
Copy link

Describe the bug
Default values are not picked, if properties are referenced (for OpenAPI yaml).

Note: Interestingly minimum and maximum values are correctly picked up. See below.

To Reproduce

Example schema:

components:
  schemas:
    Model:
      type: "object"
      properties:
        settingA:
          type: "number"
          default: 5
          minimum: 0
          maximum: 10
        settingB:
          $ref: "#/components/schemas/ModelSettingB"
    ModelSettingB:
      type: "number"
      default: 5
      minimum: 0
      maximum: 10

Used commandline:

 datamodel-codegen --input hello.yaml --input-file-type openapi --collapse-root-models

Current Output:

class Model(BaseModel):
    settingA: Optional[confloat(ge=0.0, le=10.0)] = 5
    settingB: Optional[confloat(ge=0.0, le=10.0)] = None

Expected Output:

class Model(BaseModel):
    settingA: Optional[confloat(ge=0.0, le=10.0)] = 5
    settingB: Optional[confloat(ge=0.0, le=10.0)] = 5

to happen.

Version:

  • OS: Mac OS
  • Python version: 3.11.0
  • datamodel-code-generator version: 0.26.4
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