Skip to content

Commit

Permalink
[Enhancement] [Gradle Plugin] Allow templates from classpath (#14909)
Browse files Browse the repository at this point in the history
* [Enhancement] [Gradle Plugin] Allow templates from classpath

* Adding missing argument binding.
  • Loading branch information
dimber-cais committed Jun 13, 2024
1 parent ea01903 commit f365900
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions modules/openapi-generator-gradle-plugin/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit f365900

Please sign in to comment.