chore: docs
This commit is contained in:
@ -36,10 +36,12 @@ custom type overrides (typically useful for custom scalars such as dates and tim
|
|||||||
```kotlin
|
```kotlin
|
||||||
private fun Application.mainModule() {
|
private fun Application.mainModule() {
|
||||||
install(NotarizedApplication()) {
|
install(NotarizedApplication()) {
|
||||||
spec = OpenApiSpec(
|
spec = {
|
||||||
|
OpenApiSpec(
|
||||||
// ...
|
// ...
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -20,13 +20,25 @@ reference [OpenAPI spec](https://spec.openapis.org/oas/v3.1.0) itself.
|
|||||||
For public facing APIs, having the default endpoint exposed at `/openapi.json` is totally fine. However, if you need
|
For public facing APIs, having the default endpoint exposed at `/openapi.json` is totally fine. However, if you need
|
||||||
more granular control over the route that exposes the generated schema, you can modify the `openApiJson` config value.
|
more granular control over the route that exposes the generated schema, you can modify the `openApiJson` config value.
|
||||||
|
|
||||||
For example, if we want to hide our schema behind a basic auth check, we could do the following
|
For example, if we want to hide our schema behind a basic auth check with a custom json encoder, we could do the following
|
||||||
|
|
||||||
```kotlin
|
```kotlin
|
||||||
private fun Application.mainModule() {
|
private fun Application.mainModule() {
|
||||||
// Install content negotiation, auth, etc...
|
// Install content negotiation, auth, etc...
|
||||||
install(NotarizedApplication()) {
|
install(NotarizedApplication()) {
|
||||||
// ...
|
// ...
|
||||||
|
specRoute = { spec, routing ->
|
||||||
|
routing {
|
||||||
|
authenticate("basic") {
|
||||||
|
route("/openapi.json") {
|
||||||
|
get {
|
||||||
|
call.response.headers.append("Content-Type", "application/json")
|
||||||
|
call.respondText { CustomJsonEncoder.encodeToString(spec) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
openApiJson = {
|
openApiJson = {
|
||||||
authenticate("basic") {
|
authenticate("basic") {
|
||||||
route("/openapi.json") {
|
route("/openapi.json") {
|
||||||
@ -81,25 +93,9 @@ application.
|
|||||||
|
|
||||||
## Schema Configurator
|
## Schema Configurator
|
||||||
|
|
||||||
The `SchemaConfigurator` is an interface that allows users to bridge the gap between Kompendium serialization and custom
|
Out of the box, Kompendium supports KotlinX serialization... however, in order to allow for users of other
|
||||||
serialization strategies that the serializer they are using for their API. For example, if you are using KotlinX
|
serialization libraries to use Kompendium, we have provided a `SchemaConfigurator` interface that allows you to
|
||||||
serialization in order to convert kotlin fields from camel case to snake case, you could leverage
|
configure how Kompendium will generate schema definitions.
|
||||||
the `KotlinXSchemaConfigurator` in order to instruct Kompendium on how to serialize values properly.
|
|
||||||
|
|
||||||
```kotlin
|
For an example of the `SchemaConfigurator` in action, please see the `KotlinxSchemaConfigurator`. This will give you
|
||||||
private fun Application.mainModule() {
|
a good idea of the additional functionality it can add based on your own serialization needs.
|
||||||
install(ContentNegotiation) {
|
|
||||||
json(Json {
|
|
||||||
serializersModule = KompendiumSerializersModule.module
|
|
||||||
encodeDefaults = true
|
|
||||||
explicitNulls = false
|
|
||||||
})
|
|
||||||
}
|
|
||||||
install(NotarizedApplication()) {
|
|
||||||
spec = baseSpec
|
|
||||||
// Adds support for @Transient and @SerialName
|
|
||||||
// If you are not using them this is not required.
|
|
||||||
schemaConfigurator = KotlinXSchemaConfigurator()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
@ -23,7 +23,7 @@ level plugin, and **must** be install after both the `NotarizedApplication` plug
|
|||||||
private fun Application.mainModule() {
|
private fun Application.mainModule() {
|
||||||
install(Locations)
|
install(Locations)
|
||||||
install(NotarizedApplication()) {
|
install(NotarizedApplication()) {
|
||||||
spec = baseSpec
|
spec = { baseSpec }
|
||||||
}
|
}
|
||||||
install(NotarizedLocations()) {
|
install(NotarizedLocations()) {
|
||||||
locations = mapOf(
|
locations = mapOf(
|
||||||
|
@ -30,7 +30,7 @@ application in a single block.
|
|||||||
private fun Application.mainModule() {
|
private fun Application.mainModule() {
|
||||||
install(Resources)
|
install(Resources)
|
||||||
install(NotarizedApplication()) {
|
install(NotarizedApplication()) {
|
||||||
spec = baseSpec
|
spec = { baseSpec }
|
||||||
}
|
}
|
||||||
install(NotarizedResources()) {
|
install(NotarizedResources()) {
|
||||||
resources = mapOf(
|
resources = mapOf(
|
||||||
|
Reference in New Issue
Block a user