[Enhancement] [Gradle Plugin] Allow templates from classpath (#14909)

* [Enhancement] [Gradle Plugin] Allow templates from classpath

* Adding missing argument binding.
This commit is contained in:
Daniel Imber 2024-06-13 14:20:41 +01:00 committed by GitHub
parent ea0190324e
commit f36590051f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 24 additions and 0 deletions

View File

@ -174,6 +174,10 @@ apply plugin: 'org.openapi.generator'
|None
|The template directory holding a custom template.
|templateResourcePath
|String
|Directory with mustache templates via resource path. This option will overwrite any option defined in `templateDir`
|auth
|String
|None

View File

@ -100,6 +100,7 @@ class OpenApiGeneratorPlugin : Plugin<Project> {
inputSpecRootDirectory.set(generate.inputSpecRootDirectory)
remoteInputSpec.set(generate.remoteInputSpec)
templateDir.set(generate.templateDir)
templateResourcePath.set(generate.templateResourcePath)
auth.set(generate.auth)
globalProperties.set(generate.globalProperties)
configFile.set(generate.configFile)

View File

@ -69,6 +69,11 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
*/
val templateDir = project.objects.property<String?>()
/**
* The template location (which may be a directory or a classpath location) holding custom templates.
*/
val templateResourcePath = project.objects.property<String?>()
/**
* Adds authorization headers when fetching the OpenAPI definitions remotely.
* Pass in a URL-encoded string of name:header with a comma separating multiple values

View File

@ -133,6 +133,13 @@ open class GenerateTask @Inject constructor(private val objectFactory: ObjectFac
@PathSensitive(PathSensitivity.RELATIVE)
val templateDir = project.objects.property<String?>()
/**
* Resource path containing template files.
*/
@Optional
@Input
val templateResourcePath = project.objects.property<String?>()
/**
* Adds authorization headers when fetching the OpenAPI definitions remotely.
* 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
configurator.setTemplateDir(value)
}
templateResourcePath.ifNotEmpty { value ->
templateDir.ifNotEmpty {
logger.warn("Both templateDir and templateResourcePath were configured. templateResourcePath overwrites templateDir.")
}
configurator.setTemplateDir(value)
}
packageName.ifNotEmpty { value ->
configurator.setPackageName(value)
}