Open jangalinski opened 5 years ago
It is not supported yet. It will be supported in the future release.
I have it working on version 2.15.0 and gradle 5 with this
swaggerSources {
create( "qwerservice", {
setInputFile( file("swagger.yml") )
code.outputDir = file( "$buildDir/client" )
code.language = "spring"
code.additionalProperties = mapOf( "group-id" to "com.qwer",
"dateLibrary" to "java8",
"java8" to "true",
"modelPackage" to "com.qwer.model",
"apiPackage" to "com.qwer.api",
"invokerPackage" to "com.qwer.invoker" )
} )
}
@mywill hi! Could you share your build.gradle.kts? I am trying to make it work with kotlindsl too.
@jangalinski @Clemzd @int128 and others that find this issue, here's an example:
plugins {
// ...
id("org.hidetake.swagger.generator") version "2.18.1"
}
// ...
dependencies {
swaggerCodegen("io.swagger.codegen.v3:swagger-codegen-cli:3.0.8")
// ... other Swagger dependencies like annotations
}
// ...
swaggerSources {
// Gradle recommends `register` over `create` to avoid eagerly creating/configuring items.
register("petstore") {
// Part of the "petstore" SwaggerSource
// Need to save a reference of it here because the `this` scope changes below.
val validationTask = validation
setInputFile(file("petstore-swagger.json"))
// The method signiature is `code(@DelegatesTo(GenerateSwaggerCode) Closure closure)`
// So best to use `delegateClosureOf<GenerateSwaggerCode>`
// https://docs.gradle.org/current/userguide/kotlin_dsl.html#groovy_closures_from_kotlin
code(delegateClosureOf<GenerateSwaggerCode> {
language = "spring"
components = listOf("models")
dependsOn(validationTask)
})
}
}
tasks.named("compileJava").configure {
dependsOn(tasks.named("generateSwaggerCode"))
}
sourceSets {
val main by getting
val petstore by swaggerSources.getting
main.java.srcDir("${petstore.code.outputDir}/src/main/java")
}
alternatively you can create a custom task like this:
import org.hidetake.gradle.swagger.generator.GenerateSwaggerCode
plugins {
id("org.hidetake.swagger.generator") version "2.18.2"
}
dependencies {
swaggerCodegen("io.swagger.codegen.v3:swagger-codegen-cli:3.0.23")
}
tasks {
register<GenerateSwaggerCode>("petstore") {
inputFile = projectDir.resolve("petstore.yaml")
language = "spring"
}
}
fyi to anyone seeing this, that "this scope changes" thing is not necessary. kotlin lets you use this@register and such, to access different scopes that are injected into the closure. it allows similar with return@ for breaking out of closures
I switched to gradle 5 and build.gradle.kts files ... How do I have to adopt the swaggerSources configuration block?