Skip to content

Commit f9447e1

Browse files
committed
Merge branch 'support-redoc' into pre-release-5-0-0
2 parents b5b9b38 + d822fd9 commit f9447e1

File tree

29 files changed

+688
-104
lines changed

29 files changed

+688
-104
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ repositories {
1313
}
1414

1515
dependencies {
16-
implementation(project(":ktor-swagger-ui"))
1716
implementation(project(":ktor-openapi"))
17+
implementation(project(":ktor-swagger-ui"))
18+
implementation(project(":ktor-redoc"))
1819

1920
val versionKtor: String by project
2021
implementation("io.ktor:ktor-server-netty-jvm:$versionKtor")

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

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

33
import io.github.smiley4.ktoropenapi.OpenApi
44
import io.github.smiley4.ktoropenapi.config.AuthScheme
55
import io.github.smiley4.ktoropenapi.config.AuthType
66
import io.github.smiley4.ktoropenapi.get
77
import io.github.smiley4.ktoropenapi.openApi
8+
import io.github.smiley4.ktorredoc.redoc
89
import io.github.smiley4.ktorswaggerui.swaggerUI
910
import io.ktor.server.application.Application
1011
import io.ktor.server.application.install
@@ -60,13 +61,16 @@ private fun Application.myModule() {
6061

6162
routing {
6263

63-
// add the routes for swagger-ui and api-spec
64+
// add the routes for the api-spec, swagger-ui and redoc
6465
route("swagger") {
6566
swaggerUI("/api.json")
6667
}
6768
route("api.json") {
6869
openApi()
6970
}
71+
route("redoc") {
72+
redoc("/api.json")
73+
}
7074

7175
authenticate {
7276
// route is in an "authenticate"-block -> default security-scheme will be used (if not specified otherwise)

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
package io.github.smiley4.ktorswaggerui.examples
1+
package io.github.smiley4.ktoropenapi.examples
22

33
import io.github.smiley4.ktoropenapi.OpenApi
44
import io.github.smiley4.ktoropenapi.get
55
import io.github.smiley4.ktoropenapi.openApi
6+
import io.github.smiley4.ktorredoc.redoc
67
import io.github.smiley4.ktorswaggerui.swaggerUI
78
import io.ktor.http.HttpStatusCode
89
import io.ktor.server.application.Application
@@ -44,15 +45,20 @@ private fun Application.myModule() {
4445

4546
routing {
4647

48+
// Create a route for the openapi-spec file.
49+
// This route will not be included in the spec.
50+
route("api.json") {
51+
openApi()
52+
}
4753
// Create a route for the swagger-ui using the openapi-spec at "/api.json".
4854
// This route will not be included in the spec.
4955
route("swagger") {
5056
swaggerUI("/api.json")
5157
}
52-
// Create a route for the openapi-spec file.
58+
// Create a route for redoc using the openapi-spec at "/api.json".
5359
// This route will not be included in the spec.
54-
route("api.json") {
55-
openApi()
60+
route("redoc") {
61+
redoc("/api.json")
5662
}
5763

5864
// a documented route

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

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

33
import io.github.smiley4.ktoropenapi.OpenApi
44
import io.github.smiley4.ktoropenapi.config.OpenApiPluginConfig
55
import io.github.smiley4.ktoropenapi.config.AuthScheme
66
import io.github.smiley4.ktoropenapi.config.AuthType
77
import io.github.smiley4.ktoropenapi.get
88
import io.github.smiley4.ktoropenapi.openApi
9+
import io.github.smiley4.ktorredoc.redoc
910
import io.github.smiley4.ktorswaggerui.config.SwaggerUISort
1011
import io.github.smiley4.ktorswaggerui.config.SwaggerUISyntaxHighlight
1112
import io.github.smiley4.ktorswaggerui.swaggerUI
@@ -112,7 +113,7 @@ private fun Application.myModule() {
112113
.compileReferencingRoot()
113114
}
114115
overwrite<File>(Schema<Any>().also {
115-
it.types = setOf("string")
116+
it.type = "string"
116117
it.format = "binary"
117118
})
118119
}
@@ -137,7 +138,9 @@ private fun Application.myModule() {
137138

138139
routing {
139140

140-
// add the routes for swagger-ui and api-spec
141+
route("api.json") {
142+
openApi()
143+
}
141144
route("swagger") {
142145
swaggerUI("/api.json") {
143146
displayOperationId = true
@@ -146,9 +149,48 @@ private fun Application.myModule() {
146149
syntaxHighlight = SwaggerUISyntaxHighlight.MONOKAI
147150
withCredentials = false
148151
}
149-
}
150-
route("api.json") {
151-
openApi()
152+
route("redoc") {
153+
redoc("/api.json") {
154+
disableSearch = false
155+
minCharacterLengthToInitSearch = 1
156+
expandResponses = listOf("all")
157+
expandSingleSchemaField = true
158+
hideDownloadButton = false
159+
hideHostname = false
160+
hideLoading = false
161+
hideRequestPayloadSample = true
162+
hideOneOfDescription = false
163+
hideSchemaPattern = false
164+
hideSchemaTitles = true
165+
hideSecuritySection = false
166+
hideSingleRequestSampleTab = true
167+
jsonSampleExpandLevel = "1"
168+
maxDisplayedEnumValues = 3
169+
menuToggle = true
170+
nativeScrollbars = true
171+
onlyRequiredInSamples = false
172+
pathInMiddlePanel = true
173+
requiredPropsFirst = true
174+
schemaExpansionLevel = "all"
175+
showObjectSchemaExamples = true
176+
showWebhookVerb = true
177+
simpleOneOfTypeLabel = true
178+
sortEnumValuesAlphabetically = true
179+
sortOperationsAlphabetically = true
180+
sortPropsAlphabetically = true
181+
sortTagsAlphabetically = true
182+
theme = """
183+
{
184+
"sidebar": {
185+
"backgroundColor": "lightblue"
186+
},
187+
"rightPanel": {
188+
"backgroundColor": "darkblue"
189+
}
190+
}
191+
""".trimIndent()
192+
}
193+
}
152194
}
153195

154196
// a documented route

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
package io.github.smiley4.ktorswaggerui.examples
1+
package io.github.smiley4.ktoropenapi.examples
22

33
import io.github.smiley4.ktoropenapi.OpenApi
44
import io.github.smiley4.ktoropenapi.get
55
import io.github.smiley4.ktoropenapi.openApi
6+
import io.github.smiley4.ktorredoc.redoc
67
import io.github.smiley4.ktorswaggerui.swaggerUI
78
import io.github.smiley4.schemakenerator.serialization.processKotlinxSerialization
89
import io.github.smiley4.schemakenerator.swagger.compileReferencingRoot
@@ -44,16 +45,16 @@ private fun Application.myModule() {
4445

4546
routing {
4647

47-
// Create a route for the swagger-ui using the openapi-spec at "/api.json".
48-
// This route will not be included in the spec.
48+
// add the routes for the api-spec, swagger-ui and redoc
4949
route("swagger") {
5050
swaggerUI("/api.json")
5151
}
52-
// Create a route for the openapi-spec file.
53-
// This route will not be included in the spec.
5452
route("api.json") {
5553
openApi()
5654
}
55+
route("redoc") {
56+
redoc("/api.json")
57+
}
5758

5859
// a documented route
5960
get("hello", {

ktor-swagger-ui-examples/src/main/kotlin/io/github/smiley4/ktorswaggerui/examples/Examples.kt renamed to examples/src/main/kotlin/io/github/smiley4/ktoropenapi/examples/Examples.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
package io.github.smiley4.ktorswaggerui.examples
1+
package io.github.smiley4.ktoropenapi.examples
22

33
import io.github.smiley4.ktoropenapi.OpenApi
44
import io.github.smiley4.ktoropenapi.config.KTypeDescriptor
55
import io.github.smiley4.ktoropenapi.get
66
import io.github.smiley4.ktoropenapi.openApi
7+
import io.github.smiley4.ktorredoc.redoc
78
import io.github.smiley4.ktorswaggerui.swaggerUI
89
import io.ktor.server.application.Application
910
import io.ktor.server.application.install
@@ -52,13 +53,16 @@ private fun Application.myModule() {
5253

5354
routing {
5455

55-
// add the routes for swagger-ui and api-spec
56+
// add the routes for the api-spec, swagger-ui and redoc
5657
route("swagger") {
5758
swaggerUI("/api.json")
5859
}
5960
route("api.json") {
6061
openApi()
6162
}
63+
route("redoc") {
64+
redoc("/api.json")
65+
}
6266

6367

6468
get("basic", {

ktor-swagger-ui-examples/src/main/kotlin/io/github/smiley4/ktorswaggerui/examples/ExternalOpenApiSpec.kt renamed to examples/src/main/kotlin/io/github/smiley4/ktoropenapi/examples/ExternalOpenApiSpec.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
package io.github.smiley4.ktorswaggerui.examples
1+
package io.github.smiley4.ktoropenapi.examples
22

3+
import io.github.smiley4.ktorredoc.redoc
34
import io.github.smiley4.ktorswaggerui.swaggerUI
45
import io.ktor.server.application.Application
56
import io.ktor.server.engine.embeddedServer
@@ -20,6 +21,11 @@ private fun Application.myModule() {
2021
swaggerUI("https://petstore3.swagger.io/api/v3/openapi.json")
2122
}
2223

24+
// Create a route for redoc using an external openapi-spec.
25+
route("redoc") {
26+
redoc("https://petstore3.swagger.io/api/v3/openapi.json")
27+
}
28+
2329
}
2430

2531
}

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

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
package io.github.smiley4.ktorswaggerui.examples
1+
package io.github.smiley4.ktoropenapi.examples
22

33
import io.github.smiley4.ktoropenapi.OpenApi
44
import io.github.smiley4.ktoropenapi.post
55
import io.github.smiley4.ktoropenapi.openApi
6+
import io.github.smiley4.ktorredoc.redoc
67
import io.github.smiley4.ktorswaggerui.swaggerUI
7-
import io.github.smiley4.ktorswaggerui.SwaggerUI
8-
import io.github.smiley4.ktorswaggerui.data.array
9-
import io.github.smiley4.ktorswaggerui.dsl.routing.post
10-
import io.github.smiley4.ktorswaggerui.routing.openApiSpec
11-
import io.github.smiley4.ktorswaggerui.routing.swaggerUI
128
import io.ktor.http.ContentType
139
import io.ktor.http.HttpStatusCode
1410
import io.ktor.server.application.Application
@@ -32,21 +28,24 @@ private fun Application.myModule() {
3228
schemas {
3329
// overwrite type "File" with custom schema for binary data
3430
overwrite<File>(Schema<Any>().also {
35-
it.types = setOf("string")
31+
it.type = "string"
3632
it.format = "binary"
3733
})
3834
}
3935
}
4036

4137
routing {
4238

43-
// add the routes for swagger-ui and api-spec
39+
// add the routes for the api-spec, swagger-ui and redoc
4440
route("swagger") {
4541
swaggerUI("/api.json")
4642
}
4743
route("api.json") {
4844
openApi()
4945
}
46+
route("redoc") {
47+
redoc("/api.json")
48+
}
5049

5150
// upload a single file, either as png, jpeg or svg
5251
post("single", {
@@ -63,7 +62,7 @@ private fun Application.myModule() {
6362
call.respond(HttpStatusCode.NotImplemented, "...")
6463
}
6564

66-
// upload multiple (two) files
65+
// upload multiple files
6766
post("multipart", {
6867
request {
6968
multipartBody {
@@ -88,24 +87,6 @@ private fun Application.myModule() {
8887
call.respond(HttpStatusCode.NotImplemented, "...")
8988
}
9089

91-
// upload multiple (any amount of) files
92-
post("list", {
93-
request {
94-
multipartBody {
95-
mediaTypes(ContentType.MultiPart.FormData)
96-
part("images", array<File>()) {
97-
mediaTypes(
98-
ContentType.Image.PNG,
99-
ContentType.Image.JPEG,
100-
ContentType.Image.SVG
101-
)
102-
}
103-
}
104-
}
105-
}) {
106-
call.respond(HttpStatusCode.NotImplemented, "...")
107-
}
108-
10990
}
11091

11192
}

ktor-swagger-ui-examples/src/main/kotlin/io/github/smiley4/ktorswaggerui/examples/KotlinxSerialization.kt renamed to examples/src/main/kotlin/io/github/smiley4/ktoropenapi/examples/KotlinxSerialization.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
package io.github.smiley4.ktorswaggerui.examples
1+
package io.github.smiley4.ktoropenapi.examples
22

33
import io.github.smiley4.ktoropenapi.OpenApi
44
import io.github.smiley4.ktoropenapi.config.kotlinxExampleEncoder
55
import io.github.smiley4.ktoropenapi.get
66
import io.github.smiley4.ktoropenapi.openApi
7+
import io.github.smiley4.ktorredoc.redoc
78
import io.github.smiley4.ktorswaggerui.swaggerUI
89
import io.github.smiley4.schemakenerator.serialization.processKotlinxSerialization
910
import io.github.smiley4.schemakenerator.swagger.compileReferencingRoot
@@ -46,13 +47,16 @@ private fun Application.myModule() {
4647

4748
routing {
4849

49-
// add the routes for swagger-ui and api-spec
50+
// add the routes for the api-spec, swagger-ui and redoc
5051
route("swagger") {
5152
swaggerUI("/api.json")
5253
}
5354
route("api.json") {
5455
openApi()
5556
}
57+
route("redoc") {
58+
redoc("/api.json")
59+
}
5660

5761
// a documented route
5862
get("hello", {

ktor-swagger-ui-examples/src/main/kotlin/io/github/smiley4/ktorswaggerui/examples/Minimal.kt renamed to examples/src/main/kotlin/io/github/smiley4/ktoropenapi/examples/Minimal.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
package io.github.smiley4.ktorswaggerui.examples
1+
package io.github.smiley4.ktoropenapi.examples
22

33
import io.github.smiley4.ktoropenapi.OpenApi
44
import io.github.smiley4.ktoropenapi.get
55
import io.github.smiley4.ktoropenapi.openApi
6+
import io.github.smiley4.ktorredoc.redoc
67
import io.github.smiley4.ktorswaggerui.swaggerUI
78
import io.ktor.server.application.Application
89
import io.ktor.server.application.install
@@ -23,15 +24,20 @@ private fun Application.myModule() {
2324

2425
routing {
2526

27+
// Create a route for the openapi-spec file.
28+
// This route will not be included in the spec.
29+
route("api.json") {
30+
openApi()
31+
}
2632
// Create a route for the swagger-ui using the openapi-spec at "/api.json".
2733
// This route will not be included in the spec.
2834
route("swagger") {
2935
swaggerUI("/api.json")
3036
}
31-
// Create a route for the openapi-spec file.
37+
// Create a route for redoc using the openapi-spec at "/api.json".
3238
// This route will not be included in the spec.
33-
route("api.json") {
34-
openApi()
39+
route("redoc") {
40+
redoc("/api.json")
3541
}
3642

3743
// a documented route

0 commit comments

Comments
 (0)