Skip to content
This repository was archived by the owner on Mar 31, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this project will be documented in this file.

## [Unreleased]

- Add support for method type NotarizedResource (#704)

## [4.0.3] - 2024-11-11

### 🐛 Bug Fixes
Expand Down
21 changes: 11 additions & 10 deletions docs/playground.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ Kompendium features.

At the moment, the following playground applications are

| Example | Description |
|--------------|------------------------------------------------------------|
| Basic | A minimally viable Kompendium application |
| Auth | Documenting authenticated routes |
| Custom Types | Documenting custom scalars to be used by Kompendium |
| Exceptions | Documenting exception responses |
| 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 |
| Resources | Using the Ktor Resources API to define routes |
| Example | Description |
|--------------|-------------------------------------------------------------------------------------------------------------|
| Basic | A minimally viable Kompendium application |
| Auth | Documenting authenticated routes |
| Custom Types | Documenting custom scalars to be used by Kompendium |
| Exceptions | Documenting exception responses |
| 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 |
| Resources | Using the Ktor Resources API to define routes |
| Resources v2 | Using the Ktor Resources API to define routes and use method type NotarizedResources to document the routes |

You can find all of the playground
examples [here](https://github.com/bkbnio/kompendium/tree/main/playground/src/main/kotlin/io/bkbn/kompendium/playground)
Expand Down
68 changes: 68 additions & 0 deletions docs/plugins/notarized_resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,71 @@ resource.
{% hint style="danger" %}
If you try to map a class that is not annotated with the ktor `@Resource` annotation, you will get a runtime exception!
{% endhint %}

## NotarizedResource (method typed)

If you prefer a more fine granular route-based approach similar to NotarizedResource<MyResourceType>(), you can use one of the following method typed NotarizedResources:
- `NotarizedGetResource`
- `NotarizedPostResource`
- `NotarizedPutResource`
- `NotarizedDeleteResource`
- `NotarizedHeadResource`
- `NotarizedPatchResource`
- `NotarizedOptionsResource`

```kotlin
@Resource("/users")
class Users

private fun Application.mainModule() {
install(Resources)
route("/api") {
listUserRoute()
createUserRoute()
}
}

fun Route.listUserRoute() {
listUserDocumentation()

get<Users> {
call.respondText("List user")
}
}

private fun Route.listUserDocumentation() {
install(NotarizedGetResource<Users>()) {
get = GetInfo.builder {
summary("List users")
description("List all users")
response {
responseCode(HttpStatusCode.OK)
responseType<String>()
description("List of users")
}
}
}
}

fun Route.createUserRoute() {
createUserDocumentation()

post<Users> {
call.respondText("Successfully created user", status = HttpStatusCode.Created)
}
}

private fun Route.createUserDocumentation() {
install(NotarizedPostResource<Users>()) {
post = PostInfo.builder {
summary("Create user")
description("Create a new user")
response {
responseCode(HttpStatusCode.Created)
responseType<String>()
description("User created")
}
}
}
}
```
Loading