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

[BUG] ExampleGenerator returns the string "{}" (or null) for `type: object` schemas without `properties`

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

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

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

評価

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

調査の方向性

ExampleGeneratorを実装するJavaコード内でresolvePropertyToExampleとresolveModelToExampleを見つけてください。issueには、それらのファイルやテストは記載されていません。まず、提供されたOpenAPIスキーマで再現し、未解決の$ref値がどのように扱われるかを確認してください。オブジェクトスキーマにプロパティがない場合、ネストされた例とトップレベルの例の両方で、文字列やnullではなく空のJSONオブジェクトが生成されれば完了です。

索引モデルが 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

resolvePropertyToExample returns the Java string literal "{}" for an object schema without properties and for a $ref that cannot be resolved. Json.pretty then serializes it as a JSON string ("metadata" : "{}") instead of an empty object ("metadata" : { }), so the example has the wrong type (JSON Schema Validation wright-00, 5.21).

The same happens one level up. For a top-level model type: object without properties, resolveModelToExample falls through to return null, and generate(null, ["application/json"], "Anything") returns the example null. Through the CLI this model gets unaliased first, so the operation simply has no example; only programmatic callers see null.

openapi-generator version

7.25.0 (also current master).

OpenAPI declaration file content or url
components:
  schemas:
    Reading:
      type: object
      properties:
        metadata:
          type: object
Steps to reproduce

generate -g html → "Example data" shows "metadata" : "{}". Expected: "metadata" : { }.

Suggest a fix

Return new LinkedHashMap<>() (an empty map) instead of the string "{}" in both branches of resolvePropertyToExample, and also for object schemas without properties in resolveModelToExample.

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

環境構築

Codespaces で開く

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

はじめの一歩

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

OpenAPITools/openapi-generator のほかの issue

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

似ている issue

Java の issue をもっと見る

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

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