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

Generates SyntaxError if a path parameter without a default value follows another that has a default value

未关闭
#1,281 0 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Python
星标
2k
派生
293
平均合并
34 分钟
30 天内合并 PR
1

描述

Describe the bug
Fails to generate client when a path parameter without a default value follows another one that has a default value.

Message:

Error(s) encountered while generating, client was not created
ruff failed
SyntaxError: Parameter without a default cannot follow a parameter with a default

OpenAPI Spec File
Motivating api: https://avaandmed.keskkonnaportaal.ee/swagger/index.html ("File of document")
Minimum example:

openapi: 3.0.0
info:
  title: Minimal Repro for Parameter Order Bug
  version: 1.0.0
paths:
  /test/{has_default}/{no_default}:
    get:
      summary: Test endpoint with required path params, some with defaults
      parameters:
        - name: has_default
          in: path
          required: true
          schema:
            type: string
            default: default_value
          description: Required path param with default
        - name: no_default
          in: path
          required: true
          schema:
            type: integer
          description: Required path param, no default
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  result:
                    type: string

Desktop (please complete the following information):

  • OS: Ubuntu 22.04.5 LTS
  • Python Version: 3.10.12
  • openapi-python-client version 0.25.2

Additional context
The generated function signature for _get_kwargs looks like this:

def _get_kwargs(
    has_default: str = 'default_value',
    no_default: int,
) -> dict[str, Any]:

The issue does not occur for query parameters, as the generator emits keyword-only arguments (*) for them. It only occurs for path parameters, which are emitted as positional-or-keyword arguments.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

使用报告中的最小 OpenAPI 规范重现该问题,并检查构建路径参数的生成 _get_kwargs 签名的生成器路径。通过成功生成客户端,并验证必需的路径参数可以位于具有默认值的参数之后且不会产生 Python SyntaxError,来确认修复有效。

由索引模型根据 Issue 内容生成。

评估

技术栈
openapi, python
领域
api, tooling
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
描述清楚
新手友好度
50/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。