major: ktor 3.0.0 support - fixes #644 (#645)

This commit is contained in:
knmueller
2024-10-30 16:21:46 -04:00
committed by GitHub
parent fa7b1e5833
commit 21f922a296
44 changed files with 151 additions and 777 deletions

View File

@ -4,7 +4,6 @@
* [Plugins](plugins/index.md)
* [Notarized Application](plugins/notarized_application.md)
* [Notarized Route](plugins/notarized_route.md)
* [Notarized Locations](plugins/notarized_locations.md)
* [Notarized Resources](plugins/notarized_resources.md)
* [Concepts](concepts/index.md)
* [Enrichment](concepts/enrichment.md)

View File

@ -12,7 +12,6 @@ At the moment, the following playground applications are
| Gson | Serialization using Gson instead of the default Kotlinx |
| Hidden Docs | Place your generated documentation behind authorization |
| Jackson | Serialization using Jackson instead of the default KotlinX |
| Locations | Using the Ktor Locations API to define routes |
| Resources | Using the Ktor Resources API to define routes |
You can find all of the playground

View File

@ -7,5 +7,5 @@ From there, a `NotarizedRoute` plugin is attached to each route you wish to docu
be an iterative process. Each route you notarize will be picked up and injected into the OpenAPI spec that Kompendium
generates for you.
Finally, there is the `NotarizedLocations` plugin that allows you to leverage and document your usage of the
Ktor [Locations](https://ktor.io/docs/locations.html) API.
Finally, there is the `NotarizedResources` plugin that allows you to leverage and document your usage of the
Ktor [Resources](https://ktor.io/docs/server-resources.html) API.

View File

@ -1,62 +0,0 @@
The Ktor Locations API is an experimental API that allows users to add increased type safety to their defined routes.
You can read more about it [here](https://ktor.io/docs/locations.html).
Kompendium supports Locations through an ancillary module `kompendium-locations`
## Adding the Artifact
Prior to documenting your locations, you will need to add the artifact to your gradle build file.
```kotlin
dependencies {
implementation("io.bkbn:kompendium-locations:latest.release")
}
```
## Installing Plugin
Once you have installed the dependency, you can install the plugin. The `NotarizedLocations` plugin is an _application_
level plugin, and **must** be install after both the `NotarizedApplication` plugin and the Ktor `Locations` plugin.
```kotlin
private fun Application.mainModule() {
install(Locations)
install(NotarizedApplication()) {
spec = baseSpec
}
install(NotarizedLocations()) {
locations = mapOf(
Listing::class to NotarizedLocations.LocationMetadata(
parameters = listOf(
Parameter(
name = "name",
`in` = Parameter.Location.path,
schema = TypeDefinition.STRING
),
Parameter(
name = "page",
`in` = Parameter.Location.path,
schema = TypeDefinition.INT
)
),
get = GetInfo.builder {
summary("Get user by id")
description("A very neat endpoint!")
response {
responseCode(HttpStatusCode.OK)
responseType<ExampleResponse>()
description("Will return whether or not the user is real 😱")
}
}
),
)
}
}
```
Here, the `locations` property is a map of `KClass<*>` to metadata describing that locations metadata. This
metadata is functionally identical to how a standard `NotarizedRoute` is defined.
> ⚠️ If you try to map a class that is not annotated with the ktor `@Location` annotation, you will get a runtime
> exception!