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

[BUG] OpenApiEvaluator reports "default value not in enum" for numerically equal values with different scale (e.g. 1.5 and 1.50)

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

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

@mohitduhan19 がすでに取り組んでいます。

2026年10月13日 から。

  • #25241 @mohitduhan19 による — オープン

評価

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

調査の方向性

openapi-generator モジュールの OpenApiEvaluator#validate(OpenAPI) と、報告された CT-OE-14 テスト OpenApiEvaluatorJUnitTest.ct14NumericDefaultComparedByValue から始めてください。既存の推奨チェックを読み、issue に記載された対象を絞った Maven テストコマンドを実行してください。数値として等しい 1.5 や 1.50 などの BigDecimal 値で警告が発生せず、他の enum 比較では現在の動作が維持されれば完了です。

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

説明

Issue: Bug
Summary

The "Schema has default value not in enum" recommendation compares the default against the enum items with List.contains. In numeric schemas the values are BigDecimal, and BigDecimal.equals takes the scale into account. As a result, 1.50 is not recognized as equal to 1.5, and the evaluator emits a false warning.

Environment
  • Project: OpenAPI Generator v7.25.0 (fork), commit ef964b04480889ef86b56cfae84ade8ad4c91c41
  • Module: modules/openapi-generator
  • Class/method: org.openapitools.codegen.validations.oas.OpenApiEvaluator#validate(OpenAPI)
  • OS: Linux 7.0.0-38-generic (amd64)
  • Java: OpenJDK 25 (compiled with source/target 11)
  • Tests: JUnit 5.10.2 + Mockito 4.10.0, run with the Maven Wrapper (Surefire 3.2.5)
Steps to reproduce
  1. Create an OpenAPI 3.0 document with a schema Rate that has a number property factor with enum: [1.5] and default: 1.50 (a NumberSchema with new BigDecimal("1.5") in the enum and new BigDecimal("1.50") as the default).
  2. Create a RuleConfiguration with isEnableRecommendations() = true and isEnableDefaultNotInEnumRecommendation() = true.
  3. Call new OpenApiEvaluator(config).validate(openAPI).
  4. Inspect getWarnings() on the result.

Automated test case: CT-OE-14 (OpenApiEvaluatorJUnitTest.ct14NumericDefaultComparedByValue).

./mvnw -pl modules/openapi-generator -am test -Dtest=OpenApiEvaluatorJUnitTest -Dsurefire.failIfNoSpecifiedTests=false
Expected result

No warning: 1.50 and 1.5 are the same number, so the default belongs to the enum.

Actual result
1.50 reported as outside enum [1.5]: [Schema has default value '1.50' not in enum [1.5]]
==> expected: <true> but was: <false>

The failure occurred in all 3 Surefire attempts (rerunFailingTestsCount = 2), so it is not flaky.

Root cause

In OpenApiEvaluator.java, line 73:

&& !enumList.contains(defaultValue)) {

List.contains relies on equals. For BigDecimal, new BigDecimal("1.5").equals(new BigDecimal("1.50")) returns false, while compareTo returns 0.

Impact

Users get a false recommendation and may "fix" a default that is already correct. The defect was reproduced with a model built in memory (unit test). It was not verified whether swagger-parser preserves the scale when reading a YAML/JSON file written with a different number of decimal places (e.g. 1.50).

Suggested fix

Compare numeric values by value and keep equals for every other type. For example:

boolean inEnum = enumList.stream().anyMatch(item ->
        (item instanceof BigDecimal && defaultValue instanceof BigDecimal)
                ? ((BigDecimal) item).compareTo((BigDecimal) defaultValue) == 0
                : Objects.equals(item, defaultValue));
主要言語
Java
スター
26.8k
フォーク
7.7k
平均マージ
1日 15時間
マージ済み PR(30日)
145

環境構築

Codespaces で開く

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

はじめの一歩

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

OpenAPITools/openapi-generator のほかの issue

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

似ている issue

Java の issue をもっと見る

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

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