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 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Python
スター
2k
フォーク
293
平均マージ
34分
マージ済み PR(30日)
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. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

報告にある最小限の OpenAPI 仕様で問題を再現し、パスパラメーター向けに生成される _get_kwargs シグネチャを構築するジェネレーターの処理経路を調査します。クライアントを正常に生成し、必須のパスパラメーターがデフォルト値を持つパラメーターの後に続いても Python SyntaxError が発生しないことを確認して修正を検証します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
openapi, python
領域
api, tooling
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
50/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。