Skip to content

Commit 5de8a9b

Browse files
committed
Merge branch 'develop' into release
2 parents 63296fd + 076b9f0 commit 5de8a9b

19 files changed

Lines changed: 193 additions & 33 deletions

File tree

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ install(SwaggerUI) {
5656
}
5757
}
5858
```
59+
```kotlin
60+
routing {
61+
// Create a route for the openapi-spec file.
62+
route("api.json") {
63+
openApiSpec()
64+
}
65+
// Create a route for the swagger-ui using the openapi-spec at "/api.json".
66+
route("swagger") {
67+
swaggerUI("/api.json")
68+
}
69+
}
70+
```
5971

6072
### Routes
6173

gradle.properties

Lines changed: 1 addition & 1 deletion
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.1.0
6+
projectVersion=3.2.0
77

88
# publishing information
99
projectNameBase=Ktor Swagger UI

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private fun Application.myModule() {
4949
scheme = AuthScheme.BASIC
5050
}
5151
// if no other security scheme is specified for a route, the one with this name is used instead
52-
defaultSecuritySchemeNames = setOf("MySecurityScheme")
52+
defaultSecuritySchemeNames("MySecurityScheme")
5353
// if no other response is documented for "401 Unauthorized", this information is used instead
5454
defaultUnauthorizedResponse {
5555
description = "Username or password is invalid"
@@ -88,7 +88,7 @@ private fun Application.myModule() {
8888
// route is not in an "authenticate"-block and "protected"-flag is not set
8989
// -> security schemes will be ignored and not default "401 Unauthorized" response is added
9090
get("unprotected", {
91-
securitySchemeNames = listOf("MySecurityScheme")
91+
securitySchemeNames("MySecurityScheme")
9292
}) {
9393
call.respondText("Hello World!")
9494
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ private fun Application.myModule() {
7070
// information about possible responses
7171
response {
7272
// information about a "200 OK" response
73-
HttpStatusCode.OK to {
73+
code(HttpStatusCode.OK) {
7474
// a description of the response
7575
description = "successful request - always returns 'Hello World!'"
7676
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private fun Application.myModule() {
9191
defaultUnauthorizedResponse {
9292
description = "Username or password is invalid"
9393
}
94-
defaultSecuritySchemeNames = setOf("MySecurityScheme")
94+
defaultSecuritySchemeNames("MySecurityScheme")
9595
securityScheme("MySecurityScheme") {
9696
type = AuthType.HTTP
9797
scheme = AuthScheme.BASIC
@@ -157,12 +157,12 @@ private fun Application.myModule() {
157157
operationId = "hello"
158158
summary = "hello world route"
159159
description = "A Hello-World route as an example."
160-
tags = setOf("hello", "example")
160+
tags("hello", "example")
161161
specId = PluginConfigDsl.DEFAULT_SPEC_ID
162162
deprecated = false
163163
hidden = false
164164
protected = false
165-
securitySchemeNames = emptyList()
165+
securitySchemeNames(emptyList())
166166
externalDocs {
167167
url = "example.com/hello"
168168
description = "external documentation of 'hello'-route"
@@ -179,7 +179,7 @@ private fun Application.myModule() {
179179
body<Unit>()
180180
}
181181
response {
182-
HttpStatusCode.OK to {
182+
code(HttpStatusCode.OK) {
183183
description = "successful request - always returns 'Hello World!'"
184184
header<String>("x-random") {
185185
description = "A header with some random number"
@@ -189,7 +189,7 @@ private fun Application.myModule() {
189189
}
190190
body<Greeting> {
191191
description = "the greeting object with the name of the person to greet."
192-
mediaTypes = setOf(ContentType.Application.Json)
192+
mediaTypes(ContentType.Application.Json)
193193
required = true
194194
}
195195
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private fun Application.myModule() {
6161
// information about the request
6262
response {
6363
// information about a "200 OK" response
64-
HttpStatusCode.OK to {
64+
code(HttpStatusCode.OK) {
6565
// body of the response
6666
body<MyResponseBody>()
6767
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ private fun Application.myModule() {
4848
post("single", {
4949
request {
5050
body<File> {
51-
mediaTypes = setOf(
51+
mediaTypes(
5252
ContentType.Image.PNG,
5353
ContentType.Image.JPEG,
5454
ContentType.Image.SVG,
@@ -63,16 +63,16 @@ private fun Application.myModule() {
6363
post("multipart", {
6464
request {
6565
multipartBody {
66-
mediaTypes = setOf(ContentType.MultiPart.FormData)
66+
mediaTypes(ContentType.MultiPart.FormData)
6767
part<File>("first-image",) {
68-
mediaTypes = setOf(
68+
mediaTypes(
6969
ContentType.Image.PNG,
7070
ContentType.Image.JPEG,
7171
ContentType.Image.SVG
7272
)
7373
}
7474
part<File>("second-image") {
75-
mediaTypes = setOf(
75+
mediaTypes(
7676
ContentType.Image.PNG,
7777
ContentType.Image.JPEG,
7878
ContentType.Image.SVG

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private fun Application.myModule() {
7878
}
7979
}
8080
response {
81-
HttpStatusCode.OK to {
81+
code(HttpStatusCode.OK) {
8282
body<List<Pet>> {
8383
description = "the list of available pets"
8484
example("Pet List") {
@@ -130,7 +130,7 @@ private fun Application.myModule() {
130130
}
131131
}
132132
response {
133-
HttpStatusCode.OK to {
133+
code(HttpStatusCode.OK) {
134134
body<Pet> {
135135
description = "the created pet"
136136
example("Bird") {
@@ -175,7 +175,7 @@ private fun Application.myModule() {
175175
}
176176
}
177177
response {
178-
HttpStatusCode.OK to {
178+
code(HttpStatusCode.OK) {
179179
body<Pet>{
180180
description = "the pet with the given id"
181181
example("Bird") {
@@ -194,7 +194,7 @@ private fun Application.myModule() {
194194
}
195195
}
196196
}
197-
HttpStatusCode.NotFound to {
197+
code(HttpStatusCode.NotFound) {
198198
description = "the pet with the given id was not found"
199199
}
200200
default {
@@ -221,10 +221,10 @@ private fun Application.myModule() {
221221
}
222222
}
223223
response {
224-
HttpStatusCode.NoContent to {
224+
code(HttpStatusCode.NoContent) {
225225
description = "the pet was successfully deleted"
226226
}
227-
HttpStatusCode.NotFound to {
227+
code(HttpStatusCode.NotFound) {
228228
description = "the pet with the given id was not found"
229229
}
230230
default {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ private fun Application.myModule() {
6262
// information the possible responses
6363
response {
6464
// document the "200 OK"-response
65-
HttpStatusCode.OK to {
65+
code(HttpStatusCode.OK) {
6666
description = "Calculation was performed successfully."
6767
// specify the schema of the response-body and some additional information
6868
body<CalculationResult> {
6969
description = "the result of an operation together with the original request"
7070
}
7171
}
7272
// document the "422 UnprocessableEntity"-response
73-
HttpStatusCode.UnprocessableEntity to {
73+
code(HttpStatusCode.UnprocessableEntity) {
7474
description = "The requested calculation could not be performed, e.g. due to division by zero."
7575
}
7676
}

ktor-swagger-ui/src/main/kotlin/io/github/smiley4/ktorswaggerui/builder/example/ExampleContextImpl.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ class ExampleContextImpl(private val encoder: ExampleEncoder?) : ExampleContext
2121
val example = generateExample(exampleDescriptor, null)
2222
componentExamples[exampleDescriptor.name] = example
2323
}
24-
config.securityExamples.forEach { exampleDescriptor ->
25-
val example = generateExample(exampleDescriptor, null)
26-
rootExamples[exampleDescriptor] = example
24+
config.securityExamples?.let {
25+
it.examples.forEach { exampleDescriptor ->
26+
val example = generateExample(exampleDescriptor, it.type)
27+
rootExamples[exampleDescriptor] = example
28+
}
2729
}
2830
}
2931

0 commit comments

Comments
 (0)