Skip to content

Commit

Permalink
Merge branch 'bugfix/2-missing-security-schemes' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
SMILEY4 committed Sep 14, 2022
2 parents 715bb12 + 83336b8 commit 3db9bb6
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group = "io.github.smiley4"
version = "0.5.0"
version = "0.5.1"

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ private fun getBuilder(): ApiSpecBuilder {
return ApiSpecBuilder(
OApiInfoBuilder(),
OApiServersBuilder(),
OApiSecuritySchemesBuilder(
OApiOAuthFlowsBuilder()
),
OApiTagsBuilder(),
OApiPathsBuilder(
RouteCollector(),
Expand Down Expand Up @@ -87,7 +84,10 @@ private fun getBuilder(): ApiSpecBuilder {
),
),
OApiComponentsBuilder(
OApiExampleBuilder()
OApiExampleBuilder(),
OApiSecuritySchemesBuilder(
OApiOAuthFlowsBuilder()
)
),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import io.swagger.v3.oas.models.OpenAPI
class ApiSpecBuilder(
private val infoBuilder: OApiInfoBuilder,
private val serversBuilder: OApiServersBuilder,
private val securitySchemesBuilder: OApiSecuritySchemesBuilder,
private val tagsBuilder: OApiTagsBuilder,
private val pathsBuilder: OApiPathsBuilder,
private val componentsBuilder: OApiComponentsBuilder
Expand All @@ -26,14 +25,9 @@ class ApiSpecBuilder(
val openAPI = OpenAPI().apply {
info = infoBuilder.build(config.getInfo())
servers = serversBuilder.build(config.getServers())
if (config.getSecuritySchemes().isNotEmpty()) {
components = Components().apply {
securitySchemes = securitySchemesBuilder.build(config.getSecuritySchemes())
}
}
tags = tagsBuilder.build(config.getTags())
paths = pathsBuilder.build(config, application, componentCtx)
components = componentsBuilder.build(componentCtx)
components = componentsBuilder.build(componentCtx, config.getSecuritySchemes())
}
return Json.pretty(openAPI)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
package io.github.smiley4.ktorswaggerui.specbuilder

import io.github.smiley4.ktorswaggerui.dsl.OpenApiSecurityScheme
import io.swagger.v3.oas.models.Components

/**
* Builder for the OpenAPI Components Object
*/
class OApiComponentsBuilder(
private val exampleBuilder: OApiExampleBuilder
private val exampleBuilder: OApiExampleBuilder,
private val securitySchemesBuilder: OApiSecuritySchemesBuilder
) {

fun build(ctx: ComponentsContext): Components {
fun build(ctx: ComponentsContext, securitySchemes: List<OpenApiSecurityScheme>): Components {
return Components().apply {
schemas = ctx.schemas
examples = ctx.examples.mapValues {
exampleBuilder.build("", it.value, ComponentsContext.NOOP)
}
if (securitySchemes.isNotEmpty()) {
this.securitySchemes = securitySchemesBuilder.build(securitySchemes)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ fun getApiSpecBuilder(): ApiSpecBuilder {
return ApiSpecBuilder(
OApiInfoBuilder(),
OApiServersBuilder(),
OApiSecuritySchemesBuilder(
OApiOAuthFlowsBuilder()
),
OApiTagsBuilder(),
OApiPathsBuilder(
RouteCollector(),
Expand Down Expand Up @@ -56,7 +53,10 @@ fun getApiSpecBuilder(): ApiSpecBuilder {
),
),
OApiComponentsBuilder(
OApiExampleBuilder()
OApiExampleBuilder(),
OApiSecuritySchemesBuilder(
OApiOAuthFlowsBuilder()
),
),
)
}
Expand All @@ -68,7 +68,10 @@ fun getOApiInfoBuilder(): OApiInfoBuilder {

fun getOApiComponentsBuilder(): OApiComponentsBuilder {
return OApiComponentsBuilder(
OApiExampleBuilder()
OApiExampleBuilder(),
OApiSecuritySchemesBuilder(
OApiOAuthFlowsBuilder()
)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class ComponentsObjectTest : StringSpec({
companion object {

private fun buildComponentsObject(context: ComponentsContext): Components {
return getOApiComponentsBuilder().build(context)
return getOApiComponentsBuilder().build(context, listOf())
}

private fun buildSchema(type: KClass<*>, context: ComponentsContext): Schema<*> {
Expand Down

0 comments on commit 3db9bb6

Please sign in to comment.