Skip to content

Commit 42b1c3e

Browse files
committed
refine, link and fix documentation
1 parent 97619f7 commit 42b1c3e

32 files changed

+707
-491
lines changed

docs/assets/stylesheets/extra.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,16 @@ details code {
1616
border-radius: .2rem !important;
1717
padding: 0 .3rem .3rem .3rem !important;
1818
}
19+
}
20+
21+
.md-typeset h2 {
22+
margin: 2.5em 0 .64em;
23+
}
24+
25+
.md-typeset h2 {
26+
margin: 2.6em 0 .64em;
27+
}
28+
29+
.md-typeset h3 {
30+
margin-top: 1.2em;
1931
}

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Designed to be non-invasive, they integrate seamlessly with applications without
2121

2222
Add documentation to Ktor routes and automatically generate [OpenAPI](https://www.openapis.org/) specifications.
2323

24-
[:octicons-arrow-right-24: Get Started](openapi/index.md)
24+
[:octicons-arrow-right-24: Get Started](./openapi/getting_started.md)
2525

2626

2727
- :simple-swagger:{ .lg .middle } __Swagger UI__
Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# Documenting SSE Routes
22

3-
Server-Sent Events (SSE) routes can be documented for discoverability in the OpenAPI specification. While SSE functionality works normally in Ktor, documentation is achieved by wrapping SSE routes in a documented parent route.
3+
Server-Sent Events (SSE) routes can be documented for discoverability in the OpenAPI specification.
4+
While SSE functionality works normally in Ktor, documentation is achieved by wrapping SSE routes in a documented parent route.
45

5-
??? warning "Limited OpenAPI Support"
6+
!!! warning "Limited OpenAPI Support"
67

7-
**Important:** OpenAPI has limited support for Server-Sent Events. The specification does not officially define SSE endpoints, so not all documentation features work as expected or may not render correctly in documentation UIs.
8-
9-
SSE documentation is primarily for discoverability and basic information. Advanced SSE features (event types, reconnection behavior, stream format) are not well-represented in OpenAPI.
8+
OpenAPI has limited support for Server-Sent Events. The specification does not officially define SSE endpoints,
9+
so not all documentation features work as expected or may not render correctly in documentation UIs.
10+
11+
SSE documentation is primarily for discoverability and basic information. Advanced SSE features (event types, reconnection behavior,
12+
stream format) are not well-represented in OpenAPI.
1013

1114

1215
## Describing SSE-Routes
@@ -21,10 +24,13 @@ route({
2124
tags = listOf("events", "sse")
2225
}) {
2326
sse("/events") {
24-
// SSE implementation
2527
send(ServerSentEvent(data = "Hello"))
2628
}
2729
}
2830
```
2931

30-
All standard route documentation options are (theoretically) available. See [Basic Route Documentation]() for complete documentation options.
32+
??? info "More Information"
33+
34+
All standard route documentation options are available (in theory). For more information, see:
35+
36+
[:octicons-arrow-right-24: Basic Route Documentation](./../documenting_routes/basic_route_documentation.md)

docs/openapi/advanced_topics/documenting_webhooks.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# Documenting Webhooks
22

3-
Webhooks are HTTP callbacks that your API sends to external systems. While webhooks are not part of your server's request handling, they can be documented in the OpenAPI specification to help API consumers understand what data your API will send to their endpoints.
3+
Webhooks are HTTP callbacks that your API sends to external systems. While webhooks are not part of your server's request handling,
4+
they can be documented in the OpenAPI specification to help API consumers understand what data your API will send to their endpoints.
45

5-
??? warning "Documentation Only"
6+
!!! warning "Documentation Only"
67

7-
**Important:** Webhook documentation is purely informational. It does not create callable Ktor routes and has no impact on your application's routing or request handling.
8-
9-
Webhooks appear only in the generated OpenAPI specification under the `webhooks` section. They document HTTP requests your API makes to external systems, not requests it receives.
8+
Webhook documentation is purely informational. It does not create callable Ktor routes and has no impact on your application's routing or request handling.
9+
10+
Webhooks appear only in the generated OpenAPI specification under the `webhooks` section. They document HTTP requests your API makes to external systems, not requests it receives.
1011

1112
## Describing Webhooks
1213

@@ -33,4 +34,8 @@ Parameters:
3334
- httpMethod: HTTP method for the webhook (typically HttpMethod.Post)
3435
- eventName: Unique identifier for the webhook event (e.g., "newOrder", "userCreated")
3536

36-
All standard route documentation options are available. See [Basic Route Documentation]() for complete documentation options.
37+
??? info "More Information"
38+
39+
All standard route documentation options are available. For more information, see:
40+
41+
[:octicons-arrow-right-24: Basic Route Documentation](./../documenting_routes/basic_route_documentation.md)

docs/openapi/advanced_topics/multiple_openapi_specifications.md

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
# Multiple API Specifications
22

3-
The OpenAPI plugin supports generating multiple independent specifications from a single application. This enables API versioning, separation of internal and external APIs, or organizing endpoints by product or team.
3+
The OpenAPI plugin supports generating multiple independent specifications from a single application.
4+
This enables API versioning, separation of internal and external APIs, or organizing endpoints by product or team.
5+
6+
Each specification has a unique identifier, its own configuration, and contains only the routes assigned to it.
7+
Specifications are generated and served independently.
8+
9+
410

5-
Each specification has a unique identifier, its own configuration, and contains only the routes assigned to it. Specifications are generated and served independently.
611

712
## Configuring Specifications
813

@@ -12,33 +17,36 @@ All configuration options available in the base plugin config are available for
1217

1318
```kotlin
1419
install(OpenApi) {
15-
// Base configuration for all specifications
16-
info {
20+
info { // (1)!
1721
title = "My API"
1822
}
19-
20-
// Define specification "v1"
21-
spec("v1") {
23+
spec("v1") { // (2)!
2224
info {
2325
version = "1.0.0"
2426
}
2527
}
26-
27-
// Define specification "v2"
28-
spec("v2") {
28+
spec("v2") { // (3)!
2929
info {
3030
version = "2.0.0"
3131
}
3232
}
3333
}
3434
```
3535

36+
1. Base configuration for all specifications
37+
2. Define and configure specification with identifier "v1"
38+
3. Define and configure specification with identifier "v2"
39+
3640
Each specification is identified by a unique string (e.g., "v1", "v2", "internal").
3741

42+
43+
44+
3845
## Assigning Routes to Specifications
3946

4047
Routes must be assigned to specifications to appear in them. Assignment can be done explicitly in route documentation or automatically via an assigner function.
4148

49+
4250
### Assignment at Route Documentation
4351

4452
The `specName` property assigns a route to a specific specification:
@@ -54,16 +62,19 @@ Routes can be easily assigned in groups by adding the `specName` at a parent rou
5462

5563
```kotlin
5664
route("v1", {
57-
specName = "v1" // All child routes assigned to v1
65+
specName = "v1" // (1)!
5866
}) {
5967
get("users") { }
6068
get("products") { }
6169
get("orders") { }
6270
}
6371
```
6472

73+
1. All child routes are assigned to "v1".
74+
6575
All routes within this block are automatically assigned to the "v1" specification through inheritance.
6676

77+
6778
### Assignment via Assigner Function
6879

6980
Routes can be automatically assigned based on their properties using an assigner function:
@@ -88,34 +99,41 @@ The function receives:
8899

89100
The function returns the specification identifier to assign the route to.
90101

102+
91103
### Unassigned Routes
92104

93-
Routes without an assignment are assigned to the default specification with the identifier `OpenApiPluginConfig.DEFAULT_SPEC_ID`. The default specification only exists if any routes are assigned to it.
105+
Routes without an assignment are assigned to the default specification with the identifier `OpenApiPluginConfig.DEFAULT_SPEC_ID`.
106+
The default specification only exists if any routes are assigned to it.
107+
108+
109+
94110

95111
## Serving Multiple Specifications
96112

97113
Each specification is served independently via HTTP routes.
98114

99115
```kotlin
100116
routing {
101-
// v1 specification
102-
route("v1/api.json") {
117+
route("v1/api.json") { // (1)!
103118
openApi("v1")
104119
}
105-
106-
// v2 specification
107-
route("v2/api.json") {
120+
route("v2/api.json") { // (2)!
108121
openApi("v2")
109122
}
110-
111-
// Internal specification
112-
route("internal/api.json") {
123+
route("internal/api.json") { // (3)!
113124
openApi("internal")
114125
}
115126
}
116127
```
117128

118-
More information on how to handle multiple specifications in UIs:
129+
1. Expose v1 specification.
130+
2. Expose v2 specification.
131+
3. Expose internal specification.
132+
133+
??? info "Multiple Specifications with Swagger UI and Redoc"
134+
135+
More information on how to handle multiple specifications with documentation UIs:
136+
137+
[:octicons-arrow-right-24: Swagger UI](./../../swaggerui/getting_started.md)
119138

120-
- with [Swagger UI]()
121-
- with [ReDoc]()
139+
[:octicons-arrow-right-24: ReDoc](./../../redoc/getting_started.md)

docs/openapi/advanced_topics/typesafe_routing_support.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
# Type-Safe Routing Support
22

3-
The OpenAPI plugin supports Ktor's type-safe routing via the Resources plugin. Resource classes can be used to define routes, and the plugin can automatically extract parameter information from resource class properties.
3+
The OpenAPI plugin supports Ktor's type-safe routing via the Resources plugin. Resource classes can be used to define routes and the plugin
4+
can automatically extract parameter information from resource class properties.
5+
6+
47

58
## Setup
69

710
Type-safe routing support requires additional configuration:
811

12+
913
### Installed Resources Plugin
1014

1115
The Ktor Resources plugin must be installed separately:
@@ -21,6 +25,7 @@ install(Resources)
2125
install(OpenApi)
2226
```
2327

28+
2429
### Configure Schema Generator
2530

2631
Type-safe routing requires the kotlinx.serialization schema generator:
@@ -33,6 +38,7 @@ install(OpenApi) {
3338
}
3439
```
3540

41+
3642
### Enable Auto-Documentation (Optional)
3743

3844
The `autoDocumentResourcesRoutes` option automatically extracts parameter information from resource classes:
@@ -51,6 +57,8 @@ When enabled, the plugin automatically documents:
5157

5258
This reduces the need for manual parameter documentation in resource routes.
5359

60+
61+
5462
## Documenting Resource Routes
5563

5664
### Import Documented Resource Functions
@@ -62,8 +70,10 @@ import io.github.smiley4.ktoropenapi.resources.get
6270
import io.github.smiley4.ktoropenapi.resources.post
6371
import io.github.smiley4.ktoropenapi.resources.put
6472
import io.github.smiley4.ktoropenapi.resources.delete
73+
// ...
6574
```
6675

76+
6777
### Document Resource Routes
6878

6979
The documentation block works the same as with standard routes:
@@ -79,11 +89,9 @@ class Users
7989
@Resource("{id}")
8090
class User(val parent: Users, val id: String)
8191

82-
8392
get<User>({
8493
description = "Retrieve a user by ID"
8594
tags = listOf("users")
86-
8795
response {
8896
code(HttpStatusCode.OK) {
8997
description = "User found"
@@ -94,7 +102,6 @@ get<User>({
94102
}
95103
}
96104
}) {
97-
val user = call.parameters["id"]
98-
// Handler implementation
105+
// handler implementation
99106
}
100107
```

0 commit comments

Comments
 (0)