Skip to content

Commit 4a4fb00

Browse files
committed
Merge branch 'develop' into release
2 parents 5de8a9b + 0c9b971 commit 4a4fb00

29 files changed

Lines changed: 107 additions & 25 deletions

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kotlin.code.style=official
33
# project id
44
projectGroupId=io.github.smiley4
55
projectArtifactIdBase=ktor-swagger-ui
6-
projectVersion=3.2.0
6+
projectVersion=3.3.0
77

88
# publishing information
99
projectNameBase=Ktor Swagger UI
@@ -19,7 +19,7 @@ projectDeveloperUrl=https://github.com/SMILEY4
1919
versionKtor=2.3.11
2020
versionSwaggerUI=5.17.11
2121
versionSwaggerParser=2.1.22
22-
versionSchemaKenerator=1.0.1
22+
versionSchemaKenerator=1.1.0
2323
versionKotlinLogging=3.0.5
2424
versionKotest=5.8.0
2525
versionKotlinTest=1.8.21

ktor-swagger-ui-examples/src/main/kotlin/io/github/smiley4/ktorswaggerui/examples/CompleteConfig.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ private fun Application.myModule() {
138138
specAssigner = { _, _ -> PluginConfigDsl.DEFAULT_SPEC_ID }
139139
pathFilter = { _, url -> url.firstOrNull() != "hidden" }
140140
ignoredRouteSelectors = emptySet()
141-
postBuild = { api -> println("Completed api: $api") }
141+
postBuild = { api, name -> println("Completed api '$name': $api") }
142142
}
143143

144144

ktor-swagger-ui/src/main/kotlin/io/github/smiley4/ktorswaggerui/SwaggerPlugin.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import io.github.smiley4.ktorswaggerui.builder.route.RouteMeta
3030
import io.github.smiley4.ktorswaggerui.builder.schema.SchemaContext
3131
import io.github.smiley4.ktorswaggerui.builder.schema.SchemaContextImpl
3232
import io.github.smiley4.ktorswaggerui.data.PluginConfigData
33-
import io.github.smiley4.ktorswaggerui.data.TypeDescriptor
3433
import io.github.smiley4.ktorswaggerui.dsl.config.PluginConfigDsl
3534
import io.github.smiley4.ktorswaggerui.routing.ApiSpec
3635
import io.ktor.server.application.Application
@@ -83,12 +82,12 @@ private fun buildOpenApiSpecs(config: PluginConfigData, routes: List<RouteMeta>)
8382
return buildMap {
8483
routesBySpec.forEach { (specName, routes) ->
8584
val specConfig = config.specConfigs[specName] ?: config
86-
this[specName] = buildOpenApiSpec(specConfig, routes)
85+
this[specName] = buildOpenApiSpec(specName, specConfig, routes)
8786
}
8887
}
8988
}
9089

91-
private fun buildOpenApiSpec(pluginConfig: PluginConfigData, routes: List<RouteMeta>): String {
90+
private fun buildOpenApiSpec(specName: String, pluginConfig: PluginConfigData, routes: List<RouteMeta>): String {
9291
return try {
9392
val schemaContext = SchemaContextImpl(pluginConfig.schemaConfig).also {
9493
it.addGlobal(pluginConfig.schemaConfig)
@@ -99,7 +98,7 @@ private fun buildOpenApiSpec(pluginConfig: PluginConfigData, routes: List<RouteM
9998
it.add(routes)
10099
}
101100
val openApi = builder(pluginConfig, schemaContext, exampleContext).build(routes)
102-
pluginConfig.postBuild?.invoke(openApi)
101+
pluginConfig.postBuild?.let { it(openApi, specName) }
103102
Json.pretty(openApi)
104103
} catch (e: Exception) {
105104
logger.error("Error during openapi-generation", e)

ktor-swagger-ui/src/main/kotlin/io/github/smiley4/ktorswaggerui/data/DataUtils.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,23 @@ package io.github.smiley4.ktorswaggerui.data
22

33
object DataUtils {
44

5+
/**
6+
* Merges the two boolean values.
7+
* @return true if "value" is true, value of "base" otherwise
8+
*/
59
fun mergeBoolean(base: Boolean, value: Boolean) = if (value) true else base
610

11+
12+
/**
13+
* Merges the two values.
14+
* @return "value" if "value" is different from the given default value, "base" otherwise
15+
*/
716
fun <T> mergeDefault(base: T, value: T, default: T) = if (value != default) value else base
817

18+
/**
19+
* Merges the two values.
20+
* @return "value" if "value" is not null, "base" otherwise
21+
*/
922
fun <T> merge(base: T?, value: T?) = value ?: base
1023

1124
}

ktor-swagger-ui/src/main/kotlin/io/github/smiley4/ktorswaggerui/data/PostBuild.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ import io.swagger.v3.oas.models.OpenAPI
66
* Function executed after building the openapi-spec.
77
* @author <a href=mailto:mcxinyu@foxmail.com>yuefeng</a> in 2024/3/25.
88
*/
9-
typealias PostBuild = (openApi: OpenAPI) -> Unit
9+
typealias PostBuild = (openApi: OpenAPI, specId: String) -> Unit

ktor-swagger-ui/src/main/kotlin/io/github/smiley4/ktorswaggerui/dsl/config/ExampleConfig.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ class ExampleConfig {
5555
this.exampleEncoder = exampleEncoder
5656
}
5757

58+
/**
59+
* Build the data object for this config.
60+
* @param securityConfig the data for security config that might contain additional examples
61+
*/
5862
fun build(securityConfig: SecurityData) = ExampleConfigData(
5963
sharedExamples = sharedExamples,
6064
securityExamples = securityConfig.defaultUnauthorizedResponse?.body?.let {

ktor-swagger-ui/src/main/kotlin/io/github/smiley4/ktorswaggerui/dsl/config/OpenApiContact.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ class OpenApiContact {
2828
var email: String? = ContactData.DEFAULT.email
2929

3030

31+
/**
32+
* Build the data object for this config.
33+
* @param base the base config to "inherit" from. Values from the base should be copied, replaced or merged together.
34+
*/
3135
fun build(base: ContactData) = ContactData(
3236
name = merge(base.name, name),
3337
url = merge(base.url, url),

ktor-swagger-ui/src/main/kotlin/io/github/smiley4/ktorswaggerui/dsl/config/OpenApiExternalDocs.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ class OpenApiExternalDocs {
2121
*/
2222
var url: String = "/"
2323

24-
24+
/**
25+
* Build the data object for this config.
26+
* @param base the base config to "inherit" from. Values from the base should be copied, replaced or merged together.
27+
*/
2528
fun build(base: ExternalDocsData) = ExternalDocsData(
2629
url = DataUtils.mergeDefault(base.url, url, ExternalDocsData.DEFAULT.url),
2730
description = DataUtils.merge(base.description, description)

ktor-swagger-ui/src/main/kotlin/io/github/smiley4/ktorswaggerui/dsl/config/OpenApiInfo.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ class OpenApiInfo {
6262
license = OpenApiLicense().apply(block)
6363
}
6464

65-
65+
/**
66+
* Build the data object for this config.
67+
* @param base the base config to "inherit" from. Values from the base should be copied, replaced or merged together.
68+
*/
6669
fun build(base: InfoData): InfoData {
6770
return InfoData(
6871
title = mergeDefault(base.title, this.title, InfoData.DEFAULT.title),

ktor-swagger-ui/src/main/kotlin/io/github/smiley4/ktorswaggerui/dsl/config/OpenApiLicense.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ class OpenApiLicense {
2727
*/
2828
var identifier: String? = LicenseData.DEFAULT.identifier
2929

30+
/**
31+
* Build the data object for this config.
32+
* @param base the base config to "inherit" from. Values from the base should be copied, replaced or merged together.
33+
*/
3034
fun build(base: LicenseData) = LicenseData(
3135
name = DataUtils.merge(base.name, name),
3236
url = DataUtils.merge(base.url, url),

0 commit comments

Comments
 (0)