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

required fields declared in an allof are missing in the generated code #2070

Open
comic31 opened this issue Aug 12, 2024 · 0 comments
Open

Comments

@comic31
Copy link

comic31 commented Aug 12, 2024

Describe the bug

required fields declared in an allof are missing in the generated python code.

If this is not a bug, please let me know if I'm doing something wrong.

To Reproduce

Example schema:

    ProjectedPet:
      type: object
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
    Pet:
      allOf:
        - $ref: "#/components/schemas/ProjectedPet"
        - type: object
          required:
            - id
            - name
            - opts
          properties:
            tag:
              type: string
            opts:
              type: array
              items:
                type: string

Used commandline:

datamodel-codegen --input api.yaml --output model.py --input-file-type openapi --use-annotated --collapse-root-models  --use-standard-collections --capitalize-enum-members  --target-python-version 3.10 --output-model-type pydantic_v2.BaseModel

Actual behavior

class ProjectedPet(BaseModel):
    id: Optional[int] = None
    name: Optional[str] = None

class Pet(ProjectedPet):
    tag: Optional[str] = None
    opts: list[str]

Expected behavior

class ProjectedPet(BaseModel):
    id: Optional[int] = None
    name: Optional[str] = None

class Pet(ProjectedPet):
    id: int
    name: str
    tag: Optional[str] = None
    opts: list[str]

Version:

  • OS: MacOS 14.6.1
  • Python version: 3.11
  • datamodel-code-generator version: 0.25.9
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