forked from loafle/openapi-generator-original
Merge remote-tracking branch 'origin/master' into 5.0-sync-master
This commit is contained in:
@@ -68,7 +68,7 @@ task validateSpecs(dependsOn: ['validateGoodSpec', 'validateBadSpec'])
|
||||
[source,group]
|
||||
----
|
||||
plugins {
|
||||
id "org.openapi.generator" version "4.2.3"
|
||||
id "org.openapi.generator" version "4.3.0"
|
||||
}
|
||||
----
|
||||
|
||||
@@ -330,6 +330,10 @@ apply plugin: 'org.openapi.generator'
|
||||
|false
|
||||
|To generate alias (array, list, map) as model. When false, top-level objects defined as array, list, or map will result in those definitions generated as top-level Array-of-items, List-of-items, Map-of-items definitions. When true, A model representation either containing or extending the array,list,map (depending on specific generator implementation) will be generated.
|
||||
|
||||
|engine
|
||||
|String
|
||||
|mustache
|
||||
|Templating engine: "mustache" (default) or "handlebars" (beta)
|
||||
|===
|
||||
|
||||
[NOTE]
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
# RELEASE_VERSION
|
||||
<<<<<<< HEAD
|
||||
openApiGeneratorVersion=5.0.0-SNAPSHOT
|
||||
=======
|
||||
openApiGeneratorVersion=4.3.1-SNAPSHOT
|
||||
>>>>>>> origin/master
|
||||
# /RELEASE_VERSION
|
||||
|
||||
# BEGIN placeholders
|
||||
|
||||
@@ -4,7 +4,11 @@
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<!-- RELEASE_VERSION -->
|
||||
<<<<<<< HEAD
|
||||
<version>5.0.0-SNAPSHOT</version>
|
||||
=======
|
||||
<version>4.3.1-SNAPSHOT</version>
|
||||
>>>>>>> origin/master
|
||||
<!-- /RELEASE_VERSION -->
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
|
||||
@@ -18,5 +18,5 @@ gradle generateGoWithInvalidSpec
|
||||
The samples can be tested against other versions of the plugin using the `openApiGeneratorVersion` property. For example:
|
||||
|
||||
```bash
|
||||
gradle -PopenApiGeneratorVersion=4.2.3 openApiValidate
|
||||
gradle -PopenApiGeneratorVersion=4.3.0 openApiValidate
|
||||
```
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
# RELEASE_VERSION
|
||||
openApiGeneratorVersion=4.3.0-SNAPSHOT
|
||||
openApiGeneratorVersion=4.3.1-SNAPSHOT
|
||||
# /RELEASE_VERSION
|
||||
|
||||
@@ -138,6 +138,7 @@ class OpenApiGeneratorPlugin : Plugin<Project> {
|
||||
enablePostProcessFile.set(generate.enablePostProcessFile)
|
||||
skipValidateSpec.set(generate.skipValidateSpec)
|
||||
generateAliasAsModel.set(generate.generateAliasAsModel)
|
||||
engine.set(generate.engine)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -307,6 +307,11 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
|
||||
*/
|
||||
val configOptions = project.objects.mapProperty<String, String>()
|
||||
|
||||
/**
|
||||
* Templating engine: "mustache" (default) or "handlebars" (beta)
|
||||
*/
|
||||
val engine = project.objects.property<String?>()
|
||||
|
||||
init {
|
||||
applyDefaults()
|
||||
}
|
||||
|
||||
@@ -375,6 +375,12 @@ open class GenerateTask : DefaultTask() {
|
||||
@get:Internal
|
||||
val configOptions = project.objects.mapProperty<String, String>()
|
||||
|
||||
/**
|
||||
* Templating engine: "mustache" (default) or "handlebars" (beta)
|
||||
*/
|
||||
@get:Internal
|
||||
val engine = project.objects.property<String?>()
|
||||
|
||||
private fun <T : Any?> Property<T>.ifNotEmpty(block: Property<T>.(T) -> Unit) {
|
||||
if (isPresent) {
|
||||
val item: T? = get()
|
||||
@@ -561,7 +567,14 @@ open class GenerateTask : DefaultTask() {
|
||||
configurator.setGenerateAliasAsModel(value)
|
||||
}
|
||||
|
||||
engine.ifNotEmpty { value ->
|
||||
if ("handlebars".equals(value, ignoreCase = true)) {
|
||||
configurator.setTemplatingEngineName("handlebars")
|
||||
}
|
||||
}
|
||||
|
||||
if (systemProperties.isPresent) {
|
||||
// TODO: rename to globalProperties in 5.0
|
||||
systemProperties.get().forEach { entry ->
|
||||
configurator.addSystemProperty(entry.key, entry.value)
|
||||
}
|
||||
|
||||
@@ -19,12 +19,13 @@
|
||||
package org.openapitools.generator.gradle.plugin.tasks
|
||||
|
||||
import io.swagger.parser.OpenAPIParser
|
||||
import io.swagger.v3.parser.core.models.ParseOptions
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.GradleException
|
||||
import org.gradle.api.logging.Logging
|
||||
import org.gradle.api.tasks.Internal
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.api.tasks.options.Option
|
||||
import org.gradle.api.logging.Logging
|
||||
import org.gradle.internal.logging.text.StyledTextOutput
|
||||
import org.gradle.internal.logging.text.StyledTextOutputFactory
|
||||
import org.gradle.kotlin.dsl.property
|
||||
@@ -71,7 +72,11 @@ open class ValidateTask : DefaultTask() {
|
||||
val recommendations = recommend.get()
|
||||
|
||||
logger.quiet("Validating spec $spec")
|
||||
val result = OpenAPIParser().readLocation(spec, null, null)
|
||||
|
||||
val options = ParseOptions()
|
||||
options.isResolve = true
|
||||
|
||||
val result = OpenAPIParser().readLocation(spec, null, options)
|
||||
val messages = result.messages.toSet()
|
||||
val out = services.get(StyledTextOutputFactory::class.java).create("openapi")
|
||||
|
||||
|
||||
@@ -126,4 +126,40 @@ class GenerateTaskDslTest : TestBase() {
|
||||
assertEquals(TaskOutcome.SUCCESS, result.task(":openApiGenerate")?.outcome,
|
||||
"Expected a successful run, but found ${result.task(":openApiGenerate")?.outcome}")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `openapiGenerate should attempt to set handlebars when specified as engine`(){
|
||||
// Arrange
|
||||
val projectFiles = mapOf(
|
||||
"spec.yaml" to javaClass.classLoader.getResourceAsStream("specs/petstore-v3.0.yaml")
|
||||
)
|
||||
|
||||
withProject("""
|
||||
plugins {
|
||||
id 'org.openapi.generator'
|
||||
}
|
||||
openApiGenerate {
|
||||
generatorName = "kotlin"
|
||||
inputSpec = file("spec.yaml").absolutePath
|
||||
outputDir = file("build/kotlin").absolutePath
|
||||
apiPackage = "org.openapitools.example.api"
|
||||
invokerPackage = "org.openapitools.example.invoker"
|
||||
modelPackage = "org.openapitools.example.model"
|
||||
engine = "handlebars"
|
||||
}
|
||||
""".trimIndent(), projectFiles)
|
||||
|
||||
// Act
|
||||
val result = GradleRunner.create()
|
||||
.withProjectDir(temp)
|
||||
.withArguments("openApiGenerate")
|
||||
.withPluginClasspath()
|
||||
.buildAndFail()
|
||||
|
||||
// Assert
|
||||
// rather than write out full handlebars generator templates, we'll just test that the configurator has set handlebars as the engine.
|
||||
assertTrue(result.output.contains("kotlin-client/model.handlebars (No such file or directory)"), "Build should have attempted to use handlebars.")
|
||||
assertEquals(TaskOutcome.FAILED, result.task(":openApiGenerate")?.outcome,
|
||||
"Expected a failed run, but found ${result.task(":openApiGenerate")?.outcome}")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user