You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Both project extensions and custom task instances provide bridge methods that allow Groovy DSL users to set file and directory properties using simple String paths. These bridge methods support both **method-style** and **property-style** syntax.
When configuring project extensions like `openApiGenerate { }`, `openApiValidate { }`, or `openApiMeta { }`, Groovy DSL users can use bridge methods to set properties with String paths.
.Example: Using extension bridge methods in Groovy DSL
707
+
[source,groovy]
708
+
----
709
+
// Method-style syntax
710
+
openApiGenerate {
711
+
generatorName.set("kotlin")
712
+
setInputSpec("$rootDir/specs/petstore.yaml")
713
+
setOutputDir("build/generated")
714
+
apiPackage.set("org.openapi.example.api")
715
+
}
716
+
717
+
// Property-style syntax (Groovy allows this syntactic sugar)
718
+
openApiGenerate {
719
+
generatorName.set("kotlin")
720
+
inputSpec = "$rootDir/specs/petstore.yaml"
721
+
outputDir = "build/generated"
722
+
apiPackage.set("org.openapi.example.api")
723
+
}
724
+
725
+
// Also works with openApiValidate
726
+
openApiValidate {
727
+
inputSpec = "$rootDir/specs/petstore.yaml"
728
+
recommend.set(true)
729
+
}
730
+
731
+
// And openApiMeta
732
+
openApiMeta {
733
+
generatorName.set("MyGenerator")
734
+
outputFolder = "build/custom-generator"
735
+
}
736
+
----
737
+
738
+
[IMPORTANT]
739
+
====
740
+
**Smart Input Routing:** The `setInputSpec()` method (in both extensions and tasks) automatically detects whether the provided path is a remote URL (e.g., `http://`, `https://`, `jar:`) or a local file path, and routes it to the appropriate property (`remoteInputSpec` or `inputSpec`).
741
+
742
+
Additionally, when you set a local file path after previously setting a remote URL (or vice versa), the method automatically clears the conflicting property to prevent stale values from taking precedence. This ensures your configuration behaves predictably even when you change between local and remote specs.
743
+
====
744
+
684
745
=== Generate multiple sources
685
746
686
747
If you want to perform multiple generation tasks, you'd want to create a task that inherits from the `GenerateTask`.
When creating custom task instances (as shown above), Groovy DSL users also have access to bridge methods with the `AsString` suffix. These methods provide the same functionality as the extension bridge methods.
783
+
784
+
[NOTE]
785
+
====
786
+
**Why the "AsString" suffix?**
787
+
788
+
Due to technical limitations with Gradle's abstract property getters in task classes, the bridge methods for custom tasks require the `AsString` suffix to avoid naming conflicts with Gradle's internal getter methods.
789
+
790
+
- **Extensions** (e.g., `openApiGenerate { }`) use methods like `setInputSpec()`, `setOutputDir()`
791
+
- **Custom Tasks** (e.g., `task myTask(type: GenerateTask) { }`) use methods like `setInputSpecAsString()`, `setOutputDirAsString()`
792
+
793
+
Both patterns work identically for String-based property configuration in Groovy DSL.
794
+
====
795
+
796
+
.Available AsString Bridge Methods for Custom Tasks
*Note: Standard string assignments (e.g., `inputSpec = "path/to/file.yaml"`) are still fully supported via bridge methods for static files checked into your repository.*
885
+
[NOTE]
886
+
====
887
+
**Provider API vs Bridge Methods:**
888
+
889
+
For optimal lazy configuration and task wiring, both Groovy and Kotlin DSL users should use `.set()` with the Provider API when possible (e.g., `inputSpec.set(downloadSpec.flatMap { it.outputFile })`).
890
+
891
+
For simpler cases with static String paths, Groovy DSL users can use the convenient bridge methods:
892
+
- Extension configuration: Use methods like `setInputSpec()`, `setOutputDir()` (see "Extension Bridge Methods" section)
893
+
- Custom task configuration: Use methods like `setInputSpecAsString()`, `setOutputDirAsString()` (see "Custom Task Bridge Methods" section)
0 commit comments