Fix SkipValidSpec (#2583)

For #2319
This commit is contained in:
Thibault Duperron
2019-04-06 03:40:10 +02:00
committed by Jim Schubert
parent b444456ec8
commit ff9401fee5
3 changed files with 62 additions and 2 deletions

View File

@@ -525,7 +525,7 @@ open class GenerateTask : DefaultTask() {
}
skipValidateSpec.ifNotEmpty { value ->
configurator.setValidateSpec(value)
configurator.setValidateSpec(!value)
}
generateAliasAsModel.ifNotEmpty { value ->

View File

@@ -66,4 +66,64 @@ class GenerateTaskDslTest : TestBase() {
assertEquals(TaskOutcome.SUCCESS, result.task(":openApiGenerate")?.outcome,
"Expected a successful run, but found ${result.task(":openApiGenerate")?.outcome}")
}
@Test
fun `openApiValidate should fail on invalid spec`() {
// Arrange
val projectFiles = mapOf(
"spec.yaml" to javaClass.classLoader.getResourceAsStream("specs/petstore-v3.0-invalid.yaml")
)
withProject(defaultBuildGradle, projectFiles)
// Act
val result = GradleRunner.create()
.withProjectDir(temp)
.withArguments("openApiGenerate")
.withPluginClasspath()
.buildAndFail()
// Assert
assertTrue(result.output.contains("issues with the specification"), "Unexpected/no message presented to the user for an invalid spec.")
assertEquals(TaskOutcome.FAILED, result.task(":openApiGenerate")?.outcome,
"Expected a failed run, but found ${result.task(":openApiValidate")?.outcome}")
}
@Test
fun `openApiValidate should ok skip spec validation`() {
// Arrange
val projectFiles = mapOf(
"spec.yaml" to javaClass.classLoader.getResourceAsStream("specs/petstore-v3.0-invalid.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"
skipValidateSpec = true
configOptions = [
dateLibrary: "java8"
]
}
""".trimIndent(), projectFiles)
// Act
val result = GradleRunner.create()
.withProjectDir(temp)
.withArguments("openApiGenerate")
.withPluginClasspath()
.build()
// Assert
assertTrue(result.output.contains("validation has been explicitly disabled"), "Unexpected/no message presented to the user for an invalid spec.")
assertEquals(TaskOutcome.SUCCESS, result.task(":openApiGenerate")?.outcome,
"Expected a successful run, but found ${result.task(":openApiGenerate")?.outcome}")
}
}

View File

@@ -464,7 +464,7 @@ public class CodeGenMojo extends AbstractMojo {
}
if (skipValidateSpec != null) {
configurator.setSkipOverwrite(skipValidateSpec);
configurator.setValidateSpec(!skipValidateSpec);
}
if (logToStderr != null) {