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

readOnly property not marked as optional in the generated model

未關閉
#1,204 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

主要語言
Python
星號
2k
分支
293
平均合併
34 分鐘
30 天內合併 PR
1

描述

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]

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

首先使用 openapi-python-client 0.22 執行所提供的 OpenAPI 3.1 重現案例,並檢查產生的 Bug 模型和 POST 用法。追蹤 readOnly 和 required 欄位的轉換位置;當 readOnly 欄位對 POST 輸入不再是必要的,同時仍可在產生的回應模型中使用,並具備回歸測試涵蓋時,即可完成。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
tooling
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
42/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。