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 摘要。