mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-03 14:10:56 +00:00
* #13726 Introduce new remoteInputSpec parameter * #13726 Add documentation and new warning log
This commit is contained in:
parent
7a17d3dc55
commit
3eec4eb326
@ -154,6 +154,11 @@ apply plugin: 'org.openapi.generator'
|
|||||||
|None
|
|None
|
||||||
|The Open API 2.0/3.x specification location.
|
|The Open API 2.0/3.x specification location.
|
||||||
|
|
||||||
|
|remoteInputSpec
|
||||||
|
|String
|
||||||
|
|None
|
||||||
|
|The remote Open API 2.0/3.x specification URL location.
|
||||||
|
|
||||||
|templateDir
|
|templateDir
|
||||||
|String
|
|String
|
||||||
|None
|
|None
|
||||||
|
@ -97,6 +97,7 @@ class OpenApiGeneratorPlugin : Plugin<Project> {
|
|||||||
generatorName.set(generate.generatorName)
|
generatorName.set(generate.generatorName)
|
||||||
outputDir.set(generate.outputDir)
|
outputDir.set(generate.outputDir)
|
||||||
inputSpec.set(generate.inputSpec)
|
inputSpec.set(generate.inputSpec)
|
||||||
|
remoteInputSpec.set(generate.remoteInputSpec)
|
||||||
templateDir.set(generate.templateDir)
|
templateDir.set(generate.templateDir)
|
||||||
auth.set(generate.auth)
|
auth.set(generate.auth)
|
||||||
globalProperties.set(generate.globalProperties)
|
globalProperties.set(generate.globalProperties)
|
||||||
|
@ -52,6 +52,11 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
|
|||||||
*/
|
*/
|
||||||
val inputSpec = project.objects.property<String>()
|
val inputSpec = project.objects.property<String>()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The remote Open API 2.0/3.x specification URL location.
|
||||||
|
*/
|
||||||
|
val remoteInputSpec = project.objects.property<String>()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The template directory holding a custom template.
|
* The template directory holding a custom template.
|
||||||
*/
|
*/
|
||||||
|
@ -91,10 +91,18 @@ open class GenerateTask : DefaultTask() {
|
|||||||
/**
|
/**
|
||||||
* The Open API 2.0/3.x specification location.
|
* The Open API 2.0/3.x specification location.
|
||||||
*/
|
*/
|
||||||
|
@Optional
|
||||||
@get:InputFile
|
@get:InputFile
|
||||||
@PathSensitive(PathSensitivity.RELATIVE)
|
@PathSensitive(PathSensitivity.RELATIVE)
|
||||||
val inputSpec = project.objects.property<String>()
|
val inputSpec = project.objects.property<String>()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The remote Open API 2.0/3.x specification URL location.
|
||||||
|
*/
|
||||||
|
@Input
|
||||||
|
@Optional
|
||||||
|
val remoteInputSpec = project.objects.property<String>()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The template directory holding a custom template.
|
* The template directory holding a custom template.
|
||||||
*/
|
*/
|
||||||
@ -556,6 +564,10 @@ open class GenerateTask : DefaultTask() {
|
|||||||
GlobalSettings.setProperty(CodegenConstants.WITH_XML, withXml.get().toString())
|
GlobalSettings.setProperty(CodegenConstants.WITH_XML, withXml.get().toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (inputSpec.isPresent && remoteInputSpec.isPresent) {
|
||||||
|
logger.warn("Both inputSpec and remoteInputSpec is specified. The remoteInputSpec will take priority over inputSpec.")
|
||||||
|
}
|
||||||
|
|
||||||
// now override with any specified parameters
|
// now override with any specified parameters
|
||||||
verbose.ifNotEmpty { value ->
|
verbose.ifNotEmpty { value ->
|
||||||
configurator.setVerbose(value)
|
configurator.setVerbose(value)
|
||||||
@ -573,6 +585,10 @@ open class GenerateTask : DefaultTask() {
|
|||||||
configurator.setInputSpec(value)
|
configurator.setInputSpec(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
remoteInputSpec.ifNotEmpty { value ->
|
||||||
|
configurator.setInputSpec(value)
|
||||||
|
}
|
||||||
|
|
||||||
generatorName.ifNotEmpty { value ->
|
generatorName.ifNotEmpty { value ->
|
||||||
configurator.setGeneratorName(value)
|
configurator.setGeneratorName(value)
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,65 @@ class GenerateTaskDslTest : TestBase() {
|
|||||||
}
|
}
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `openApiGenerate should create an expected file structure from URL config`() {
|
||||||
|
val specUrl = "https://raw.githubusercontent.com/OpenAPITools/openapi-generator/b6b8c0db872fb4a418ae496e89c7e656e14be165/modules/openapi-generator-gradle-plugin/src/test/resources/specs/petstore-v3.0.yaml"
|
||||||
|
// Arrange
|
||||||
|
val buildContents = """
|
||||||
|
plugins {
|
||||||
|
id 'org.openapi.generator'
|
||||||
|
}
|
||||||
|
openApiGenerate {
|
||||||
|
generatorName = "kotlin"
|
||||||
|
remoteInputSpec = "$specUrl"
|
||||||
|
outputDir = file("build/kotlin").absolutePath
|
||||||
|
apiPackage = "org.openapitools.example.api"
|
||||||
|
invokerPackage = "org.openapitools.example.invoker"
|
||||||
|
modelPackage = "org.openapitools.example.model"
|
||||||
|
configOptions = [
|
||||||
|
dateLibrary: "java8"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
""".trimIndent()
|
||||||
|
File(temp, "build.gradle").writeText(buildContents)
|
||||||
|
|
||||||
|
// Act
|
||||||
|
val result = GradleRunner.create()
|
||||||
|
.withProjectDir(temp)
|
||||||
|
.withArguments("openApiGenerate")
|
||||||
|
.withPluginClasspath()
|
||||||
|
.build()
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
assertTrue(
|
||||||
|
result.output.contains("Successfully generated code to"),
|
||||||
|
"User friendly generate notice is missing."
|
||||||
|
)
|
||||||
|
|
||||||
|
listOf(
|
||||||
|
"build/kotlin/.openapi-generator-ignore",
|
||||||
|
"build/kotlin/docs/PetsApi.md",
|
||||||
|
"build/kotlin/docs/Error.md",
|
||||||
|
"build/kotlin/docs/Pet.md",
|
||||||
|
"build/kotlin/README.md",
|
||||||
|
"build/kotlin/build.gradle",
|
||||||
|
"build/kotlin/.openapi-generator/VERSION",
|
||||||
|
"build/kotlin/settings.gradle",
|
||||||
|
"build/kotlin/src/main/kotlin/org/openapitools/example/model/Pet.kt",
|
||||||
|
"build/kotlin/src/main/kotlin/org/openapitools/example/model/Error.kt",
|
||||||
|
"build/kotlin/src/main/kotlin/org/openapitools/example/api/PetsApi.kt",
|
||||||
|
"build/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt"
|
||||||
|
).map {
|
||||||
|
val f = File(temp, it)
|
||||||
|
assertTrue(f.exists() && f.isFile, "An expected file was not generated when invoking the generation: $f")
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
TaskOutcome.SUCCESS, result.task(":openApiGenerate")?.outcome,
|
||||||
|
"Expected a successful run, but found ${result.task(":openApiGenerate")?.outcome}"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `openApiGenerate should create an expected file structure from DSL config`() {
|
fun `openApiGenerate should create an expected file structure from DSL config`() {
|
||||||
// Arrange
|
// Arrange
|
||||||
|
Loading…
x
Reference in New Issue
Block a user