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