-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(doc): add notes about previous repositories
- Loading branch information
1 parent
91ebe9b
commit b9696c6
Showing
4 changed files
with
55 additions
and
4 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,51 @@ | ||
# Ktor OpenAPI Generator | ||
|
||
Hosted on different repository: https://github.com/LukasForst/ktor-openapi-generator/ | ||
Hosted on different | ||
repository: [LukasForst/ktor-openapi-generator](https://github.com/LukasForst/ktor-openapi-generator/). | ||
|
||
## Minimal example | ||
|
||
```kotlin | ||
/** | ||
* Minimal example of OpenAPI plugin for Ktor. | ||
*/ | ||
fun Application.minimalExample() { | ||
// install OpenAPI plugin | ||
install(OpenAPIGen) { | ||
// this automatically servers Swagger UI on /swagger-ui | ||
serveSwaggerUi = true | ||
info { | ||
title = "Minimal Example API" | ||
} | ||
} | ||
// install JSON support | ||
install(ContentNegotiation) { | ||
jackson() | ||
} | ||
// add basic routes for openapi.json and redirect to UI | ||
routing { | ||
// serve openapi.json | ||
get("/openapi.json") { | ||
call.respond(this@routing.application.openAPIGen.api.serialize()) | ||
} | ||
// and do redirect to make it easier to remember | ||
get("/swagger-ui") { | ||
call.respondRedirect("/swagger-ui/index.html?url=/openapi.json", true) | ||
} | ||
} | ||
// and now example routing | ||
apiRouting { | ||
route("/example/{name}") { | ||
// SomeParams are parameters (query or path), SomeResponse is what the backend returns and SomeRequest | ||
// is what was passed in the body of the request | ||
post<SomeParams, SomeResponse, SomeRequest> { params, someRequest -> | ||
respond(SomeResponse(bar = "Hello ${params.name}! From body: ${someRequest.foo}.")) | ||
} | ||
} | ||
} | ||
} | ||
|
||
data class SomeParams(@PathParam("who to say hello") val name: String) | ||
data class SomeRequest(val foo: String) | ||
data class SomeResponse(val bar: 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