-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'support-spec-as-yaml' into develop
- Loading branch information
Showing
8 changed files
with
96 additions
and
88 deletions.
There are no files selected for viewing
70 changes: 0 additions & 70 deletions
70
ktor-swagger-ui-examples/src/main/kotlin/io/github/smiley4/ktorswaggerui/examples/Test.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
ktor-swagger-ui/src/main/kotlin/io/github/smiley4/ktorswaggerui/data/OutputFormat.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package io.github.smiley4.ktorswaggerui.data | ||
|
||
enum class OutputFormat(val empty: String) { | ||
JSON("{}"), | ||
YAML("") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 10 additions & 5 deletions
15
ktor-swagger-ui/src/main/kotlin/io/github/smiley4/ktorswaggerui/routing/ApiSpec.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,33 @@ | ||
package io.github.smiley4.ktorswaggerui.routing | ||
|
||
import io.github.smiley4.ktorswaggerui.data.OutputFormat | ||
import io.github.smiley4.ktorswaggerui.data.SwaggerUIData | ||
|
||
object ApiSpec { | ||
|
||
var swaggerUiConfig: SwaggerUIData = SwaggerUIData.DEFAULT | ||
|
||
private val apiSpecs = mutableMapOf<String, String>() | ||
private val apiSpecs = mutableMapOf<String, Pair<String, OutputFormat>>() | ||
|
||
fun setAll(specs: Map<String, String>) { | ||
fun setAll(specs: Map<String, Pair<String, OutputFormat>>) { | ||
apiSpecs.clear() | ||
apiSpecs.putAll(specs) | ||
} | ||
|
||
fun set(name: String, spec: String) { | ||
fun set(name: String, spec: Pair<String, OutputFormat>) { | ||
apiSpecs[name] = spec | ||
} | ||
|
||
fun get(name: String): String { | ||
return apiSpecs[name] ?: throw NoSuchElementException("No api-spec with name '$name' registered.") | ||
return apiSpecs[name]?.first ?: throw NoSuchElementException("No api-spec with name '$name' registered.") | ||
} | ||
|
||
fun getFormat(name: String): OutputFormat { | ||
return apiSpecs[name]?.second ?: throw NoSuchElementException("No api-spec with name '$name' registered.") | ||
} | ||
|
||
fun getAll(): Map<String, String> { | ||
return apiSpecs | ||
return apiSpecs.mapValues { it.value.first } | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters