feat: add skipUnusedModels option to validate command and Gradle task#23716
Open
fabb wants to merge 1 commit intoOpenAPITools:masterfrom
Open
feat: add skipUnusedModels option to validate command and Gradle task#23716fabb wants to merge 1 commit intoOpenAPITools:masterfrom
fabb wants to merge 1 commit intoOpenAPITools:masterfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Closes #17679
Adds a way to suppress the
Unused model: <name>recommendation warnings emitted during spec validation for schemas that are defined incomponents/schemasbut 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
RuleConfigurationalready reads theopenapi.generator.rule.unused-schemassystem property to defaultenableUnusedSchemasRecommendation. This means the warning can already be suppressed without this PR, but only via undocumented JVM flags:Gradle — add to
gradle.properties:CLI — pass the flag when invoking the JVM:
This PR surfaces the same control as a first-class, documented, per-invocation option.
Changes
CLI (
validatecommand):--skip-unused-modelsflag. When set,enableUnusedSchemasRecommendationis disabled on theRuleConfigurationbefore validation runs.Gradle plugin (
ValidateTask+OpenApiGeneratorValidateExtension):skipUnusedModelsproperty (default:false) on both the extension (foropenApiValidate {}block) and the task.OpenApiGeneratorPluginalongside the existingrecommendandtreatWarningsAsErrorsproperties.Usage
CLI:
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
ValidateTaskDslTestcases and a companion test spec (petstore-v3.0-with-unused-schema.yaml):Unused modelwarning appears by default.skipUnusedModels = truesuppresses the warning while the build still succeeds.