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

`default` property sibling to a `$ref` is ignored

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

還沒有人認領這個 Issue。

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

描述

Describe the bug
default property sibling to a $ref is ignored. OAS 3.1.X relies on JSON Schema 2020-12 which does not include the requirement that sibling properties to $ref should be ignored.

OpenAPI Spec File

{
  "openapi": "3.1.0",
  "info": {
    "title": "title",
    "summary": "summary",
    "description": "description",
    "version": "0.0.1"
  },
  "paths": {
    "/": {
      "get": {
        "parameters": [
          {
            "name": "default_lost1",
            "required": false,
            "schema": {
              "$ref": "#/components/schemas/String",
              "default": "lost"
            }
          },
          {
            "name": "default_lost2",
            "required": false,
            "schema": {
              "$ref": "#/components/schemas/DefaultString"
            }
          },
          {
            "name": "default_lost3",
            "schema": {
              "allOf": [
                {
                  "$ref": "#/components/schemas/DefaultString"
                }
              ]
            }
          }, 
          {
            "name": "default_kept",
            "schema": {
              "allOf": [
                {
                  "$ref": "#/components/schemas/String"
                }
              ],
              "default": "kept"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {}
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "String": {
        "type": "string"
      },
      "DefaultString": {
        "type": "string",
        "default": "component_default"
      }
    }
  }
}

Desktop (please complete the following information):

  • OS: macOS 26.4.1
  • Python Version: 3.11.13
  • openapi-python-client version: 0.28.3

Additional context
The previous schema generates code like this:

def _get_kwargs(
    *,
    body: Object,
    default_lost1: str | Unset = UNSET,
    default_lost2: str | Unset = UNSET,
    default_lost3: str | Unset = UNSET,
    default_kept: str | Unset = 'kept',

) -> dict[str, Any]:

I would expect all defaults to be kept.

If anything else is needed I will be more than happy to provide it. Thank you for your time!

貢獻指南

開啟貢獻指南

從這裡開始

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

研究方向

首先使用報告中的 OpenAPI 3.1 規範重現問題,並檢查產生的 _get_kwargs 輸出。追蹤直接 $ref sibling、被參照的 schema 以及 allOf wrapper 的 schema 預設值處理方式。產生的用戶端保留全部四個預設值(包括 component_default)即表示完成。

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

評估

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

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

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