Skip to content

Commit

Permalink
make it possible to pass route annotations for e.g. access control
Browse files Browse the repository at this point in the history
  • Loading branch information
angryziber committed Aug 21, 2023
1 parent aafc08e commit 5641d46
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions openapi/src/OpenAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import io.swagger.v3.oas.annotations.enums.ParameterIn
import io.swagger.v3.oas.annotations.media.Schema.AccessMode
import io.swagger.v3.oas.annotations.tags.Tag
import klite.*
import klite.RequestMethod.GET
import klite.StatusCode.Companion.NoContent
import klite.StatusCode.Companion.OK
import klite.annotations.*
Expand All @@ -31,8 +32,8 @@ import kotlin.reflect.full.isSubclassOf
* - @Parameter annotation can be used on method parameters directly.
* - @Tag annotation is supported on route classes for grouping of routes.
*/
fun Router.openApi(path: String = "/openapi", title: String = "API", version: String = "1.0.0") {
get(path) {
fun Router.openApi(path: String = "/openapi", title: String = "API", version: String = "1.0.0", annotations: List<Annotation> = emptyList()) {
add(Route(GET, path.toRegex(), annotations) {
mapOf(
"openapi" to "3.0.0",
"info" to mapOf("title" to title, "version" to version),
Expand All @@ -42,7 +43,7 @@ fun Router.openApi(path: String = "/openapi", title: String = "API", version: St
routes.associate(::toOperation)
}
)
}
})
}

internal fun toTags(routes: List<Route>) = routes.asSequence()
Expand Down

0 comments on commit 5641d46

Please sign in to comment.