Skip to content

Commit

Permalink
Add better Swagger configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
cstroe committed Dec 15, 2018
1 parent 0628f5a commit f85e52a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
26 changes: 24 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.springframework.boot.gradle.tasks.bundling.BootJar
import io.swagger.v3.plugins.gradle.tasks.ResolveTask.Format.JSON

plugins {
id("java")
Expand All @@ -10,14 +11,16 @@ plugins {
id("org.jetbrains.kotlin.plugin.spring") version "1.3.11"
// https://kotlinlang.org/docs/reference/compiler-plugins.html#jpa-support
id("org.jetbrains.kotlin.plugin.jpa") version "1.3.11"
// https://github.com/swagger-api/swagger-core/tree/master/modules/swagger-gradle-plugin
id("io.swagger.core.v3.swagger-gradle-plugin") version "2.0.6"
}

repositories {
mavenCentral()
}

group = "cloud.cosmin.checklister"
version = "0.0.7-SNAPSHOT"
version = "0.0.7"

val compileKotlin: KotlinCompile by tasks

Expand All @@ -31,10 +34,20 @@ compileTestKotlin.kotlinOptions {
jvmTarget = "1.8"
}

// fixed name for boot JAR (referenced in Dockerfile)
val bootJar: BootJar by tasks

bootJar.archiveName = "app.jar"

// Customize JAR manifest to surface project version in app
tasks.jar {
manifest {
attributes(
"Implementation-Title" to "Checklister",
"Implementation-Version" to version
)
}
}

sourceSets {
create("integrationTest") {
compileClasspath += sourceSets.main.get().output
Expand All @@ -61,6 +74,15 @@ val integrationTest = task<Test>("integrationTest") {
shouldRunAfter("test")
}

tasks.resolve {
outputFileName = "PetStoreAPI"
outputFormat = JSON
prettyPrint = true
classpath = sourceSets["main"].runtimeClasspath
resourcePackages = setOf("io.test")
outputPath = "test"
}

dependencies {
// Kotlin
compile(kotlin("stdlib-jdk8"))
Expand Down
20 changes: 17 additions & 3 deletions src/main/kotlin/cloud/cosmin/checklister/config/SwaggerConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package cloud.cosmin.checklister.config
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import springfox.documentation.builders.RequestHandlerSelectors.basePackage
import springfox.documentation.service.ApiInfo
import springfox.documentation.service.Contact
import springfox.documentation.spi.DocumentationType
import springfox.documentation.spring.web.plugins.Docket
import springfox.documentation.swagger2.annotations.EnableSwagger2
Expand All @@ -12,10 +14,22 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2
class SwaggerConfig {
@Bean
fun checklisterApi(): Docket {
val docket = Docket(DocumentationType.SWAGGER_2);
docket.select()
val appName = this.javaClass.`package`.implementationTitle
val version = this.javaClass.`package`.implementationVersion
val apiInfo = ApiInfo(
"Checklister API",
"A RESTful API for managing lists.",
version,
"",
Contact("GitHub", "https://github.com/cosmincloud/checklister", null),
"Apache License 2.0",
"https://www.apache.org/licenses/LICENSE-2.0",
listOf())

return Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo)
.select()
.apis(basePackage("cloud.cosmin.checklister.rest"))
.build()
return docket
}
}

0 comments on commit f85e52a

Please sign in to comment.