Skip to content

read-only-write-only-model-type breaks with refs #2940

@Yamakaky

Description

@Yamakaky

Describe the bug
read-only-write-only-model-type doesn't support refs to others schemas with readOnly properties. In the example below, I assume the generator creates ChildResponse and ChildRequest, then search for Child when generating Parent. Same behavior if Parent also has a readOnly property.

To Reproduce

Example schema:

openapi: "3.0.0"
info:
  title: broken readonly $ref
  version: "1.0"
paths: {}
components:
  schemas:
    Child:
      properties:
        opt:
          readOnly: true
          type: integer
    Parent:
      properties:
        child:
          $ref: "#/components/schemas/Child"
        opt:
          readOnly: true
          type: integer

Used commandline:

$ datamodel-codegen --input example.yaml --read-only-write-only-model-type request-response

Expected behavior
If $ref points to a schema with readonly fields, the parent schema should always be a request/response, and use the right ref.

Version:

  • OS: linux
  • Python version: 3.14
  • datamodel-code-generator version: 0.55.2

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