Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở Phù hợp với người mới
#25,232 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@mohitduhan19 đang làm issue này rồi.

Từ ngày 13/10/2026.

  • #25240 của @mohitduhan19 — đang mở

Đá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
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java
Lĩnh vực
backend, testing

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ả

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()) {
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

Mở trong Codespaces

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.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của OpenAPITools/openapi-generator

Tất cả issue của OpenAPITools/openapi-generator

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.