Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
136 changes: 133 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,134 @@
.idea
.gradle
# Jetbrains
.idea/

### Kotlin
.kotlin
build
*.class
*.log
*.jar

# Dokka
docs/dokka/

### Visual Studio Code
.vscode/

# Local History for Visual Studio Code
.history/

### Linux
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### Windows
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

### Gradle
.gradle/
build/

# Ignore Gradle GUI config
gradle-app.setting

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

# Avoid ignore Gradle wrappper properties
!gradle-wrapper.properties

# Cache of project
.gradletasknamecache

# Eclipse Gradle plugin generated files
# Eclipse Core
.project
# JDT-specific (Eclipse Java Development Tools)
.classpath

### macOS
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk


### Python
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# pyenv
.python-version

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# mkdocs documentation
/site
17 changes: 17 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,25 @@ plugins {
id("io.gitlab.arturbosch.detekt") version "1.23.0" apply false
id("com.vanniktech.maven.publish") version "0.28.0" apply false
id("com.github.ben-manes.versions") version "0.51.0" apply false
id("ru.vyarus.mkdocs") version "4.0.1"
}

repositories {
mavenCentral()
}

mkdocs {
sourcesDir = "."
buildDir = "./build/mkdocs"
updateSiteUrl = true
publish {
version = "5.0"
rootRedirect = true
rootRedirectTo = "latest"
setVersionAliases("latest")
generateVersionsFile = true
}
python {
minPythonVersion = "3.12"
}
}
Binary file added docs/assets/images/quickstart/redoc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/images/quickstart/swagger.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Changelog
6 changes: 6 additions & 0 deletions docs/examples/authentication.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Authentication


```kotlin title="Authentication.kt" linenums="1"
---8<--- "Authentication.kt"
```
118 changes: 118 additions & 0 deletions docs/examples/basics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
[//]: # (# Basics)

[//]: # ()
[//]: # (This example shows a basic usage of the plugin)

[//]: # ()
[//]: # (## Complete Example)

[//]: # (```kotlin title="Basics.kt" linenums="1")

[//]: # (--8<-- "Basics.kt")

[//]: # (```)

[//]: # ()
[//]: # (## Breaking it down)

[//]: # (### Install and configure the plugin)

[//]: # ()
[//]: # (```kotlin title="Basics.kt")

[//]: # (--8<-- "Basics.kt:24:44")

[//]: # (```)

[//]: # ()
[//]: # (### Configure routes)

[//]: # ()
[//]: # (#### Spec routes)

[//]: # ()
[//]: # (=== "OpenAPI")

[//]: # ()
[//]: # ( Configure the OpenAPI spec file to be served from `/api.json`)

[//]: # ( )
[//]: # ( ```kotlin)

[//]: # ( --8<-- "Basics.kt:50:52")

[//]: # ( ```)

[//]: # ()
[//]: # (=== "Swagger UI")

[//]: # ()
[//]: # ( Configure Swagger UI to be served from `/swagger` with the OpenAPI spec file at `/api.json`)

[//]: # ()
[//]: # ( ```kotlin)

[//]: # ( --8<-- "Basics.kt:55:57")

[//]: # ( ```)

[//]: # ()
[//]: # (=== "ReDoc")

[//]: # ()
[//]: # ( Configure Swagger UI to be served from `/redoc` with the OpenAPI spec file at `/api.json`)

[//]: # ()
[//]: # ( ```kotlin)

[//]: # ( --8<-- "Basics.kt:55:57")

[//]: # ( ```)

[//]: # ()
[//]: # (!!! note)

[//]: # ()
[//]: # ( The spec routes will not be included in the final OpenAPI spec file)

[//]: # ()
[//]: # ()
[//]: # (#### Document a route)

[//]: # ()
[//]: # (We add information about the route itself)

[//]: # ()
[//]: # (```kotlin title="Basics.kt" hl_lines="3")

[//]: # (--8<-- "Basics.kt:65:86")

[//]: # (```)

[//]: # ()
[//]: # (We add information about the request)

[//]: # ()
[//]: # (```kotlin title="Basics.kt" hl_lines="5-10")

[//]: # (--8<-- "Basics.kt:65:86")

[//]: # (```)

[//]: # ()
[//]: # (And finally, the response)

[//]: # ()
[//]: # (```kotlin title="Basics.kt" hl_lines="12-15")

[//]: # (--8<-- "Basics.kt:65:86")

[//]: # (```)

# Basic

This example shows a basic usage of the plugin

```kotlin title="Basics.kt" linenums="1"
--8<---- "Basics.kt"
```
7 changes: 7 additions & 0 deletions docs/examples/complete-configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Complete Configuration

This example showcases a **nearly** complete - and mostly nonsensical - plugin configuration

```kotlin title="CompleteConfig.kt" linenums="1"
--8<-- "CompleteConfig.kt"
```
5 changes: 5 additions & 0 deletions docs/examples/customized-schema-generator.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Customized Schema Generator

```kotlin linenums="1"
---8<--- "CustomizedSchemaGenerator.kt"
```
5 changes: 5 additions & 0 deletions docs/examples/external-openapi-spec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# External OpenAPI Spec

```kotlin linenums="1"
---8<--- "ExternalOpenApiSpec.kt"
```
5 changes: 5 additions & 0 deletions docs/examples/file-upload.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# File Upload

```kotlin linenums="1"
---8<--- "FileUpload.kt"
```
5 changes: 5 additions & 0 deletions docs/examples/kotlinx-serialization.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Kotlinx Serialization

```kotlin linenums="1"
---8<--- "KotlinxSerialization.kt"
```
7 changes: 7 additions & 0 deletions docs/examples/minimal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Minimal

This example showcases using the plugin with most of the default configuration

```kotlin title="Minimal.kt" linenums="1"
--8<-- "Minimal.kt"
```
5 changes: 5 additions & 0 deletions docs/examples/multiple-specs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Multiple Specs

```kotlin linenums="1"
---8<--- "MultipleSpecs.kt"
```
5 changes: 5 additions & 0 deletions docs/examples/openapi-examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# OpenAPI Examples

```kotlin linenums="1"
---8<--- "Examples.kt"
```
5 changes: 5 additions & 0 deletions docs/examples/petstore.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Petstore

```kotlin linenums="1"
---8<--- "Petstore.kt"
```
5 changes: 5 additions & 0 deletions docs/examples/request-response.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Requests and Responses

```kotlin linenums="1"
---8<--- "RequestResponse.kt"
```
5 changes: 5 additions & 0 deletions docs/examples/schemas.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Schemas

```kotlin linenums="1"
---8<--- "Schemas.kt"
```
21 changes: 21 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Ktor Swagger UI

[![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)
[![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)
Copy link
Owner

@SMILEY4 SMILEY4 Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maye remove badges from mkdocs wiki -> I think one of them results in some cookies associated with google analytics being set. I'm not 100% sure though about it, perhaps you could test it too and double check.

image
Firefox blocks it for me, though google chrome seems to allow it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into it. It seems to be the Checks - Passing badge.

But that also reminds me, now that we have three packages instead of one, we may need to add the others to Maven Central if we still want to keep that too.


This library provides a [Ktor](https://ktor.io/) plugin to document routes, generate an OpenAPI specification and serve [Swagger UI](https://swagger.io/tools/swagger-ui/) and [ReDoc](https://github.com/Redocly/redoc).

It is meant to be minimally invasive i.e. it can be plugged into existing application without requiring immediate changes to the code.
Routes can then be gradually enhanced with documentation.


## Features

- Minimally invasive (no immediate change to existing code required)
- Provides OpenAPI spec, Swagger UI and ReDoc with minimal configuration
- Supports most of the [OpenAPI 3.1.0 Specification](https://swagger.io/specification/)
- Automatic [json-schema generation](https://github.com/SMILEY4/schema-kenerator) from arbitrary types/classes for bodies and parameters
- Supports generics, inheritance, collections, etc.
- (Optional) support for Jackson-annotations and swagger schema annotations
- Use with reflection or kotlinx-serialization
- Customizable schema generation
Loading