Skip to content

Commit e90a0be

Browse files
committed
Merge branch 'develop' into release
2 parents e6d6f9a + 5b28911 commit e90a0be

File tree

207 files changed

+7190
-2640
lines changed

Some content is hidden

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

207 files changed

+7190
-2640
lines changed

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
build:
1010

1111
runs-on: ubuntu-latest
12-
if: github.repository == 'SMILEY4/ktor-swagger-ui'
12+
if: github.repository == 'SMILEY4/ktor-openapi-tools'
1313

1414
steps:
1515
- uses: actions/checkout@v3

.gitignore

Lines changed: 135 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,135 @@
1-
.idea
2-
.gradle
3-
build
1+
# Jetbrains
2+
.idea/
3+
4+
### Kotlin
5+
.kotlin
6+
*.class
7+
*.log
8+
*.jar
9+
10+
# Dokka
11+
docs/dokka/
12+
13+
### Visual Studio Code
14+
.vscode/
15+
16+
# Local History for Visual Studio Code
17+
.history/
18+
19+
### Linux
20+
*~
21+
22+
# temporary files which can be created if a process still has a handle open of a deleted file
23+
.fuse_hidden*
24+
25+
# KDE directory preferences
26+
.directory
27+
28+
# Linux trash folder which might appear on any partition or disk
29+
.Trash-*
30+
31+
# .nfs files are created when an open file is removed but is still being accessed
32+
.nfs*
33+
34+
### Windows
35+
# Windows thumbnail cache files
36+
Thumbs.db
37+
Thumbs.db:encryptable
38+
ehthumbs.db
39+
ehthumbs_vista.db
40+
41+
# Dump file
42+
*.stackdump
43+
44+
# Folder config file
45+
[Dd]esktop.ini
46+
47+
# Recycle Bin used on file shares
48+
$RECYCLE.BIN/
49+
50+
# Windows Installer files
51+
*.cab
52+
*.msi
53+
*.msix
54+
*.msm
55+
*.msp
56+
57+
# Windows shortcuts
58+
*.lnk
59+
60+
### Gradle
61+
.gradle/
62+
build/
63+
64+
# Ignore Gradle GUI config
65+
gradle-app.setting
66+
67+
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
68+
!gradle-wrapper.jar
69+
70+
# Avoid ignore Gradle wrappper properties
71+
!gradle-wrapper.properties
72+
73+
# Cache of project
74+
.gradletasknamecache
75+
76+
# Eclipse Gradle plugin generated files
77+
# Eclipse Core
78+
.project
79+
# JDT-specific (Eclipse Java Development Tools)
80+
.classpath
81+
82+
### macOS
83+
# General
84+
.DS_Store
85+
.AppleDouble
86+
.LSOverride
87+
88+
# Icon must end with two \r
89+
Icon
90+
91+
# Thumbnails
92+
._*
93+
94+
# Files that might appear in the root of a volume
95+
.DocumentRevisions-V100
96+
.fseventsd
97+
.Spotlight-V100
98+
.TemporaryItems
99+
.Trashes
100+
.VolumeIcon.icns
101+
.com.apple.timemachine.donotpresent
102+
103+
# Directories potentially created on remote AFP share
104+
.AppleDB
105+
.AppleDesktop
106+
Network Trash Folder
107+
Temporary Items
108+
.apdisk
109+
110+
111+
### Python
112+
# Byte-compiled / optimized / DLL files
113+
__pycache__/
114+
*.py[cod]
115+
*$py.class
116+
117+
# Installer logs
118+
pip-log.txt
119+
pip-delete-this-directory.txt
120+
121+
# pyenv
122+
.python-version
123+
124+
# Environments
125+
.env
126+
.venv
127+
env/
128+
venv/
129+
ENV/
130+
env.bak/
131+
venv.bak/
132+
133+
# mkdocs documentation
134+
/site
135+
.cache

README.md

Lines changed: 72 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,138 +1,101 @@
1-
# Ktor Swagger-UI
1+
# Ktor OpenAPI Tools
22

3-
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.github.smiley4/ktor-swagger-ui/badge.svg)](https://search.maven.org/artifact/io.github.smiley4/ktor-swagger-ui)
4-
[![Checks Passing](https://github.com/SMILEY4/ktor-swagger-ui/actions/workflows/checks.yml/badge.svg?branch=develop)](https://github.com/SMILEY4/ktor-swagger-ui/actions/workflows/checks.yml)
3+
[![Version](https://img.shields.io/maven-central/v/io.github.smiley4/ktor-openapi?style=flat&color=blue&logo=apachemaven)](https://search.maven.org/search?q=g:io.github.smiley4%20a:ktor-openapi)
4+
[![Checks Passing](https://img.shields.io/github/actions/workflow/status/SMILEY4/ktor-swagger-ui/checks.yml?style=flat&logo=github)](https://github.com/SMILEY4/ktor-openapi-tools/actions/workflows/checks.yml)
5+
[![License](https://img.shields.io/github/license/SMILEY4/ktor-swagger-ui?style=flat&color=teal)](https://github.com/SMILEY4/ktor-openapi-tools/blob/develop/LICENSE)
56

6-
This library provides a Ktor plugin to document routes, generate an OpenApi Specification and serve a Swagger UI. It is meant to be minimally invasive, meaning it can be plugged into existing application without requiring immediate changes to the code. Routes can then be gradually enhanced with documentation.
7+
A collection of libraries to simplify API documentation and exploration for [Ktor](https://ktor.io/) applications. Designed to be non-invasive, they integrate seamlessly with applications without requiring immediate change to existing code while being highly customizable to fit every use case.
78

9+
**Documentation** can be found [here](https://smiley4.github.io/ktor-openapi-tools/latest/).
810

9-
## Features
1011

11-
- minimally invasive (no immediate change to existing code required)
12-
- provides swagger-ui and openapi-spec with minimal configuration
13-
- supports most of the [OpenAPI 3.1.0 Specification](https://swagger.io/specification/)
14-
- automatic [json-schema generation](https://github.com/SMILEY4/schema-kenerator) from arbitrary types/classes for bodies and parameters
15-
- supports generics, inheritance, collections, ...
16-
- support for Jackson-annotations and swagger Schema-annotations (optional)
17-
- use with reflection or kotlinx-serialization
18-
- customizable schema-generation
12+
## OpenAPI
1913

14+
Ktor plugin to automatically generate [OpenAPI](https://www.openapis.org/) specifications from routes. Additional information can be gradually added to existing routes without requiring major changes to existing code.
2015

21-
## Documentation
22-
23-
A wiki with a short documentation is available [here](https://github.com/SMILEY4/ktor-swagger-ui/wiki).
24-
25-
26-
## Installation
16+
- Extends existing Ktor DSL
17+
- No immediate change to code required
18+
- Support for [Type-safe routing](https://ktor.io/docs/server-resources.html) / Resources plugin
19+
- Document webhooks and (limited) options for server-sent events
20+
- Covers (almost) complete [OpenAPI 3.1.0 Specification](https://swagger.io/specification/)
21+
- Automatically generates json schemas from kotlin types
22+
- Out-of-the-box support for type parameters, inheritance, collections, etc
23+
- Usable with reflection or [kotlinx.serialization](https://github.com/Kotlin/kotlinx.serialization)
24+
- Supports [Jackson](https://github.com/FasterXML/jackson), [Swagger](https://github.com/swagger-api/swagger-core), [Javax](https://mvnrepository.com/artifact/javax.validation/validation-api)
25+
and [Jakarta](https://github.com/jakartaee/validation/tree/main) annotations
26+
- Highly configurable and customizable
2727

2828
```kotlin
29-
dependencies {
30-
implementation "io.github.smiley4:ktor-swagger-ui:<VERSION>"
29+
// Install and configure the OpenAPI plugin.
30+
install(OpenApi)
31+
32+
routing {
33+
34+
route("api.json") {
35+
// Create a route to expose the OpenAPI specification file at `/api.json`.
36+
openApi()
37+
}
38+
39+
get("example", {
40+
// Add (optional) information to the route, e.g. a description and responses and response bodies.
41+
description = "An example route"
42+
response {
43+
HttpStatusCode.OK to {
44+
description = "A success response"
45+
body<String>()
46+
}
47+
}
48+
}) {
49+
// Handle requests as usual.
50+
call.respondText("Hello World!")
51+
}
3152
}
3253
```
3354

3455

35-
## Ktor compatibility
36-
37-
- Ktor 2.x: ktor-swagger-ui up to 3.x
38-
- Ktor 3.x: ktor-swagger-ui starting with 4.0
56+
## Swagger UI
3957

58+
Library for Ktor applications to serve [Swagger UI](https://swagger.io/tools/swagger-ui/) - visualize and interact with generated OpenAPI specifications.
4059

41-
## Examples
60+
- Explore and interact with OpenAPI specifications generated by [`ktor-openapi`](../openapi/index.md) or external specifications
61+
- Serve bundled Swagger UI
62+
- Expose multiple "instances" of Swagger UI (e.g. for different OpenAPI specifications)
63+
- All Swagger UI configuration options available
4264

43-
Runnable examples can be found in [ktor-swagger-ui-examples/src/main/kotlin/io/github/smiley4/ktorswaggerui/examples](https://github.com/SMILEY4/ktor-swagger-ui/tree/release/ktor-swagger-ui-examples/src/main/kotlin/io/github/smiley4/ktorswaggerui/examples).
44-
45-
46-
### Configuration
47-
48-
```kotlin
49-
install(SwaggerUI) {
50-
swagger {
51-
swaggerUrl = "swagger-ui"
52-
forwardRoot = true
53-
}
54-
info {
55-
title = "Example API"
56-
version = "latest"
57-
description = "Example API for testing and demonstration purposes."
58-
}
59-
server {
60-
url = "http://localhost:8080"
61-
description = "Development Server"
62-
}
63-
}
64-
```
6565
```kotlin
6666
routing {
67-
// Create a route for the openapi-spec file.
68-
route("api.json") {
69-
openApiSpec()
70-
}
71-
// Create a route for the swagger-ui using the openapi-spec at "/api.json".
67+
7268
route("swagger") {
73-
swaggerUI("/api.json")
69+
// Expose Swagger UI using OpenAPI specification at `/api.json`.
70+
// Path can be relative pointing to specification provided by this application or absolute pointing to an external resource.
71+
swaggerUI("/api.json") {
72+
// Add configuration for this Swagger UI "instance" here.
73+
}
7474
}
75+
7576
}
7677
```
7778

78-
### Routes
7979

80-
```kotlin
81-
get("hello", {
82-
description = "Hello World Endpoint."
83-
response {
84-
HttpStatusCode.OK to {
85-
description = "Successful Request"
86-
body<String> { description = "the response" }
87-
}
88-
HttpStatusCode.InternalServerError to {
89-
description = "Something unexpected happened"
90-
}
91-
}
92-
}) {
93-
call.respondText("Hello World!")
94-
}
95-
```
80+
## ReDoc
81+
82+
Library for Ktor applications to serve [ReDoc](https://github.com/Redocly/redoc) - visualize and interact with generated OpenAPI specifications.
83+
84+
- Explore and interact with OpenAPI specifications generated by [`ktor-openapi`](../openapi/index.md) or external specifications
85+
- Serve bundled ReDoc page
86+
- Expose multiple "instances" of ReDoc (e.g. for different OpenAPI specifications)
87+
- All ReDoc configuration options available
9688

9789
```kotlin
98-
post("math/{operation}", {
99-
tags = listOf("test")
100-
description = "Performs the given operation on the given values and returns the result"
101-
request {
102-
pathParameter<String>("operation") {
103-
description = "the math operation to perform. Either 'add' or 'sub'"
104-
}
105-
body<MathRequest>()
106-
}
107-
response {
108-
HttpStatusCode.OK to {
109-
description = "The operation was successful"
110-
body<MathResult> {
111-
description = "The result of the operation"
112-
}
113-
}
114-
HttpStatusCode.BadRequest to {
115-
description = "An invalid operation was provided"
116-
}
117-
}
118-
}) {
119-
val operation = call.parameters["operation"]!!
120-
call.receive<MathRequest>().let { request ->
121-
when (operation) {
122-
"add" -> call.respond(HttpStatusCode.OK, MathResult(request.a + request.b))
123-
"sub" -> call.respond(HttpStatusCode.OK, MathResult(request.a - request.b))
124-
else -> call.respond(HttpStatusCode.BadRequest, Unit)
90+
routing {
91+
92+
route("redoc") {
93+
// Expose ReDoc showing OpenAPI specification at `/api.json`.
94+
// Path can be relative pointing to specification provided by this application or absolute pointing to an external resource.
95+
redoc("/api.json") {
96+
// Add configuration for this ReDoc "instance" here.
12597
}
12698
}
99+
127100
}
128-
129-
data class MathRequest(
130-
val a: Int,
131-
val b: Int
132-
)
133-
134-
data class MathResult(
135-
val value: Int
136-
)
137-
```
138-
101+
```

build.gradle.kts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,27 @@ plugins {
44
id("org.owasp.dependencycheck") version "8.2.1" apply false
55
id("io.gitlab.arturbosch.detekt") version "1.23.0" apply false
66
id("com.vanniktech.maven.publish") version "0.28.0" apply false
7+
id("com.github.ben-manes.versions") version "0.51.0" apply false
8+
id("ru.vyarus.mkdocs") version "4.0.1"
79
}
810

911
repositories {
1012
mavenCentral()
1113
}
14+
15+
mkdocs {
16+
sourcesDir = "."
17+
buildDir = "./build/mkdocs"
18+
updateSiteUrl = true
19+
publish {
20+
branch = "gh-pages"
21+
version = "5.x"
22+
rootRedirect = true
23+
rootRedirectTo = "latest"
24+
setVersionAliases("latest")
25+
generateVersionsFile = true
26+
}
27+
python {
28+
minPythonVersion = "3.12"
29+
}
30+
}

detekt/detekt.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ style:
733733
UntilInsteadOfRangeTo:
734734
active: false
735735
UnusedImports:
736-
active: false
736+
active: true
737737
UnusedParameter:
738738
active: true
739739
allowedNames: 'ignored|expected'

0 commit comments

Comments
 (0)