Skip to content

Commit f4b13c2

Browse files
committed
Merge branch 'develop' into release
2 parents a488d1e + 2e63aac commit f4b13c2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+3690
-1216
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
kotlin("jvm") version "2.0.21"
2+
kotlin("jvm") version "2.2.21"
33
id("org.jetbrains.dokka") version "1.9.20" apply false
44
id("org.owasp.dependencycheck") version "8.2.1" apply false
55
id("io.gitlab.arturbosch.detekt") version "1.23.0" apply false

docs/assets/stylesheets/extra.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,20 @@ 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: 2.2em;
31+
}
32+
33+
.md-content {
34+
padding-bottom: 7em;
1935
}

docs/changelog.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,20 @@ search:
55

66
# Changelog
77

8+
## 5.4.0
9+
10+
- support for ReDoc extensions `x-displayName` and `x-tagGroups` [#221](https://github.com/SMILEY4/ktor-openapi-tools/pull/221), [#219](https://github.com/SMILEY4/ktor-openapi-tools/pull/219)
11+
- complete overhaul of the documentation
12+
- upgrade schema-kenerator from 2.4.0 to [2.5.0](https://github.com/SMILEY4/schema-kenerator/releases/tag/2.5.0)
13+
- upgrade Ktor from 3.2.3 to 3.3.2
14+
- upgrade kotlin from 2.0.21 to 2.2.21
15+
816
## 5.3.0
917

1018
- fix kotlinx-serialization example encoding [#212](https://github.com/SMILEY4/ktor-openapi-tools/issues/212)
1119
- fix missing response bodies from documented resources routes [#209](https://github.com/SMILEY4/ktor-openapi-tools/issues/209)
1220
- upgrade schema-kenerator from 2.3.0 to [2.4.0](https://github.com/SMILEY4/schema-kenerator/releases/tag/2.4.0)
13-
- upgrade ktor from 3.1.1 to ktor 3.3.0
21+
- upgrade ktor from 3.1.1 to ktor 3.2.3
1422

1523
## 5.2.0
1624

docs/index.md

Lines changed: 3 additions & 3 deletions
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: Read Documentation](./openapi/getting_started.md)
2525

2626

2727
- :simple-swagger:{ .lg .middle } __Swagger UI__
@@ -32,7 +32,7 @@ Designed to be non-invasive, they integrate seamlessly with applications without
3232

3333
Serve an interactive [Swagger UI](https://swagger.io/tools/swagger-ui/) for easy API exploration and testing
3434

35-
[:octicons-arrow-right-24: Get Started](swaggerui/index.md)
35+
[:octicons-arrow-right-24: Read Documentation](swaggerui/index.md)
3636

3737

3838
- :redoc:{ .lg .middle } __Redoc__
@@ -43,6 +43,6 @@ Designed to be non-invasive, they integrate seamlessly with applications without
4343

4444
Serve an interactive [ReDoc](https://github.com/Redocly/redoc) page for easy API exploration and testing
4545

46-
[:octicons-arrow-right-24: Get Started](redoc/index.md)
46+
[:octicons-arrow-right-24: Read Documentation](redoc/index.md)
4747

4848
</div>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Documenting SSE Routes
2+
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.
5+
6+
!!! warning "Limited OpenAPI Support"
7+
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.
13+
14+
15+
## Describing SSE-Routes
16+
17+
SSE routes are documented by wrapping them in a parent route with documentation:
18+
19+
```kotlin
20+
import io.ktor.server.sse.sse
21+
22+
route({
23+
description = "Server-sent events stream for real-time updates"
24+
tags = listOf("events", "sse")
25+
}) {
26+
sse("/events") {
27+
send(ServerSentEvent(data = "Hello"))
28+
}
29+
}
30+
```
31+
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)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Documenting Webhooks
2+
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.
5+
6+
!!! warning "Documentation Only"
7+
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.
11+
12+
## Describing Webhooks
13+
14+
Webhooks are documented using the webhook function:
15+
16+
```kotlin
17+
routing {
18+
route("webhooks") {
19+
webhook(HttpMethod.Post, "concertAlert") {
20+
description = "Notify the registered URL with details of an upcoming concert"
21+
request {
22+
body<String> {
23+
mediaTypes(ContentType.Text.Plain)
24+
required = true
25+
}
26+
}
27+
}
28+
}
29+
}
30+
```
31+
32+
Parameters:
33+
34+
- httpMethod: HTTP method for the webhook (typically HttpMethod.Post)
35+
- eventName: Unique identifier for the webhook event (e.g., "newOrder", "userCreated")
36+
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)
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# Multiple API Specifications
2+
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+
10+
11+
12+
## Configuring Specifications
13+
14+
Each specification can have its own configuration that extends or overrides the base plugin configuration.
15+
16+
All configuration options available in the base plugin config are available for individual specifications:
17+
18+
```kotlin
19+
install(OpenApi) {
20+
info { // (1)!
21+
title = "My API"
22+
}
23+
spec("v1") { // (2)!
24+
info {
25+
version = "1.0.0"
26+
}
27+
}
28+
spec("v2") { // (3)!
29+
info {
30+
version = "2.0.0"
31+
}
32+
}
33+
}
34+
```
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+
40+
Each specification is identified by a unique string (e.g., "v1", "v2", "internal").
41+
42+
43+
44+
45+
## Assigning Routes to Specifications
46+
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.
48+
49+
50+
### Assignment at Route Documentation
51+
52+
The `specName` property assigns a route to a specific specification:
53+
54+
```kotlin
55+
get("users", {
56+
specName = "v1"
57+
description = "Get users (v1)"
58+
}) { }
59+
```
60+
61+
Routes can be easily assigned in groups by adding the `specName` at a parent route:
62+
63+
```kotlin
64+
route("v1", {
65+
specName = "v1" // (1)!
66+
}) {
67+
get("users") { }
68+
get("products") { }
69+
get("orders") { }
70+
}
71+
```
72+
73+
1. All child routes are assigned to "v1".
74+
75+
All routes within this block are automatically assigned to the "v1" specification through inheritance.
76+
77+
78+
### Assignment via Assigner Function
79+
80+
Routes can be automatically assigned based on their properties using an assigner function:
81+
82+
```kotlin
83+
install(OpenApi) {
84+
specAssigner = { url, tags ->
85+
when (url.firstOrNull()) {
86+
"v1" -> "v1"
87+
"v2" -> "v2"
88+
"internal" -> "internal"
89+
else -> OpenApiPluginConfig.DEFAULT_SPEC_ID
90+
}
91+
}
92+
}
93+
```
94+
95+
The function receives:
96+
97+
- `url`: URL path as a list of segments (e.g., `["api", "v1", "users"]` for `/api/v1/users`)
98+
- `tags`: Tags assigned to the route
99+
100+
The function returns the specification identifier to assign the route to.
101+
102+
103+
### Unassigned Routes
104+
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+
110+
111+
## Serving Multiple Specifications
112+
113+
Each specification is served independently via HTTP routes.
114+
115+
```kotlin
116+
routing {
117+
route("v1/api.json") { // (1)!
118+
openApi("v1")
119+
}
120+
route("v2/api.json") { // (2)!
121+
openApi("v2")
122+
}
123+
route("internal/api.json") { // (3)!
124+
openApi("internal")
125+
}
126+
}
127+
```
128+
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)
138+
139+
[:octicons-arrow-right-24: ReDoc](./../../redoc/getting_started.md)

0 commit comments

Comments
 (0)