[BUG] OpenApiEvaluator emits "Unused model" warnings even when recommendations are disabled
维护者通常 1 天内回复
评估
调研方向
阅读 modules/openapi-generator 和 OpenApiEvaluator.java,并将未使用 schema 的检查与 issue 中描述的建议检查进行比较。运行提供的 Maven Wrapper 测试命令,并检查 OpenApiEvaluatorJUnitTest.ct07GlobalRecommendationsOffSuppressUnusedSchema。当该测试通过,并且全局建议被禁用时未使用 schema 的警告会被抑制,即表示完成。
由索引模型根据 Issue 内容生成。
描述
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
- Create an OpenAPI 3.0 document with a schema under
components/schemasthat is not referenced anywhere (e.g.Orphan). - Create a
RuleConfigurationwithisEnableRecommendations() = falseandisEnableUnusedSchemasRecommendation() = true(the default). - Call
new OpenApiEvaluator(config).validate(openAPI). - 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
validatecommand without--recommendcallssetEnableRecommendations(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
validategoal also disables recommendations (ValidateMojo.java, line 377). From reading the code, withstrictSpec = truea 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
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
OpenAPITools/openapi-generator 的其他 Issue
-
[BUG] ExampleGenerator returns the string "{}" (or null) for `type: object` schemas without `properties`可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
OpenAPITools/openapi-generator#25237 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
OpenAPITools/openapi-generator#25236 ·
维护者通常 1 天内回复
-
[BUG] OpenApiEvaluator reports "default value not in enum" for numerically equal values with different scale (e.g. 1.5 and 1.50)可能已有人在做 @mohitduhan19 于 1 天前认领。 未关闭Issue: Bug
难度 2/5 1-3 小时 新手友好度 78/100
OpenAPITools/openapi-generator#25233 ·
维护者通常 1 天内回复
-
[BUG][KOTLIN] multiplatform/jvm-ktor: `DELETE` without `requestBody` sends `"Content-Type: application/json"` with an empty body可能已有人在做 @mohitduhan19 于 1 天前认领。 未关闭Issue: Bug
难度 2/5 1-3 小时 新手友好度 78/100
OpenAPITools/openapi-generator#25223 ·
维护者通常 1 天内回复
-
Issue: Bug
难度 2/5 1-3 小时 新手友好度 65/100
OpenAPITools/openapi-generator#25218 ·
维护者通常 1 天内回复
查看 OpenAPITools/openapi-generator 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
bug new windows
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
GantMan/jail-monkey#380 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
objectionary/jucs#145 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
objectionary/lints#1559 ·
维护者通常 2 天内回复