-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
160 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,9 +94,6 @@ private fun Application.myModule() { | |
call.respondText("Hello World!") | ||
} | ||
|
||
|
||
|
||
|
||
} | ||
|
||
} |
3 changes: 0 additions & 3 deletions
3
...ger-ui-examples/src/main/kotlin/io/github/smiley4/ktorswaggerui/examples/CustomSchemas.kt
This file was deleted.
Oops, something went wrong.
113 changes: 113 additions & 0 deletions
113
...-swagger-ui-examples/src/main/kotlin/io/github/smiley4/ktorswaggerui/examples/Examples.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package io.github.smiley4.ktorswaggerui.examples | ||
|
||
import io.github.smiley4.ktorswaggerui.SwaggerUI | ||
import io.github.smiley4.ktorswaggerui.data.KTypeDescriptor | ||
import io.github.smiley4.ktorswaggerui.data.RefExampleDescriptor | ||
import io.github.smiley4.ktorswaggerui.data.ValueExampleDescriptor | ||
import io.github.smiley4.ktorswaggerui.dsl.routing.get | ||
import io.github.smiley4.ktorswaggerui.routing.openApiSpec | ||
import io.github.smiley4.ktorswaggerui.routing.swaggerUI | ||
import io.ktor.server.application.Application | ||
import io.ktor.server.application.call | ||
import io.ktor.server.application.install | ||
import io.ktor.server.engine.embeddedServer | ||
import io.ktor.server.netty.Netty | ||
import io.ktor.server.response.respondText | ||
import io.ktor.server.routing.route | ||
import io.ktor.server.routing.routing | ||
import kotlin.reflect.typeOf | ||
|
||
fun main() { | ||
embeddedServer(Netty, port = 8080, host = "localhost", module = Application::myModule).start(wait = true) | ||
} | ||
|
||
private fun Application.myModule() { | ||
|
||
// Install and customize the "SwaggerUI"-Plugin | ||
install(SwaggerUI) { | ||
examples { | ||
|
||
// specify two shared examples | ||
example(ValueExampleDescriptor( | ||
name = "Shared A", | ||
description = "first shared example", | ||
value = MyExampleClass( | ||
someValue = "shared a" | ||
) | ||
)) | ||
example(ValueExampleDescriptor( | ||
name = "Shared B", | ||
description = "second shared example", | ||
value = MyExampleClass( | ||
someValue = "shared b" | ||
) | ||
)) | ||
|
||
} | ||
} | ||
|
||
routing { | ||
|
||
// add the routes for swagger-ui and api-spec | ||
route("swagger") { | ||
swaggerUI("/api.json") | ||
} | ||
route("api.json") { | ||
openApiSpec() | ||
} | ||
|
||
|
||
get("basic", { | ||
request { | ||
body(KTypeDescriptor(typeOf<MyExampleClass>())) { | ||
// specify two example values | ||
example( | ||
ValueExampleDescriptor( | ||
name = "Example 1", | ||
description = "A first example value", | ||
value = MyExampleClass( | ||
someValue = "example 1" | ||
), | ||
) | ||
) | ||
example( | ||
ValueExampleDescriptor( | ||
name = "Example 2", | ||
description = "A second example value", | ||
value = MyExampleClass( | ||
someValue = "example 2" | ||
), | ||
) | ||
) | ||
} | ||
} | ||
}) { | ||
call.respondText("...") | ||
} | ||
|
||
|
||
get("reference-shared", { | ||
request { | ||
body(KTypeDescriptor(typeOf<MyExampleClass>())) { | ||
// reference two shared examples specified in the plugin-config (and placed in the component section) | ||
example( | ||
RefExampleDescriptor("Example 1", "Shared A") | ||
) | ||
example( | ||
RefExampleDescriptor("Example 2", "Shared B") | ||
) | ||
} | ||
} | ||
}) { | ||
call.respondText("...") | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
|
||
private data class MyExampleClass( | ||
val someValue: String | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
...-examples/src/main/kotlin/io/github/smiley4/ktorswaggerui/examples/SchemaCostomization.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
ktor-swagger-ui/src/main/kotlin/io/github/smiley4/ktorswaggerui/data/ExampleConfigData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.