You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
4
5
5
-
??? warning "Limited OpenAPI Support"
6
+
!!! warning "Limited OpenAPI Support"
6
7
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.
10
13
11
14
12
15
## Describing SSE-Routes
@@ -21,10 +24,13 @@ route({
21
24
tags =listOf("events", "sse")
22
25
}) {
23
26
sse("/events") {
24
-
// SSE implementation
25
27
send(ServerSentEvent(data ="Hello"))
26
28
}
27
29
}
28
30
```
29
31
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:
Copy file name to clipboardExpand all lines: docs/openapi/advanced_topics/documenting_webhooks.md
+11-6Lines changed: 11 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,13 @@
1
1
# Documenting Webhooks
2
2
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.
4
5
5
-
??? warning "Documentation Only"
6
+
!!! warning "Documentation Only"
6
7
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.
10
11
11
12
## Describing Webhooks
12
13
@@ -33,4 +34,8 @@ Parameters:
33
34
- httpMethod: HTTP method for the webhook (typically HttpMethod.Post)
34
35
- eventName: Unique identifier for the webhook event (e.g., "newOrder", "userCreated")
35
36
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:
Copy file name to clipboardExpand all lines: docs/openapi/advanced_topics/multiple_openapi_specifications.md
+41-23Lines changed: 41 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,13 @@
1
1
# Multiple API Specifications
2
2
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
+
4
10
5
-
Each specification has a unique identifier, its own configuration, and contains only the routes assigned to it. Specifications are generated and served independently.
6
11
7
12
## Configuring Specifications
8
13
@@ -12,33 +17,36 @@ All configuration options available in the base plugin config are available for
12
17
13
18
```kotlin
14
19
install(OpenApi) {
15
-
// Base configuration for all specifications
16
-
info {
20
+
info { // (1)!
17
21
title ="My API"
18
22
}
19
-
20
-
// Define specification "v1"
21
-
spec("v1") {
23
+
spec("v1") { // (2)!
22
24
info {
23
25
version ="1.0.0"
24
26
}
25
27
}
26
-
27
-
// Define specification "v2"
28
-
spec("v2") {
28
+
spec("v2") { // (3)!
29
29
info {
30
30
version ="2.0.0"
31
31
}
32
32
}
33
33
}
34
34
```
35
35
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
+
36
40
Each specification is identified by a unique string (e.g., "v1", "v2", "internal").
37
41
42
+
43
+
44
+
38
45
## Assigning Routes to Specifications
39
46
40
47
Routes must be assigned to specifications to appear in them. Assignment can be done explicitly in route documentation or automatically via an assigner function.
41
48
49
+
42
50
### Assignment at Route Documentation
43
51
44
52
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
54
62
55
63
```kotlin
56
64
route("v1", {
57
-
specName ="v1"//All child routes assigned to v1
65
+
specName ="v1"//(1)!
58
66
}) {
59
67
get("users") { }
60
68
get("products") { }
61
69
get("orders") { }
62
70
}
63
71
```
64
72
73
+
1. All child routes are assigned to "v1".
74
+
65
75
All routes within this block are automatically assigned to the "v1" specification through inheritance.
66
76
77
+
67
78
### Assignment via Assigner Function
68
79
69
80
Routes can be automatically assigned based on their properties using an assigner function:
@@ -88,34 +99,41 @@ The function receives:
88
99
89
100
The function returns the specification identifier to assign the route to.
90
101
102
+
91
103
### Unassigned Routes
92
104
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
+
94
110
95
111
## Serving Multiple Specifications
96
112
97
113
Each specification is served independently via HTTP routes.
98
114
99
115
```kotlin
100
116
routing {
101
-
// v1 specification
102
-
route("v1/api.json") {
117
+
route("v1/api.json") { // (1)!
103
118
openApi("v1")
104
119
}
105
-
106
-
// v2 specification
107
-
route("v2/api.json") {
120
+
route("v2/api.json") { // (2)!
108
121
openApi("v2")
109
122
}
110
-
111
-
// Internal specification
112
-
route("internal/api.json") {
123
+
route("internal/api.json") { // (3)!
113
124
openApi("internal")
114
125
}
115
126
}
116
127
```
117
128
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:
Copy file name to clipboardExpand all lines: docs/openapi/advanced_topics/typesafe_routing_support.md
+12-5Lines changed: 12 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,15 @@
1
1
# Type-Safe Routing Support
2
2
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
+
4
7
5
8
## Setup
6
9
7
10
Type-safe routing support requires additional configuration:
8
11
12
+
9
13
### Installed Resources Plugin
10
14
11
15
The Ktor Resources plugin must be installed separately:
@@ -21,6 +25,7 @@ install(Resources)
21
25
install(OpenApi)
22
26
```
23
27
28
+
24
29
### Configure Schema Generator
25
30
26
31
Type-safe routing requires the kotlinx.serialization schema generator:
@@ -33,6 +38,7 @@ install(OpenApi) {
33
38
}
34
39
```
35
40
41
+
36
42
### Enable Auto-Documentation (Optional)
37
43
38
44
The `autoDocumentResourcesRoutes` option automatically extracts parameter information from resource classes:
@@ -51,6 +57,8 @@ When enabled, the plugin automatically documents:
51
57
52
58
This reduces the need for manual parameter documentation in resource routes.
0 commit comments