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