Search code examples
gradlegroovyswaggergradle-kotlin-dsl

Configure swagger in gradle build script with kotlin dsl


I'm trying to switch my simple project from Groovy to Kotlin in build scripts. I'm using this plugin: https://github.com/gigaSproule/swagger-gradle-plugin I have this configuration in my build script:

swagger{
  apiSource {
    springmvc = false
    locations = ['my.location']
    schemes = ['https']
    host = 'test.com:8080'
    info {
      title = 'My Service'
      version = 'v1'
    }
    swaggerDirectory = "$buildDir/swagger"
  }

To where shall I refer to in this situations? Shall I do something like?

    task( "swagger" ) {
      ...
    }

It is not quite familiar for me. Thanks.


Solution

  • In case anyone is still looking for this information, this is how you would do it using Gradle Kotlin DSL:

    import com.benjaminsproule.swagger.gradleplugin.model.*
    
    plugins {
        id("com.benjaminsproule.swagger") version "1.0.0"
    }
    
    swagger {
        apiSource(closureOf<ApiSourceExtension> {
            springmvc = false
            schemes = mutableListOf("https")
            host = "test.com:8080"
    
            info(closureOf<InfoExtension> {
                title = "My Service"
                version = "v1"
                description = "My Service Description"
                termsOfService = "http://www.example.com/termsOfService"
                contact(closureOf<ContactExtension> {
                    email = "email@internet.com"
                    name = "A Developer"
                    url = "http://www.internet.com"
                })
                license(closureOf<LicenseExtension> {
                    url = "http://www.apache.org/licenses/LICENSE-2.0.html"
                    name = "Apache 2.0"
                })
            })
    
            locations = mutableListOf("com.foo.fighting")
            swaggerDirectory = "$buildDir/swagger"
        })
    }
    

    I've tested it using Gradle v4.6.