简体   繁体   中英

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM