Skip to content

feat: add skipUnusedModels option to validate command and Gradle task#23716

Open
fabb wants to merge 1 commit intoOpenAPITools:masterfrom
fabb:fix/17679-skip-unused-models-validate
Open

feat: add skipUnusedModels option to validate command and Gradle task#23716
fabb wants to merge 1 commit intoOpenAPITools:masterfrom
fabb:fix/17679-skip-unused-models-validate

Conversation

@fabb
Copy link
Copy Markdown

@fabb fabb commented May 7, 2026

Description

Closes #17679

Adds a way to suppress the Unused model: <name> recommendation warnings emitted during spec validation for schemas that are defined in components/schemas but not directly referenced by any operation. This is a common pattern in specs that serve as shared model libraries or that are bundled across multiple spec files.

Prior art / existing workaround

RuleConfiguration already reads the openapi.generator.rule.unused-schemas system property to default enableUnusedSchemasRecommendation. This means the warning can already be suppressed without this PR, but only via undocumented JVM flags:

Gradle — add to gradle.properties:

org.gradle.jvmargs=-Dopenapi.generator.rule.unused-schemas=false

CLI — pass the flag when invoking the JVM:

JAVA_OPTS="-Dopenapi.generator.rule.unused-schemas=false" openapi-generator-cli validate -i api.yaml --recommend
# or
java -Dopenapi.generator.rule.unused-schemas=false -jar openapi-generator-cli.jar validate -i api.yaml --recommend

This PR surfaces the same control as a first-class, documented, per-invocation option.

Changes

CLI (validate command):

  • New --skip-unused-models flag. When set, enableUnusedSchemasRecommendation is disabled on the RuleConfiguration before validation runs.

Gradle plugin (ValidateTask + OpenApiGeneratorValidateExtension):

  • New skipUnusedModels property (default: false) on both the extension (for openApiValidate {} block) and the task.
  • Wired through OpenApiGeneratorPlugin alongside the existing recommend and treatWarningsAsErrors properties.

Usage

CLI:

openapi-generator-cli validate -i api.yaml --recommend --skip-unused-models

Gradle (Groovy DSL):

openApiValidate {
  inputSpec = "$rootDir/api.yaml"
  skipUnusedModels = true
}

Gradle (Kotlin DSL):

openApiValidate {
  inputSpec.set("$rootDir/api.yaml")
  skipUnusedModels.set(true)
}

Tests

Added two new ValidateTaskDslTest cases and a companion test spec (petstore-v3.0-with-unused-schema.yaml):

  • Verifies that the Unused model warning appears by default.
  • Verifies that skipUnusedModels = true suppresses the warning while the build still succeeds.

Adds a new `--skip-unused-models` flag to the CLI `validate` command and
a `skipUnusedModels` property to the Gradle `ValidateTask`/extension.

When enabled, the recommendation warning for schemas defined in
`components/schemas` that are not referenced by any operation is
suppressed. This is useful for specs where shared schemas are intentionally
defined without being directly bound to operations (e.g. shared model
libraries bundled across multiple spec files).

Fixes OpenAPITools#17679
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 6 files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[REQ] Add configuration option to skip unused models in the OpenAPI Generator CLI

1 participant