diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 99aedc5..e565fc1 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -4,6 +4,7 @@ dependencies { api("org.http4k:http4k-config") api("org.http4k:http4k-multipart") api("org.http4k:http4k-contract") + api("org.http4k:http4k-contract-ui-swagger") api("org.http4k:http4k-format-jackson") api("org.http4k:http4k-security-oauth") api("org.http4k:http4k-template-rocker") diff --git a/app/src/main/kotlin/http4kbox/Http4kBox.kt b/app/src/main/kotlin/http4kbox/Http4kBox.kt index 3bcdb93..a8b7c61 100644 --- a/app/src/main/kotlin/http4kbox/Http4kBox.kt +++ b/app/src/main/kotlin/http4kbox/Http4kBox.kt @@ -28,7 +28,8 @@ fun Http4kBox(env: Environment, http: HttpHandler, clock: Clock): HttpHandler { return CatchAll().then( routes( "/oauth/callback" bind GET to oAuthProvider.callback, - oAuthProvider.authFilter.then(routes(Api(CREDENTIALS(env), fs), web(fs))) + "/api" bind Api(CREDENTIALS(env), fs), + oAuthProvider.authFilter.then(web(fs)) ) ) } diff --git a/app/src/main/kotlin/http4kbox/Settings.kt b/app/src/main/kotlin/http4kbox/Settings.kt index 5409e48..e6e6e21 100644 --- a/app/src/main/kotlin/http4kbox/Settings.kt +++ b/app/src/main/kotlin/http4kbox/Settings.kt @@ -11,6 +11,6 @@ import org.http4k.lens.value object Settings { val OAUTH_BASE_URI by EnvironmentKey.uri().of().defaulted(Uri.of("https://github.com")) val CALLBACK by EnvironmentKey.uri().of().required() - val CREDENTIALS by EnvironmentKey.map { it.split(":") }.map { Credentials(it[0], it[0]) }.of().required() + val CREDENTIALS by EnvironmentKey.map { it.split(":") }.map { Credentials(it[0], it[1]) }.of().required() val AWS_BUCKET by EnvironmentKey.value(BucketName).of().required() } diff --git a/app/src/main/kotlin/http4kbox/endpoints/Api.kt b/app/src/main/kotlin/http4kbox/endpoints/Api.kt index 4bc5038..04490f6 100644 --- a/app/src/main/kotlin/http4kbox/endpoints/Api.kt +++ b/app/src/main/kotlin/http4kbox/endpoints/Api.kt @@ -5,11 +5,22 @@ import org.http4k.contract.contract import org.http4k.contract.openapi.ApiInfo import org.http4k.contract.openapi.v3.OpenApi3 import org.http4k.contract.security.ApiKeySecurity +import org.http4k.contract.ui.swagger.swaggerUiWebjar import org.http4k.core.Credentials import org.http4k.lens.Header +import org.http4k.routing.routes -fun Api(credentials: Credentials, fs: FileStorage) = contract { - security = ApiKeySecurity(Header.required("http4k-api-key"), { it == credentials.password }) - renderer = OpenApi3(ApiInfo("http4kbox", "0.0")) - routes += ListFiles(fs) -} \ No newline at end of file +fun Api(credentials: Credentials, fs: FileStorage) = + routes( + swaggerUiWebjar { + pageTitle = "http4kbox API" + url = "/api/openapi.json" + }, + contract { + descriptionPath = "/openapi.json" + println(credentials.password) + security = ApiKeySecurity(Header.required("http4k-api-key"), { it == credentials.password }) + renderer = OpenApi3(ApiInfo("http4kbox", "0.0")) + routes += ListFiles(fs) + } + ) \ No newline at end of file diff --git a/app/src/test/kotlin/env/DevRunner.kt b/app/src/test/kotlin/env/DevRunner.kt index a2c387b..3866a87 100644 --- a/app/src/test/kotlin/env/DevRunner.kt +++ b/app/src/test/kotlin/env/DevRunner.kt @@ -23,9 +23,8 @@ fun main() { val github = FakeGitHub(clock).asServer(SunHttp(10000)).start() - val http = reverseProxy( - "github" to SetBaseUriFrom(Uri.of("http://localhost:${github.port()}")).then(JavaHttpClient()), + "localhost" to SetBaseUriFrom(Uri.of("http://localhost:${github.port()}")).then(JavaHttpClient()), "s3" to SetBaseUriFrom(Uri.of("http://localhost:${s3.port()}")).then(JavaHttpClient()), )