Plugin Options¶
These options control the plugin's behavior, including output format, file location, and build performance.
Basic Options¶
swagger {
pluginOptions {
enabled = true
saveInBuild = true
format = "yaml"
filePath = null
regenerationMode = "strict"
}
}
Option Reference¶
enabled¶
Enables or disables the plugin entirely.
Set to false to temporarily disable OpenAPI generation without removing the plugin:
Conditional Enabling
You can enable/disable based on build type:
Then run:./gradlew build -PskipOpenApi saveInBuild¶
Controls whether the spec is saved in the build/ directory.
When true, the spec is saved to:
When false and filePath is not set, it saves to:
format¶
Sets the output format for the generated specification.
| Value | Description |
|---|---|
"yaml" | YAML format (default, more readable) |
"json" | JSON format (better for programmatic use) |
filePath¶
Custom absolute path for the generated specification.
Override to save to a specific location:
Absolute Path Required
The filePath must be an absolute path. Use ${project.projectDir} to reference your project directory.
regenerationMode¶
Controls how the plugin handles incremental compilation.
| Mode | Build Speed | Correctness | Best For |
|---|---|---|---|
"strict" | Slower | Always complete | CI/CD, releases |
"safe" | Balanced | Usually complete | Local development |
"fast" | Fastest | May be incomplete | Rapid prototyping |
strict (Default)¶
Always regenerates the full spec on every build:
Pros: Guarantees a complete and accurate specification
Cons: Disables incremental compilation benefits
Use for: CI/CD pipelines, production builds, any build where spec accuracy is critical
safe¶
Tracks source files containing @GenerateOpenApi and regenerates when they change:
Pros: Faster builds when editing non-route files
Cons: May miss body-only changes in route helper functions
Use for: Local development when you primarily edit @GenerateOpenApi annotated files
fast¶
Trusts Kotlin's incremental compilation completely:
Pros: Fastest possible builds
Cons: May produce incomplete specs during incremental builds
Use for: Rapid prototyping where you don't need an accurate spec
CI/CD Recommendation
For CI/CD pipelines, always use strict mode to ensure your deployed API documentation is complete.
Environment-Based Configuration¶
Configure different options for different environments:
swagger {
pluginOptions {
// Use fast mode locally, strict in CI
regenerationMode = if (System.getenv("CI") != null) "strict" else "safe"
// Different output format for different environments
format = findProperty("openapi.format")?.toString() ?: "yaml"
}
}
Complete Reference¶
| Option | Type | Default | Description |
|---|---|---|---|
enabled | Boolean | true | Enable/disable the plugin |
saveInBuild | Boolean | true | Save spec in build directory |
format | String | "yaml" | Output format: yaml or json |
filePath | String? | null | Custom output path (absolute) |
regenerationMode | String | "strict" | Incremental build mode |