openapi-generators / openapi-generators/openapi-python-client

readOnly property not marked as optional in the generated model

Open
#1,204 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2k
Forks
293
Avg merge
34m
Merged PRs (30d)
1

Description

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]

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Begin by running the supplied OpenAPI 3.1 reproduction with openapi-python-client 0.22 and inspecting the generated Bug model and POST usage. Trace where readOnly and required fields are converted; done when readOnly fields are not required for POST input while remaining available in generated response models, with regression coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.