Skip to content

Commit a488d1e

Browse files
committed
Merge branch 'develop' into release
2 parents b4ce98b + b501b9b commit a488d1e

File tree

13 files changed

+123
-73
lines changed

13 files changed

+123
-73
lines changed

docs/changelog.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ search:
55

66
# Changelog
77

8+
## 5.3.0
9+
10+
- fix kotlinx-serialization example encoding [#212](https://github.com/SMILEY4/ktor-openapi-tools/issues/212)
11+
- fix missing response bodies from documented resources routes [#209](https://github.com/SMILEY4/ktor-openapi-tools/issues/209)
12+
- upgrade schema-kenerator from 2.3.0 to [2.4.0](https://github.com/SMILEY4/schema-kenerator/releases/tag/2.4.0)
13+
- upgrade ktor from 3.1.1 to ktor 3.3.0
14+
15+
## 5.2.0
16+
17+
- upgrade schema-kenerator from 2.1.3 to [2.3.0](https://github.com/SMILEY4/schema-kenerator/releases/tag/2.3.0)
18+
- fix handling of different OpenApi specs with multiple ktor modules
19+
820
## 5.1.0
921

1022
- upgrade schema-kenerator to [2.1.3](https://github.com/SMILEY4/schema-kenerator/releases/tag/2.1.3)

examples/src/main/kotlin/io/github/smiley4/ktoropenapi/examples/TypesafeRouting.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,15 @@ private fun Application.myModule() {
8181
call.respond(HttpStatusCode.NotImplemented, Unit)
8282
}
8383

84+
// delete route
8485
delete<PetsRoute.Id.Delete> { request ->
8586
println("..${request.parent.id}")
8687
call.respond(HttpStatusCode.NotImplemented, Unit)
8788
}
8889

89-
post<PetsRoute.Id.New> { request ->
90-
println("..${request.parent.id}")
90+
// post with request body. Request body is added to the schema automatically.
91+
post<PetsRoute.Id.New, Pet> { request, body ->
92+
println("..${request.parent.id} $body")
9193
call.respond(HttpStatusCode.NotImplemented, Unit)
9294
}
9395

gradle.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ kotlin.code.style=official
22

33
# project id
44
projectGroupId=io.github.smiley4
5-
projectVersion=5.2.0
5+
projectVersion=5.3.0
66

77
# common publishing information
88
projectBaseScmUrl=https://github.com/SMILEY4/
@@ -13,10 +13,10 @@ projectDeveloperName=smiley4
1313
projectDeveloperUrl=https://github.com/SMILEY4
1414

1515
# dependency versions
16-
versionKtor=3.1.1
16+
versionKtor=3.2.3
1717
versionSwaggerUI=5.17.14
1818
versionSwaggerParser=2.1.24
19-
versionSchemaKenerator=2.3.0
19+
versionSchemaKenerator=2.4.0
2020
versionKotlinLogging=7.0.0
2121
versionKotest=5.8.0
2222
versionKotlinTest=2.0.21

ktor-openapi/src/main/kotlin/io/github/smiley4/ktoropenapi/builder/example/ExampleContextImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ internal class ExampleContextImpl(private val encoder: GenericExampleEncoder) :
8282
private fun generateExample(exampleDescriptor: ExampleDescriptor, type: TypeDescriptor?): Example {
8383
return when (exampleDescriptor) {
8484
is ValueExampleDescriptor -> Example().also {
85-
it.value = encoder(type, exampleDescriptor.value)
85+
it.value = encoder(type ?: exampleDescriptor.type, exampleDescriptor.value)
8686
it.summary = exampleDescriptor.summary
8787
it.description = exampleDescriptor.description
8888
}

ktor-openapi/src/main/kotlin/io/github/smiley4/ktoropenapi/config/ExampleConfig.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package io.github.smiley4.ktoropenapi.config
22

33
import io.github.smiley4.ktoropenapi.config.descriptors.ExampleDescriptor
4+
import io.github.smiley4.ktoropenapi.config.descriptors.KTypeDescriptor
45
import io.github.smiley4.ktoropenapi.config.descriptors.SwaggerExampleDescriptor
56
import io.github.smiley4.ktoropenapi.config.descriptors.ValueExampleDescriptor
67
import io.github.smiley4.ktoropenapi.data.ExampleConfigData
78
import io.github.smiley4.ktoropenapi.data.MultipartBodyData
89
import io.github.smiley4.ktoropenapi.data.SecurityData
910
import io.github.smiley4.ktoropenapi.data.SimpleBodyData
1011
import io.swagger.v3.oas.models.examples.Example
12+
import kotlin.reflect.typeOf
1113

1214

1315
/**
@@ -43,15 +45,16 @@ class ExampleConfig internal constructor() {
4345
* Add a shared example that can be referenced by all routes by the given name.
4446
* The provided name has to be unique among all shared examples and acts as its id.
4547
*/
46-
fun example(name: String, example: ValueExampleDescriptorConfig.() -> Unit) = example(
47-
ValueExampleDescriptorConfig()
48+
inline fun <reified T> example(name: String, example: ValueExampleDescriptorConfig<T>.() -> Unit) = example(
49+
ValueExampleDescriptorConfig<T>()
4850
.apply(example)
4951
.let { result ->
5052
ValueExampleDescriptor(
5153
name = name,
5254
value = result.value,
5355
summary = result.summary,
54-
description = result.description
56+
description = result.description,
57+
type = KTypeDescriptor(typeOf<T>())
5558
)
5659
}
5760
)

ktor-openapi/src/main/kotlin/io/github/smiley4/ktoropenapi/config/RequestParameterConfig.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package io.github.smiley4.ktoropenapi.config
22

33
import io.github.smiley4.ktoropenapi.config.descriptors.ExampleDescriptor
4+
import io.github.smiley4.ktoropenapi.config.descriptors.KTypeDescriptor
45
import io.github.smiley4.ktoropenapi.config.descriptors.SwaggerExampleDescriptor
56
import io.github.smiley4.ktoropenapi.config.descriptors.ValueExampleDescriptor
67
import io.github.smiley4.ktoropenapi.config.descriptors.TypeDescriptor
78
import io.github.smiley4.ktoropenapi.data.RequestParameterData
89
import io.swagger.v3.oas.models.examples.Example
910
import io.swagger.v3.oas.models.parameters.Parameter
11+
import kotlin.reflect.typeOf
1012

1113
/**
1214
* Describes a single request parameter.
@@ -56,15 +58,16 @@ class RequestParameterConfig internal constructor(
5658
/**
5759
* An example value for this parameter
5860
*/
59-
fun example(name: String, example: ValueExampleDescriptorConfig.() -> Unit) = example(
60-
ValueExampleDescriptorConfig()
61+
inline fun <reified T> example(name: String, example: ValueExampleDescriptorConfig<T>.() -> Unit) = example(
62+
ValueExampleDescriptorConfig<T>()
6163
.apply(example)
6264
.let { result ->
6365
ValueExampleDescriptor(
6466
name = name,
6567
value = result.value,
6668
summary = result.summary,
67-
description = result.description
69+
description = result.description,
70+
type = KTypeDescriptor(typeOf<T>())
6871
)
6972
}
7073
)

ktor-openapi/src/main/kotlin/io/github/smiley4/ktoropenapi/config/SchemaGenerator.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@ object SchemaGenerator {
261261
type
262262
.analyzeTypeUsingKotlinxSerialization {
263263
serializersModule = configInstance.serializersModule
264-
knownNotParameterized = configInstance.knownNotParameterized
265264
customModules.addAll(configInstance.analyzerModules)
266265
}
267266
.addJsonClassDiscriminatorProperty()
@@ -306,35 +305,39 @@ object SchemaGenerator {
306305
* The types that are guaranteed to not have type parameters.
307306
* This helps the type processing step to determine whether two types are truly the same and may fix issues encountered with types.
308307
*/
308+
@Deprecated("unused")
309309
var knownNotParameterized = mutableSetOf<String>()
310310

311311

312312
/**
313313
* Mark the type with the given full/qualified name as "not parameterized", i.e. as not having any generic type parameters.
314314
* This helps the type processing step to determine whether two types are truly the same and may fix issues encountered with types.
315315
*/
316+
@Suppress("unused")
317+
@Deprecated("unused")
316318
fun markNotParameterized(name: String) {
317-
knownNotParameterized.add(name)
319+
// does nothing anymore
318320
}
319321

320322

321323
/**
322324
* Mark the given type as "not parameterized", i.e as not having any generic type parameters.
323325
* This helps the type processing step to determine whether two types are truly the same and may fix issues encountered with types.
324326
*/
327+
@Suppress("unused")
328+
@Deprecated("unused")
325329
fun markNotParameterized(type: KType) {
326-
val clazz = type.classifier!! as KClass<*>
327-
markNotParameterized(clazz.qualifiedName ?: clazz.java.name)
330+
// does nothing anymore
328331
}
329332

330333

331334
/**
332335
* Mark the given type as "not parameterized", i.e as not having any generic type parameters.
333336
* This helps the type processing step to determine whether two types are truly the same.
334337
*/
338+
@Deprecated("unused")
335339
inline fun <reified T> markNotParameterized() {
336-
val clazz = typeOf<T>().classifier!! as KClass<*>
337-
markNotParameterized(clazz.qualifiedName ?: clazz.java.name)
340+
// does nothing anymore
338341
}
339342

340343
/**

ktor-openapi/src/main/kotlin/io/github/smiley4/ktoropenapi/config/SimpleBodyConfig.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package io.github.smiley4.ktoropenapi.config
22

33
import io.github.smiley4.ktoropenapi.config.descriptors.ExampleDescriptor
4+
import io.github.smiley4.ktoropenapi.config.descriptors.KTypeDescriptor
45
import io.github.smiley4.ktoropenapi.config.descriptors.RefExampleDescriptor
56
import io.github.smiley4.ktoropenapi.config.descriptors.SwaggerExampleDescriptor
67
import io.github.smiley4.ktoropenapi.config.descriptors.ValueExampleDescriptor
78
import io.github.smiley4.ktoropenapi.config.descriptors.TypeDescriptor
89
import io.github.smiley4.ktoropenapi.data.SimpleBodyData
910
import io.swagger.v3.oas.models.examples.Example
11+
import kotlin.reflect.typeOf
1012

1113

1214
/**
@@ -40,15 +42,16 @@ class SimpleBodyConfig internal constructor(
4042
/**
4143
* Add the given example as an example to this body
4244
*/
43-
fun example(name: String, example: ValueExampleDescriptorConfig.() -> Unit) = example(
44-
ValueExampleDescriptorConfig()
45+
inline fun <reified T> example(name: String, example: ValueExampleDescriptorConfig<T>.() -> Unit) = example(
46+
ValueExampleDescriptorConfig<T>()
4547
.apply(example)
4648
.let { result ->
4749
ValueExampleDescriptor(
4850
name = name,
4951
value = result.value,
5052
summary = result.summary,
51-
description = result.description
53+
description = result.description,
54+
type = KTypeDescriptor(typeOf<T>())
5255
)
5356
}
5457
)

ktor-openapi/src/main/kotlin/io/github/smiley4/ktoropenapi/config/ValueExampleDescriptorConfig.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package io.github.smiley4.ktoropenapi.config
22

3-
class ValueExampleDescriptorConfig {
3+
class ValueExampleDescriptorConfig<T> {
44

55
/**
66
* the example value
77
*/
8-
var value: Any? = null
8+
var value: T? = null
99

1010

1111
/**

ktor-openapi/src/main/kotlin/io/github/smiley4/ktoropenapi/config/descriptors/ExampleDescriptor.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class ValueExampleDescriptor(
1818
val value: Any?,
1919
val summary: String? = null,
2020
val description: String? = null,
21+
val type: TypeDescriptor? = null,
2122
) : ExampleDescriptor(name)
2223

2324

0 commit comments

Comments
 (0)