Skip to content

readOnly property not marked as optional in the generated model #1204

Open
@OrfeoTerkuci

Description

@OrfeoTerkuci

Describe the bug
Fields marked as readOnly in a schema in the OpenAPI document are not set as optional in the generated model.
This makes them required in the body of any POST request in which this model is used, defeating the purpose of using the readOnly property.

OpenAPI Spec File

openapi: 3.1.0
info:
  title: Minimal bug reproduction API
  version: 1.0.0
paths:
  /bug:
    get:
      summary: Get all bugs
      responses:
        "200":
          description: A list of bugs
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/Bug"
    post:
      summary: Create a bug
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/Bug"
      responses:
        "201":
          description: Bug created
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Bug"

components:
  schemas:
    Bug:
      type: object
      properties:
        id:
          readOnly: true
          type: integer
        created_at:
          readOnly: true
          type: string
          format: date-time
        name:
          type: string
        description:
          type: string
        status:
          type: string
          enum:
            - open
            - closed
      required:
        - id
        - name
        - description
        - status
        - created_at

Desktop (please complete the following information):

  • OS: [Windows 11]
  • Python Version: [3.12]
  • openapi-python-client version [0.22]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions