Skip to content

Commit 0acb0b9

Browse files
authored
Merge pull request #37 from uuf6429/Update-swaggerui-version
Update swaggerui, make its version configurable, minor readme update
2 parents 91f826a + dbe14f1 commit 0acb0b9

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@ Ktor OpenAPI Generator is:
1010
- Explicit
1111

1212
Currently Supported:
13-
- Authentication ineroperability with strongly typed Principal (OAuth only, see TestServer in tests)
14-
- Content Negociation interoperability (see TestServer in tests)
15-
- Custom response codes (as parameter in @Response)
16-
- Automatic and custom content Type routing and parsing (see com.papsign.ktor.openapigen.content.type, Binary Parser and default JSON parser (that uses the ktor implicit parsing/serializing))
17-
- Exception handling (use .throws(ex) {} in the routes with an APIException object) with Status pages interop (with .withAPI in the StatusPages configuration)
18-
- tags (.tag(tag) {} in route with a tag object, currently must be an enum, but may be subject to change)
13+
- Authentication interoperability with strongly typed Principal (OAuth only, see TestServer in tests)
14+
- Content Negotiation interoperability (see TestServer in tests)
15+
- Custom response codes (as parameter in `@Response`)
16+
- Automatic and custom content Type routing and parsing (see `com.papsign.ktor.openapigen.content.type`, Binary Parser and default JSON parser (that uses the ktor implicit parsing/serializing))
17+
- Exception handling (use `.throws(ex) {}` in the routes with an APIException object) with Status pages interop (with .withAPI in the StatusPages configuration)
18+
- tags (`.tag(tag) {}` in route with a tag object, currently must be an enum, but may be subject to change)
1919
- Spec compliant Parameter Parsing (see basic example)
2020

21+
Extra Features:
22+
- Includes Swagger-UI (enabled by default, can be managed in the `install(OpenAPIGen) { ... }` section)
23+
2124
It is inspired by ktor Locations, but makes no use of it.
2225

2326
Take a look at the [wiki for advanced features and mechanics](https://github.com/papsign/Ktor-OpenAPI-Generator/wiki)
@@ -26,7 +29,7 @@ Take a look at the [wiki for advanced features and mechanics](https://github.com
2629

2730
### Gradle
2831

29-
Step 1. Add the JitPack repository to your build file
32+
Step 1. Add the JitPack repository to your build file:
3033
```
3134
allprojects {
3235
repositories {
@@ -35,7 +38,7 @@ allprojects {
3538
}
3639
}
3740
```
38-
Step 2. Add the dependency
41+
Step 2. Add the dependency:
3942
```
4043
dependencies {
4144
implementation 'com.github.papsign:Ktor-OpenAPI-Generator:-SNAPSHOT'
@@ -114,7 +117,7 @@ data class StringResponse(val str: String)
114117
data class StringUsable(val str: String)
115118
```
116119

117-
Creates this openapi.json description:
120+
Creates this `openapi.json` description:
118121

119122
```json
120123
{

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ dependencies {
2020

2121
implementation "io.ktor:ktor-jackson:$ktor_version" // needed for parameter parsing and multipart parsing
2222
implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.9.8" // needed for multipart parsing
23-
implementation 'org.webjars:swagger-ui:3.18.2'
23+
implementation 'org.webjars:swagger-ui:3.25.0'
2424

2525
implementation "org.reflections:reflections:0.9.11" // only used while initializing
2626

src/main/kotlin/com/papsign/ktor/openapigen/OpenAPIGen.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class OpenAPIGen(
6767

6868
var swaggerUiPath = "swagger-ui"
6969
var serveSwaggerUi = true
70+
var swaggerUiVersion = "3.25.0"
7071

7172
var schemaNamer: (KType) -> String = KType::toString
7273

@@ -118,7 +119,7 @@ class OpenAPIGen(
118119
val api = OpenAPI()
119120
val cfg = Configuration(api).apply(configure)
120121
if (cfg.serveSwaggerUi) {
121-
val ui = SwaggerUi(cfg.swaggerUiPath)
122+
val ui = SwaggerUi(cfg.swaggerUiPath, cfg.swaggerUiVersion)
122123
pipeline.intercept(ApplicationCallPipeline.Call) {
123124
val cmp = "/${cfg.swaggerUiPath.trim('/')}/"
124125
if (call.request.path().startsWith(cmp))

src/main/kotlin/com/papsign/ktor/openapigen/SwaggerUI.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ import io.ktor.request.port
1414
import io.ktor.response.respond
1515
import java.net.URL
1616

17-
class SwaggerUi(val basePath: String) {
17+
class SwaggerUi(private val basePath: String, private val version: String) {
1818
private val notFound = mutableListOf<String>()
1919
private val content = mutableMapOf<String, ResourceContent>()
2020
suspend fun serve(filename: String?, call: ApplicationCall) {
2121
when (filename) {
2222
in notFound -> return
2323
null -> return
2424
else -> {
25-
val resource = this::class.java.getResource("/META-INF/resources/webjars/swagger-ui/3.18.2/$filename")
25+
val resource = this::class.java.getResource("/META-INF/resources/webjars/swagger-ui/$version/$filename")
2626
if (resource == null) {
2727
notFound.add(filename)
2828
return

0 commit comments

Comments
 (0)