Skip to content

Commit 2b9f040

Browse files
committed
add groovy bridge methods
1 parent ee99576 commit 2b9f040

4 files changed

Lines changed: 460 additions & 0 deletions

File tree

modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/tasks/GenerateTask.kt

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,4 +971,66 @@ abstract class GenerateTask : DefaultTask() {
971971
// All directory properties use the same conversion logic
972972
this.set(layout.projectDirectory.dir(path))
973973
}
974+
975+
// ========================================================================
976+
// Groovy DSL bridge methods
977+
// These methods allow Groovy DSL users to set properties using String paths.
978+
// Groovy's property syntax allows calling these as:
979+
// - Method style: setInputSpecAsString("$rootDir/api.yaml")
980+
// - Property style: inputSpecAsString = "$rootDir/api.yaml"
981+
// ========================================================================
982+
983+
/**
984+
* Groovy-compatible setter for inputSpec property.
985+
* Accepts a String and automatically routes to remote or local file based on URI detection.
986+
*/
987+
fun setInputSpecAsString(path: String) {
988+
if (path.isRemoteUri()) {
989+
remoteInputSpec.set(path)
990+
} else {
991+
inputSpec.set(layout.projectDirectory.file(path))
992+
}
993+
}
994+
995+
/**
996+
* Groovy-compatible setter for configFile property.
997+
*/
998+
fun setConfigFileAsString(path: String) {
999+
configFile.set(layout.projectDirectory.file(path))
1000+
}
1001+
1002+
/**
1003+
* Groovy-compatible setter for ignoreFileOverride property.
1004+
*/
1005+
fun setIgnoreFileOverrideAsString(path: String) {
1006+
ignoreFileOverride.set(layout.projectDirectory.file(path))
1007+
}
1008+
1009+
/**
1010+
* Groovy-compatible setter for templateDir property.
1011+
*/
1012+
fun setTemplateDirAsString(path: String) {
1013+
templateDir.set(layout.projectDirectory.dir(path))
1014+
}
1015+
1016+
/**
1017+
* Groovy-compatible setter for outputDir property.
1018+
*/
1019+
fun setOutputDirAsString(path: String) {
1020+
outputDir.set(layout.projectDirectory.dir(path))
1021+
}
1022+
1023+
/**
1024+
* Groovy-compatible setter for inputSpecRootDirectory property.
1025+
*/
1026+
fun setInputSpecRootDirectoryAsString(path: String) {
1027+
inputSpecRootDirectory.set(layout.projectDirectory.dir(path))
1028+
}
1029+
1030+
/**
1031+
* Groovy-compatible setter for schemaLocation property.
1032+
*/
1033+
fun setSchemaLocationAsString(path: String) {
1034+
schemaLocation.set(layout.projectDirectory.dir(path))
1035+
}
9741036
}

modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/tasks/MetaTask.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,19 @@ abstract class MetaTask : DefaultTask() {
155155
// All directory properties use the same conversion logic
156156
this.set(layout.projectDirectory.dir(path))
157157
}
158+
159+
// ========================================================================
160+
// Groovy DSL bridge methods
161+
// These methods allow Groovy DSL users to set properties using String paths.
162+
// Groovy's property syntax allows calling these as:
163+
// - Method style: setOutputFolderAsString("$buildDir/generated")
164+
// - Property style: outputFolderAsString = "$buildDir/generated"
165+
// ========================================================================
166+
167+
/**
168+
* Groovy-compatible setter for outputFolder property.
169+
*/
170+
fun setOutputFolderAsString(path: String) {
171+
outputFolder.set(layout.projectDirectory.dir(path))
172+
}
158173
}

modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/tasks/ValidateTask.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,24 @@ abstract class ValidateTask : DefaultTask() {
176176
}
177177
}
178178
}
179+
180+
// ========================================================================
181+
// Groovy DSL bridge methods
182+
// These methods allow Groovy DSL users to set properties using String paths.
183+
// Groovy's property syntax allows calling these as:
184+
// - Method style: setInputSpecAsString("$rootDir/api.yaml")
185+
// - Property style: inputSpecAsString = "$rootDir/api.yaml"
186+
// ========================================================================
187+
188+
/**
189+
* Groovy-compatible setter for inputSpec property.
190+
* Accepts a String and automatically routes to remote or local file based on URI detection.
191+
*/
192+
fun setInputSpecAsString(path: String) {
193+
if (path.isRemoteUri()) {
194+
remoteInputSpec.set(path)
195+
} else {
196+
inputSpec.set(layout.projectDirectory.file(path))
197+
}
198+
}
179199
}

0 commit comments

Comments
 (0)