[BUG] OpenApiEvaluator emits "Unused model" warnings even when recommendations are disabled
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 82/100
Hướng nghiên cứu
Đọc modules/openapi-generator và OpenApiEvaluator.java, rồi so sánh bước kiểm tra schema không được sử dụng với các bước kiểm tra đề xuất được mô tả trong issue. Chạy lệnh kiểm thử Maven Wrapper được cung cấp và kiểm tra OpenApiEvaluatorJUnitTest.ct07GlobalRecommendationsOffSuppressUnusedSchema. Hoàn tất khi kiểm thử đó chạy thành công và các cảnh báo về schema không được sử dụng bị tắt khi các đề xuất toàn cục bị vô hiệu hóa.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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()) {
- Ngôn ngữ chính
- Java
- Star
- 26.8k
- Fork
- 7.7k
- Merge trung bình
- 1 ngày 11 giờ
- Pull request đã merge (30 ngày)
- 139
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Có Dockerfile hoặc tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của OpenAPITools/openapi-generator
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
OpenAPITools/openapi-generator#25237 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
OpenAPITools/openapi-generator#25236 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] OpenApiEvaluator reports "default value not in enum" for numerically equal values with different scale (e.g. 1.5 and 1.50)Có thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởIssue: Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
OpenAPITools/openapi-generator#25233 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG][KOTLIN] multiplatform/jvm-ktor: `DELETE` without `requestBody` sends `"Content-Type: application/json"` with an empty bodyCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởIssue: Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
OpenAPITools/openapi-generator#25223 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Issue: Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
OpenAPITools/openapi-generator#25218 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của OpenAPITools/openapi-generator
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
wildfly/wildfly-launcher#99 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
traccar/traccar#6076 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Flight SQL JDBC parses boolean properties case-sensitively, silently disabling TLS for useEncryption=TRUECó thể đã có người làm @Arawoof06 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
apache/arrow-java#1357 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug] Demo alert imports accept empty and oversized rule documentsCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
apache/rocketmq-dashboard#6610 ·
Maintainer thường phản hồi trong vòng 3 ngày