Skip to content

Commit

Permalink
feat: Move spec url to versioned path
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Nov 6, 2024
1 parent e22ec16 commit e871b23
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/main/kotlin/app/revanced/api/configuration/HTTP.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.koin.ktor.ext.get
import kotlin.time.Duration.Companion.minutes

fun Application.configureHTTP() {
val configurationRepository = get<ConfigurationRepository>()
val configuration = get<ConfigurationRepository>()

install(CORS) {
HttpMethod.DefaultMethods.minus(HttpMethod.Options).forEach(::allowMethod)
Expand All @@ -22,7 +22,7 @@ fun Application.configureHTTP() {

allowCredentials = true

configurationRepository.corsAllowedHosts.forEach { host ->
configuration.corsAllowedHosts.forEach { host ->
allowHost(host = host, schemes = listOf("https"))
}
}
Expand Down
16 changes: 13 additions & 3 deletions src/main/kotlin/app/revanced/api/configuration/OpenAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app.revanced.api.configuration

import app.revanced.api.command.applicationVersion
import app.revanced.api.configuration.repository.ConfigurationRepository
import io.bkbn.kompendium.core.attribute.KompendiumAttributes
import io.bkbn.kompendium.core.plugin.NotarizedApplication
import io.bkbn.kompendium.json.schema.KotlinXSchemaConfigurator
import io.bkbn.kompendium.oas.OpenApiSpec
Expand All @@ -12,13 +13,22 @@ import io.bkbn.kompendium.oas.info.License
import io.bkbn.kompendium.oas.security.BearerAuth
import io.bkbn.kompendium.oas.server.Server
import io.ktor.server.application.*
import org.koin.ktor.ext.get
import io.ktor.server.response.*
import io.ktor.server.routing.*
import java.net.URI
import org.koin.ktor.ext.get as koinGet

internal fun Application.configureOpenAPI() {
val configurationRepository = get<ConfigurationRepository>()
val configuration = koinGet<ConfigurationRepository>()

install(NotarizedApplication()) {
openApiJson = {
route("/${configuration.apiVersion}/openapi.json") {
get {
call.respond(application.attributes[KompendiumAttributes.openApiSpec])
}
}
}
spec = OpenApiSpec(
info = Info(
title = "ReVanced API",
Expand All @@ -41,7 +51,7 @@ internal fun Application.configureOpenAPI() {
),
).apply {
servers += Server(
url = URI(configurationRepository.endpoint),
url = URI(configuration.endpoint),
description = "ReVanced API server",
)
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/app/revanced/api/configuration/Routing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ internal fun Application.configureRouting() = routing {
extensions("json", "asc")
}

swagger(pageTitle = "ReVanced API", path = "/")
redoc(pageTitle = "ReVanced API", path = "/redoc")
val specUrl = "/${configuration.apiVersion}/openapi.json"
swagger(pageTitle = "ReVanced API", path = "/", specUrl = specUrl)
redoc(pageTitle = "ReVanced API", path = "/redoc", specUrl = specUrl)
}

0 comments on commit e871b23

Please sign in to comment.