-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add OpenAPI docs and cache to routes
- Loading branch information
Showing
14 changed files
with
572 additions
and
104 deletions.
There are no files selected for viewing
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
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
22 changes: 21 additions & 1 deletion
22
src/main/kotlin/app/revanced/api/configuration/Extensions.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,7 +1,27 @@ | ||
package app.revanced.api.configuration | ||
|
||
import io.bkbn.kompendium.core.plugin.NotarizedRoute | ||
import io.ktor.http.* | ||
import io.ktor.http.content.* | ||
import io.ktor.server.application.* | ||
import io.ktor.server.plugins.cachingheaders.* | ||
import io.ktor.server.response.* | ||
import kotlin.time.Duration | ||
|
||
suspend fun ApplicationCall.respondOrNotFound(value: Any?) = respond(value ?: HttpStatusCode.NotFound) | ||
internal suspend fun ApplicationCall.respondOrNotFound(value: Any?) = respond(value ?: HttpStatusCode.NotFound) | ||
|
||
internal fun ApplicationCallPipeline.installCache(maxAge: Duration) = | ||
installCache(CacheControl.MaxAge(maxAgeSeconds = maxAge.inWholeSeconds.toInt())) | ||
|
||
internal fun ApplicationCallPipeline.installNoCache() = | ||
installCache(CacheControl.NoCache(null)) | ||
|
||
internal fun ApplicationCallPipeline.installCache(cacheControl: CacheControl) = | ||
install(CachingHeaders) { | ||
options { _, _ -> | ||
CachingOptions(cacheControl) | ||
} | ||
} | ||
|
||
internal fun ApplicationCallPipeline.installNotarizedRoute(configure: NotarizedRoute.Config.() -> Unit = {}) = | ||
install(NotarizedRoute(), configure) |
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,52 @@ | ||
package app.revanced.api.configuration | ||
|
||
import app.revanced.api.command.applicationVersion | ||
import io.bkbn.kompendium.core.plugin.NotarizedApplication | ||
import io.bkbn.kompendium.json.schema.KotlinXSchemaConfigurator | ||
import io.bkbn.kompendium.oas.OpenApiSpec | ||
import io.bkbn.kompendium.oas.component.Components | ||
import io.bkbn.kompendium.oas.info.Contact | ||
import io.bkbn.kompendium.oas.info.Info | ||
import io.bkbn.kompendium.oas.info.License | ||
import io.bkbn.kompendium.oas.security.BasicAuth | ||
import io.bkbn.kompendium.oas.security.BearerAuth | ||
import io.bkbn.kompendium.oas.server.Server | ||
import io.ktor.server.application.* | ||
import java.net.URI | ||
|
||
internal fun Application.configureOpenAPI() { | ||
install(NotarizedApplication()) { | ||
spec = { | ||
OpenApiSpec( | ||
info = Info( | ||
title = "Revanced API", | ||
version = applicationVersion, | ||
description = "API server for ReVanced.", | ||
contact = Contact( | ||
name = "ReVanced", | ||
url = URI("https://revanced.app"), | ||
email = "[email protected]", | ||
), | ||
license = License( | ||
name = "AGPLv3", | ||
url = URI("https://github.com/ReVanced/revanced-api/blob/main/LICENSE"), | ||
), | ||
), | ||
components = Components( | ||
securitySchemes = mutableMapOf( | ||
"bearer" to BearerAuth(), | ||
"basic" to BasicAuth(), | ||
), | ||
), | ||
|
||
).apply { | ||
servers += Server( | ||
url = URI("https://api.revanced.app"), | ||
description = "ReVanced API server.", | ||
) | ||
} | ||
} | ||
|
||
schemaConfigurator = KotlinXSchemaConfigurator() | ||
} | ||
} |
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
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
Oops, something went wrong.