Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto Apto para principiantes
#25,233 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@mohitduhan19 ya está trabajando en esto.

Desde el 13/10/2026.

  • #25241 de @mohitduhan19 — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
78/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
java, openapi

Línea de trabajo

Empieza con OpenApiEvaluator#validate(OpenAPI) en el módulo openapi-generator y la prueba CT-OE-14 indicada, OpenApiEvaluatorJUnitTest.ct14NumericDefaultComparedByValue. Lee la comprobación existente de la recomendación y ejecuta el comando de Maven para la prueba específica del issue. El objetivo se cumple cuando valores BigDecimal numéricamente iguales, como 1.5 y 1.50, no producen una advertencia, mientras que las demás comparaciones de enum conservan su comportamiento actual.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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));
Lenguaje dominante
Java
Estrellas
26.8k
Forks
7.7k
Merge medio
1 d 15 h
PR fusionados (30 d)
146

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de OpenAPITools/openapi-generator

Todos los issues de OpenAPITools/openapi-generator

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.