[BUG][Java] Nested <OperationId>Request class collides with request body model, breaking existing methods

オープン
#25,646 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

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

評価

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

調査の方向性

Read Java/libraries/webclient/single_request_parameter.mustache and inspect the Java WebClient generator tests for useSingleRequestParameter. The issue includes a minimal OpenAPI spec shape, though it has not been run separately; generate a client with that shape and inspect the *Api class. Done means the generated nested request class no longer shadows the body model and positional callers can still pass that model.

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

説明

Issue: Bug
Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
Description

With useSingleRequestParameter set to true or static, the Java client generates a nested class named <OperationId>Request inside each *Api class. When a request body model has that same name, the nested class shadows the model inside the *Api class:

  • The existing positional method's body parameter now resolves to the nested class, so existing callers that pass the model no longer compile.
  • The nested class's body field is typed as the nested class itself, so there is no way to send the real body.

Enabling the option is expected to be additive (the positional methods are still generated), but in this case it breaks the existing API.

openapi-generator version

Seen with 7.14.0 and 7.27.0 (Gradle plugin). On master, Java/libraries/webclient/single_request_parameter.mustache uses the same <OperationId>Request naming with no collision handling.

OpenAPI declaration file content or url

Minimal spec showing the shape (an operation updateFoo whose request body model is UpdateFooRequest). The behaviour was observed on a larger spec with the same pattern; this reduced version has not been run separately.

openapi: 3.0.3
info: { title: repro, version: "1" }
paths:
  /foo/{id}:
    patch:
      operationId: updateFoo
      parameters:
        - { name: id, in: path, required: true, schema: { type: string } }
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/UpdateFooRequest' }
      responses:
        '200': { description: ok }
components:
  schemas:
    UpdateFooRequest:
      type: object
      properties:
        name: { type: string }
Generation Details

generatorName: java, library: webclient, useSingleRequestParameter: static (same result with true).

Steps to reproduce
  1. Generate a Java webclient client from the spec above with useSingleRequestParameter set to static or true.
  2. Look at the generated *Api class.

Actual: a nested public static class UpdateFooRequest containing private UpdateFooRequest updateFooRequest. The positional updateFoo(String id, UpdateFooRequest updateFooRequest) now resolves to the nested class, so code passing the model UpdateFooRequest fails with incompatible types: <model>.UpdateFooRequest cannot be converted to <Api>.UpdateFooRequest.

Expected: no shadowing, for example by giving the request class a non-colliding name (such as UpdateFooRequestParams) or by using fully qualified model names in signatures when a collision exists.

Related issues/PRs

#19827 (adds the option to WebClient), #20679, #24568. I did not find an existing issue for this collision.

主要言語
Java
スター
26.9k
フォーク
7.8k
平均マージ
2日 10時間
マージ済み PR(30日)
180

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

OpenAPITools/openapi-generator のほかの issue

OpenAPITools/openapi-generator の issue をすべて見る

似ている issue

Java の issue をもっと見る

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

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