Skip to content

Commit f365900

Browse files
authored
[Enhancement] [Gradle Plugin] Allow templates from classpath (#14909)
* [Enhancement] [Gradle Plugin] Allow templates from classpath * Adding missing argument binding.
1 parent ea01903 commit f365900

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

modules/openapi-generator-gradle-plugin/README.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ apply plugin: 'org.openapi.generator'
174174
|None
175175
|The template directory holding a custom template.
176176

177+
|templateResourcePath
178+
|String
179+
|Directory with mustache templates via resource path. This option will overwrite any option defined in `templateDir`
180+
177181
|auth
178182
|String
179183
|None

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class OpenApiGeneratorPlugin : Plugin<Project> {
100100
inputSpecRootDirectory.set(generate.inputSpecRootDirectory)
101101
remoteInputSpec.set(generate.remoteInputSpec)
102102
templateDir.set(generate.templateDir)
103+
templateResourcePath.set(generate.templateResourcePath)
103104
auth.set(generate.auth)
104105
globalProperties.set(generate.globalProperties)
105106
configFile.set(generate.configFile)

modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/extensions/OpenApiGeneratorGenerateExtension.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
6969
*/
7070
val templateDir = project.objects.property<String?>()
7171

72+
/**
73+
* The template location (which may be a directory or a classpath location) holding custom templates.
74+
*/
75+
val templateResourcePath = project.objects.property<String?>()
76+
7277
/**
7378
* Adds authorization headers when fetching the OpenAPI definitions remotely.
7479
* Pass in a URL-encoded string of name:header with a comma separating multiple values

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ open class GenerateTask @Inject constructor(private val objectFactory: ObjectFac
133133
@PathSensitive(PathSensitivity.RELATIVE)
134134
val templateDir = project.objects.property<String?>()
135135

136+
/**
137+
* Resource path containing template files.
138+
*/
139+
@Optional
140+
@Input
141+
val templateResourcePath = project.objects.property<String?>()
142+
136143
/**
137144
* Adds authorization headers when fetching the OpenAPI definitions remotely.
138145
* Pass in a URL-encoded string of name:header with a comma separating multiple values
@@ -707,6 +714,13 @@ open class GenerateTask @Inject constructor(private val objectFactory: ObjectFac
707714
configurator.setTemplateDir(value)
708715
}
709716

717+
templateResourcePath.ifNotEmpty { value ->
718+
templateDir.ifNotEmpty {
719+
logger.warn("Both templateDir and templateResourcePath were configured. templateResourcePath overwrites templateDir.")
720+
}
721+
configurator.setTemplateDir(value)
722+
}
723+
710724
packageName.ifNotEmpty { value ->
711725
configurator.setPackageName(value)
712726
}

0 commit comments

Comments
 (0)