diff --git a/README.md b/README.md index ec58bf7..40f482f 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ kotlin-openapi3-dsl is available on maven central ### gradle ```groovy -compile "cc.vileda:kotlin-openapi3-dsl:1.2.0" +compile "cc.vileda:kotlin-openapi3-dsl:1.3.0" ``` ### maven @@ -20,7 +20,7 @@ compile "cc.vileda:kotlin-openapi3-dsl:1.2.0" cc.vileda kotlin-openapi3-dsl - 1.2.0 + 1.3.0 ``` diff --git a/build.gradle b/build.gradle index 0d1323f..4b0346d 100644 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ apply plugin: 'maven-publish' apply plugin: 'signing' group 'cc.vileda' -version '1.2.0' +version '1.3.0' repositories { mavenCentral() @@ -120,4 +120,12 @@ compileKotlin { } compileTestKotlin { kotlinOptions.jvmTarget = "1.8" +} +compileJava { + sourceCompatibility = 1.8 + targetCompatibility = 1.8 +} +compileTestJava { + sourceCompatibility = 1.8 + targetCompatibility = 1.8 } \ No newline at end of file diff --git a/src/main/kotlin/cc/vileda/openapi/dsl/OpenApiDsl.kt b/src/main/kotlin/cc/vileda/openapi/dsl/OpenApiDsl.kt index fa2230e..e8bc10b 100644 --- a/src/main/kotlin/cc/vileda/openapi/dsl/OpenApiDsl.kt +++ b/src/main/kotlin/cc/vileda/openapi/dsl/OpenApiDsl.kt @@ -125,14 +125,14 @@ inline fun Components.schema() { schemas.put(T::class.java.simpleName, schema) } -fun Components.securityScheme(init: SecurityScheme.() -> Unit) { +fun Components.securityScheme(name: String, init: SecurityScheme.() -> Unit) { val security = SecurityScheme() security.init() securitySchemes = securitySchemes ?: mutableMapOf() // Security schemes will not validate with a name value. Use https://editor.swagger.io to validate. // Use the type as the name. see https://swagger.io/docs/specification/authentication/ - securitySchemes.put(security.type.toString(), security) + addSecuritySchemes(name, security) } fun SecurityScheme.flows(init: OAuthFlows.() -> Unit) { diff --git a/src/test/kotlin/cc/vileda/openapi/dsl/OpenApiDslTest.kt b/src/test/kotlin/cc/vileda/openapi/dsl/OpenApiDslTest.kt index a21f61a..981c38f 100644 --- a/src/test/kotlin/cc/vileda/openapi/dsl/OpenApiDslTest.kt +++ b/src/test/kotlin/cc/vileda/openapi/dsl/OpenApiDslTest.kt @@ -19,7 +19,11 @@ data class AnotherExampleSchema(val bar: String) data class ExampleRequestSchema(val foo: String) data class ListExampleSchema(val baz: List) -enum class ExampleEnum { ONE, TWO } +@Suppress("unused") +enum class ExampleEnum { + ONE, + TWO +} class OpenApi3BuilderTest : StringSpec() { init { @@ -52,9 +56,9 @@ class OpenApi3BuilderTest : StringSpec() { schema() schema() schema() - securityScheme { + securityScheme("bearer") { type = SecurityScheme.Type.OPENIDCONNECT - openIdConnectUrl = "http://localhost/auth" + openIdConnectUrl = "http://localhost:8080/auth" flows { implicit { authorizationUrl = "http://localhost:8080/auth" @@ -153,10 +157,11 @@ class OpenApi3BuilderTest : StringSpec() { api.info.title shouldBe "jjjj" api.info.version shouldBe "1.0" val securityScheme = - api.components.securitySchemes[SecurityScheme.Type.OPENIDCONNECT.toString()] + api.components.securitySchemes["bearer"] securityScheme shouldNotBe null securityScheme!!.flows!!.implicit shouldNotBe null securityScheme.flows.implicit!!.extensions!!["x-internal"] shouldBe true + securityScheme.type shouldBe SecurityScheme.Type.OPENIDCONNECT val postOp = api.paths["foo"]!!.readOperationsMap()!![PathItem.HttpMethod.POST] postOp shouldNotBe null