Skip to content

Commit

Permalink
add redoc support
Browse files Browse the repository at this point in the history
  • Loading branch information
SMILEY4 committed Jan 15, 2025
1 parent b5b9b38 commit f9c7429
Show file tree
Hide file tree
Showing 29 changed files with 686 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ repositories {
}

dependencies {
implementation(project(":ktor-swagger-ui"))
implementation(project(":ktor-openapi"))
implementation(project(":ktor-swagger-ui"))
implementation(project(":ktor-redoc"))

val versionKtor: String by project
implementation("io.ktor:ktor-server-netty-jvm:$versionKtor")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package io.github.smiley4.ktorswaggerui.examples
package io.github.smiley4.ktoropenapi.examples

import io.github.smiley4.ktoropenapi.OpenApi
import io.github.smiley4.ktoropenapi.config.AuthScheme
import io.github.smiley4.ktoropenapi.config.AuthType
import io.github.smiley4.ktoropenapi.get
import io.github.smiley4.ktoropenapi.openApi
import io.github.smiley4.ktorredoc.redoc
import io.github.smiley4.ktorswaggerui.swaggerUI
import io.ktor.server.application.Application
import io.ktor.server.application.install
Expand Down Expand Up @@ -60,13 +61,16 @@ private fun Application.myModule() {

routing {

// add the routes for swagger-ui and api-spec
// add the routes for the api-spec, swagger-ui and redoc
route("swagger") {
swaggerUI("/api.json")
}
route("api.json") {
openApi()
}
route("redoc") {
redoc("/api.json")
}

authenticate {
// route is in an "authenticate"-block -> default security-scheme will be used (if not specified otherwise)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package io.github.smiley4.ktorswaggerui.examples
package io.github.smiley4.ktoropenapi.examples

import io.github.smiley4.ktoropenapi.OpenApi
import io.github.smiley4.ktoropenapi.get
import io.github.smiley4.ktoropenapi.openApi
import io.github.smiley4.ktorredoc.redoc
import io.github.smiley4.ktorswaggerui.swaggerUI
import io.ktor.http.HttpStatusCode
import io.ktor.server.application.Application
Expand Down Expand Up @@ -44,15 +45,20 @@ private fun Application.myModule() {

routing {

// Create a route for the openapi-spec file.
// This route will not be included in the spec.
route("api.json") {
openApi()
}
// Create a route for the swagger-ui using the openapi-spec at "/api.json".
// This route will not be included in the spec.
route("swagger") {
swaggerUI("/api.json")
}
// Create a route for the openapi-spec file.
// Create a route for redoc using the openapi-spec at "/api.json".
// This route will not be included in the spec.
route("api.json") {
openApi()
route("redoc") {
redoc("/api.json")
}

// a documented route
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package io.github.smiley4.ktorswaggerui.examples
package io.github.smiley4.ktoropenapi.examples

import io.github.smiley4.ktoropenapi.OpenApi
import io.github.smiley4.ktoropenapi.config.OpenApiPluginConfig
import io.github.smiley4.ktoropenapi.config.AuthScheme
import io.github.smiley4.ktoropenapi.config.AuthType
import io.github.smiley4.ktoropenapi.get
import io.github.smiley4.ktoropenapi.openApi
import io.github.smiley4.ktorredoc.redoc
import io.github.smiley4.ktorswaggerui.config.SwaggerUISort
import io.github.smiley4.ktorswaggerui.config.SwaggerUISyntaxHighlight
import io.github.smiley4.ktorswaggerui.swaggerUI
Expand Down Expand Up @@ -112,7 +113,7 @@ private fun Application.myModule() {
.compileReferencingRoot()
}
overwrite<File>(Schema<Any>().also {
it.types = setOf("string")
it.type = "string"
it.format = "binary"
})
}
Expand All @@ -137,7 +138,9 @@ private fun Application.myModule() {

routing {

// add the routes for swagger-ui and api-spec
route("api.json") {
openApi()
}
route("swagger") {
swaggerUI("/api.json") {
displayOperationId = true
Expand All @@ -146,9 +149,48 @@ private fun Application.myModule() {
syntaxHighlight = SwaggerUISyntaxHighlight.MONOKAI
withCredentials = false
}
}
route("api.json") {
openApi()
route("redoc") {
redoc("/api.json") {
disableSearch = false
minCharacterLengthToInitSearch = 1
expandResponses = listOf("all")
expandSingleSchemaField = true
hideDownloadButton = false
hideHostname = false
hideLoading = false
hideRequestPayloadSample = true
hideOneOfDescription = false
hideSchemaPattern = false
hideSchemaTitles = true
hideSecuritySection = false
hideSingleRequestSampleTab = true
jsonSampleExpandLevel = "1"
maxDisplayedEnumValues = 3
menuToggle = true
nativeScrollbars = true
onlyRequiredInSamples = false
pathInMiddlePanel = true
requiredPropsFirst = true
schemaExpansionLevel = "all"
showObjectSchemaExamples = true
showWebhookVerb = true
simpleOneOfTypeLabel = true
sortEnumValuesAlphabetically = true
sortOperationsAlphabetically = true
sortPropsAlphabetically = true
sortTagsAlphabetically = true
theme = """
{
"sidebar": {
"backgroundColor": "lightblue"
},
"rightPanel": {
"backgroundColor": "darkblue"
}
}
""".trimIndent()
}
}
}

// a documented route
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package io.github.smiley4.ktorswaggerui.examples
package io.github.smiley4.ktoropenapi.examples

import io.github.smiley4.ktoropenapi.OpenApi
import io.github.smiley4.ktoropenapi.get
import io.github.smiley4.ktoropenapi.openApi
import io.github.smiley4.ktorredoc.redoc
import io.github.smiley4.ktorswaggerui.swaggerUI
import io.github.smiley4.schemakenerator.serialization.processKotlinxSerialization
import io.github.smiley4.schemakenerator.swagger.compileReferencingRoot
Expand Down Expand Up @@ -44,16 +45,16 @@ private fun Application.myModule() {

routing {

// Create a route for the swagger-ui using the openapi-spec at "/api.json".
// This route will not be included in the spec.
// add the routes for the api-spec, swagger-ui and redoc
route("swagger") {
swaggerUI("/api.json")
}
// Create a route for the openapi-spec file.
// This route will not be included in the spec.
route("api.json") {
openApi()
}
route("redoc") {
redoc("/api.json")
}

// a documented route
get("hello", {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package io.github.smiley4.ktorswaggerui.examples
package io.github.smiley4.ktoropenapi.examples

import io.github.smiley4.ktoropenapi.OpenApi
import io.github.smiley4.ktoropenapi.config.KTypeDescriptor
import io.github.smiley4.ktoropenapi.get
import io.github.smiley4.ktoropenapi.openApi
import io.github.smiley4.ktorredoc.redoc
import io.github.smiley4.ktorswaggerui.swaggerUI
import io.ktor.server.application.Application
import io.ktor.server.application.install
Expand Down Expand Up @@ -52,13 +53,16 @@ private fun Application.myModule() {

routing {

// add the routes for swagger-ui and api-spec
// add the routes for the api-spec, swagger-ui and redoc
route("swagger") {
swaggerUI("/api.json")
}
route("api.json") {
openApi()
}
route("redoc") {
redoc("/api.json")
}


get("basic", {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.smiley4.ktorswaggerui.examples
package io.github.smiley4.ktoropenapi.examples

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

// Create a route for redoc using an external openapi-spec.
route("redoc") {
redoc("https://petstore3.swagger.io/api/v3/openapi.json")
}

}

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package io.github.smiley4.ktorswaggerui.examples
package io.github.smiley4.ktoropenapi.examples

import io.github.smiley4.ktoropenapi.OpenApi
import io.github.smiley4.ktoropenapi.post
import io.github.smiley4.ktoropenapi.openApi
import io.github.smiley4.ktorredoc.redoc
import io.github.smiley4.ktorswaggerui.swaggerUI
import io.github.smiley4.ktorswaggerui.SwaggerUI
import io.github.smiley4.ktorswaggerui.data.array
import io.github.smiley4.ktorswaggerui.dsl.routing.post
import io.github.smiley4.ktorswaggerui.routing.openApiSpec
import io.github.smiley4.ktorswaggerui.routing.swaggerUI
import io.ktor.http.ContentType
import io.ktor.http.HttpStatusCode
import io.ktor.server.application.Application
Expand All @@ -32,21 +28,24 @@ private fun Application.myModule() {
schemas {
// overwrite type "File" with custom schema for binary data
overwrite<File>(Schema<Any>().also {
it.types = setOf("string")
it.type = "string"
it.format = "binary"
})
}
}

routing {

// add the routes for swagger-ui and api-spec
// add the routes for the api-spec, swagger-ui and redoc
route("swagger") {
swaggerUI("/api.json")
}
route("api.json") {
openApi()
}
route("redoc") {
redoc("/api.json")
}

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

// upload multiple (two) files
// upload multiple files
post("multipart", {
request {
multipartBody {
Expand All @@ -88,24 +87,6 @@ private fun Application.myModule() {
call.respond(HttpStatusCode.NotImplemented, "...")
}

// upload multiple (any amount of) files
post("list", {
request {
multipartBody {
mediaTypes(ContentType.MultiPart.FormData)
part("images", array<File>()) {
mediaTypes(
ContentType.Image.PNG,
ContentType.Image.JPEG,
ContentType.Image.SVG
)
}
}
}
}) {
call.respond(HttpStatusCode.NotImplemented, "...")
}

}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package io.github.smiley4.ktorswaggerui.examples
package io.github.smiley4.ktoropenapi.examples

import io.github.smiley4.ktoropenapi.OpenApi
import io.github.smiley4.ktoropenapi.config.kotlinxExampleEncoder
import io.github.smiley4.ktoropenapi.get
import io.github.smiley4.ktoropenapi.openApi
import io.github.smiley4.ktorredoc.redoc
import io.github.smiley4.ktorswaggerui.swaggerUI
import io.github.smiley4.schemakenerator.serialization.processKotlinxSerialization
import io.github.smiley4.schemakenerator.swagger.compileReferencingRoot
Expand Down Expand Up @@ -46,13 +47,16 @@ private fun Application.myModule() {

routing {

// add the routes for swagger-ui and api-spec
// add the routes for the api-spec, swagger-ui and redoc
route("swagger") {
swaggerUI("/api.json")
}
route("api.json") {
openApi()
}
route("redoc") {
redoc("/api.json")
}

// a documented route
get("hello", {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package io.github.smiley4.ktorswaggerui.examples
package io.github.smiley4.ktoropenapi.examples

import io.github.smiley4.ktoropenapi.OpenApi
import io.github.smiley4.ktoropenapi.get
import io.github.smiley4.ktoropenapi.openApi
import io.github.smiley4.ktorredoc.redoc
import io.github.smiley4.ktorswaggerui.swaggerUI
import io.ktor.server.application.Application
import io.ktor.server.application.install
Expand All @@ -23,15 +24,20 @@ private fun Application.myModule() {

routing {

// Create a route for the openapi-spec file.
// This route will not be included in the spec.
route("api.json") {
openApi()
}
// Create a route for the swagger-ui using the openapi-spec at "/api.json".
// This route will not be included in the spec.
route("swagger") {
swaggerUI("/api.json")
}
// Create a route for the openapi-spec file.
// Create a route for redoc using the openapi-spec at "/api.json".
// This route will not be included in the spec.
route("api.json") {
openApi()
route("redoc") {
redoc("/api.json")
}

// a documented route
Expand Down
Loading

0 comments on commit f9c7429

Please sign in to comment.