Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[BUG] OpenApiEvaluator emits "Unused model" warnings even when recommendations are disabled

未关闭 适合新手
#25,232 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@mohitduhan19 已经在做这个了。

开始于 2026年10月13日。

  • #25240 来自 @mohitduhan19 —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
82/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
java
领域
backend, testing

调研方向

阅读 modules/openapi-generator 和 OpenApiEvaluator.java,并将未使用 schema 的检查与 issue 中描述的建议检查进行比较。运行提供的 Maven Wrapper 测试命令,并检查 OpenApiEvaluatorJUnitTest.ct07GlobalRecommendationsOffSuppressUnusedSchema。当该测试通过,并且全局建议被禁用时未使用 schema 的警告会被抑制,即表示完成。

由索引模型根据 Issue 内容生成。

描述

Issue: Bug
Summary

OpenApiEvaluator.validate(OpenAPI) reports unused schemas (Unused model: <name>) even when recommendations are globally disabled (RuleConfiguration.isEnableRecommendations() == false). All other recommendations respect this flag: default not in enum, header with underscore, and GET/HEAD with request body. Only the unused-schema check ignores it. Recommendations are optional best-practice warnings that the evaluator should emit only when recommendations are enabled.

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 under components/schemas that is not referenced anywhere (e.g. Orphan).
  2. Create a RuleConfiguration with isEnableRecommendations() = false and isEnableUnusedSchemasRecommendation() = true (the default).
  3. Call new OpenApiEvaluator(config).validate(openAPI).
  4. Inspect getWarnings() on the result.

Automated test case: CT-OE-07 (OpenApiEvaluatorJUnitTest.ct07GlobalRecommendationsOffSuppressUnusedSchema).

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

No recommendation warnings, since recommendations are globally disabled.

Actual result
unused-schema recommendation emitted while recommendations are disabled: [Unused model: Orphan]
==> 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 46, the unused-schema block checks only its own flag:

if (ruleConfiguration.isEnableUnusedSchemasRecommendation()) {

The default-not-in-enum rule (line 61) and the delegated validators (OpenApiSchemaValidations, OpenApiParameterValidations, OpenApiOperationValidations, OpenApiSecuritySchemeValidations) all check the global isEnableRecommendations() flag first.

Impact
  • The CLI validate command without --recommend calls setEnableRecommendations(false) (Validate.java, lines 71–72). It still lists unused schemas as warnings and ends with "Spec has N recommendation(s)".
  • The Maven plugin's validate goal also disables recommendations (ValidateMojo.java, line 377). From reading the code, with strictSpec = true a single unused schema is enough to fail the goal (lines 245 and 252). This plugin behavior was identified by code reading only and was not executed.
Suggested fix

Require both flags, as the default-not-in-enum rule does:

if (ruleConfiguration.isEnableRecommendations()
        && ruleConfiguration.isEnableUnusedSchemasRecommendation()) {
主要语言
Java
星标
26.8k
派生
7.7k
平均合并
1 天 12 小时
30 天内合并 PR
141

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

OpenAPITools/openapi-generator 的其他 Issue

查看 OpenAPITools/openapi-generator 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。