Skip to content

Commit

Permalink
release 1.3.0
Browse files Browse the repository at this point in the history
this release introduces a breaking change in
`securityScheme` which now has a new first
parameter `name`.

closes #95
  • Loading branch information
derveloper committed Apr 24, 2023
1 parent dea09af commit 1cc82e0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ 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
```xml
<dependency>
<groupId>cc.vileda</groupId>
<artifactId>kotlin-openapi3-dsl</artifactId>
<version>1.2.0</version>
<version>1.3.0</version>
</dependency>
```

Expand Down
10 changes: 9 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ apply plugin: 'maven-publish'
apply plugin: 'signing'

group 'cc.vileda'
version '1.2.0'
version '1.3.0'

repositories {
mavenCentral()
Expand Down Expand Up @@ -120,4 +120,12 @@ compileKotlin {
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileJava {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
compileTestJava {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
4 changes: 2 additions & 2 deletions src/main/kotlin/cc/vileda/openapi/dsl/OpenApiDsl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ inline fun <reified T> 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) {
Expand Down
13 changes: 9 additions & 4 deletions src/test/kotlin/cc/vileda/openapi/dsl/OpenApiDslTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ data class AnotherExampleSchema(val bar: String)
data class ExampleRequestSchema(val foo: String)
data class ListExampleSchema(val baz: List<ExampleSchema>)

enum class ExampleEnum { ONE, TWO }
@Suppress("unused")
enum class ExampleEnum {
ONE,
TWO
}

class OpenApi3BuilderTest : StringSpec() {
init {
Expand Down Expand Up @@ -52,9 +56,9 @@ class OpenApi3BuilderTest : StringSpec() {
schema<AnotherExampleSchema>()
schema<ListExampleSchema>()
schema<ExampleEnum>()
securityScheme {
securityScheme("bearer") {
type = SecurityScheme.Type.OPENIDCONNECT
openIdConnectUrl = "http://localhost/auth"
openIdConnectUrl = "http://localhost:8080/auth"
flows {
implicit {
authorizationUrl = "http://localhost:8080/auth"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1cc82e0

Please sign in to comment.