Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

[BUG] ExampleGenerator.generateFromResponseSchema treats the keys of an inline object `example` (java.util.Map) as media types

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

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

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

評価

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

調査の方向性

ExampleGenerator.generateFromResponseSchema(Schema, Set)から始め、null ではないインラインスキーマの例がどのようにgenerateのオーバーロードに渡るかを追ってください。レスポンススキーマの例に関する既存のテストを確認し、生成されるメディアタイプがapplication/jsonであるJavaのMapの例についてテストカバレッジを追加してください。完了条件は、Mapのキーをメディアタイプとして扱うのではなく、そのメディアタイプの下に1つの例として出力されることです。

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

説明

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

When generateFromResponseSchema(statusCode, schema, produces) gets an inline (non-$ref, non-array) schema whose example is a java.util.Map, the "primitive type" branch casts the example to Map<String, Object> and passes it as the examples argument of generate(Map, List, Schema). That argument means {mediaType -> example}, so every key of the example becomes a contentType and every value becomes a separate example:

Schema<Object> response = new ObjectSchema()
        .addProperty("id", new IntegerSchema())
        .addProperty("name", new StringSchema());
response.setExample(Map.of("id", 1, "name", "Rex"));

new ExampleGenerator(Map.of(), new OpenAPI())
        .generateFromResponseSchema("200", response, Set.of("application/json"));
// actual:   [{contentType=name, example="Rex", statusCode=200}, {contentType=id, example=1, statusCode=200}]
// expected: [{contentType=application/json, example={"id":1,"name":"Rex"}, statusCode=200}]

When the spec is read from a file, swagger-parser gives the example as a Jackson ObjectNode, not a Map, so the CLI does not hit this path. It affects programmatic use, such as custom generators or tools that build or transform the OpenAPI model with plain Java maps.

openapi-generator version

7.25.0 (also current master).

Suggest a fix

In generateFromResponseSchema(Schema, Set), handle any non-null example (including Map) through generate(Object, List), and use the generate(Map, ...) overloads only for the media-type map.

主要言語
Java
スター
26.8k
フォーク
7.7k
平均マージ
1日 11時間
マージ済み PR(30日)
139

環境構築

Codespaces で開く

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

はじめの一歩

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

OpenAPITools/openapi-generator のほかの issue

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

似ている issue

Java の issue をもっと見る

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

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