From 340f2acf08ae49d6f9fb1965f1971fd22e21f618 Mon Sep 17 00:00:00 2001 From: Jonas Kellerer Date: Thu, 8 Feb 2024 15:56:13 +0100 Subject: [PATCH] feat: add access key parameter to /sample/info and remove downloadAsFile --- .../openApi/AccessKeyParameterCustomizer.kt | 41 +++++++++++++++++++ .../DownloadAsFileParameterCustomizer.kt | 13 +++++- .../genspectrum/lapis/openApi/OpenApiDocs.kt | 8 +--- .../org/genspectrum/lapis/openApi/Schemas.kt | 6 +++ 4 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 lapis2/src/main/kotlin/org/genspectrum/lapis/openApi/AccessKeyParameterCustomizer.kt diff --git a/lapis2/src/main/kotlin/org/genspectrum/lapis/openApi/AccessKeyParameterCustomizer.kt b/lapis2/src/main/kotlin/org/genspectrum/lapis/openApi/AccessKeyParameterCustomizer.kt new file mode 100644 index 00000000..15596284 --- /dev/null +++ b/lapis2/src/main/kotlin/org/genspectrum/lapis/openApi/AccessKeyParameterCustomizer.kt @@ -0,0 +1,41 @@ +package org.genspectrum.lapis.openApi + +import io.swagger.v3.oas.models.OpenAPI +import io.swagger.v3.oas.models.parameters.Parameter +import org.genspectrum.lapis.config.DatabaseConfig +import org.genspectrum.lapis.config.OpennessLevel +import org.genspectrum.lapis.controller.ACCESS_KEY_PROPERTY +import org.genspectrum.lapis.controller.INFO_ROUTE +import org.springdoc.core.customizers.OpenApiCustomizer +import org.springframework.stereotype.Component + +@Component +class AccessKeyParameterCustomizer( + private val databaseConfig: DatabaseConfig, +) : OpenApiCustomizer { + companion object { + private val PATH_WITH_ACCESS_KEY_PARAMETER = listOf( + "/sample$INFO_ROUTE", + ) + } + + override fun customise(openApi: OpenAPI) { + if (databaseConfig.schema.opennessLevel == OpennessLevel.OPEN) { + return + } + + for ((_, path) in openApi.paths.filter { (url, _) -> + PATH_WITH_ACCESS_KEY_PARAMETER.any { + url.startsWith(it) + } + }) { + path.get.addParametersItem( + Parameter() + .`in`("query") + .name(ACCESS_KEY_PROPERTY) + .description(ACCESS_KEY_DESCRIPTION) + .schema(accessKeySchema()), + ) + } + } +} diff --git a/lapis2/src/main/kotlin/org/genspectrum/lapis/openApi/DownloadAsFileParameterCustomizer.kt b/lapis2/src/main/kotlin/org/genspectrum/lapis/openApi/DownloadAsFileParameterCustomizer.kt index 2a7acfba..7c0b73c6 100644 --- a/lapis2/src/main/kotlin/org/genspectrum/lapis/openApi/DownloadAsFileParameterCustomizer.kt +++ b/lapis2/src/main/kotlin/org/genspectrum/lapis/openApi/DownloadAsFileParameterCustomizer.kt @@ -3,13 +3,24 @@ package org.genspectrum.lapis.openApi import io.swagger.v3.oas.models.OpenAPI import io.swagger.v3.oas.models.parameters.Parameter import org.genspectrum.lapis.controller.DOWNLOAD_AS_FILE_PROPERTY +import org.genspectrum.lapis.controller.INFO_ROUTE import org.springdoc.core.customizers.OpenApiCustomizer import org.springframework.stereotype.Component @Component class DownloadAsFileParameterCustomizer : OpenApiCustomizer { + companion object { + private val PATH_WITHOUT_DOWNLOAD_AS_FILE = listOf( + "/sample$INFO_ROUTE", + ) + } + override fun customise(openApi: OpenAPI) { - for ((_, path) in openApi.paths.filter { (url, _) -> url.startsWith("/sample") }) { + for ((_, path) in openApi.paths.filter { (url, _) -> + url.startsWith("/sample") && !PATH_WITHOUT_DOWNLOAD_AS_FILE.any { + url.startsWith(it) + } + }) { path.get.addParametersItem( Parameter() .`in`("query") diff --git a/lapis2/src/main/kotlin/org/genspectrum/lapis/openApi/OpenApiDocs.kt b/lapis2/src/main/kotlin/org/genspectrum/lapis/openApi/OpenApiDocs.kt index 1f3f29db..35670138 100644 --- a/lapis2/src/main/kotlin/org/genspectrum/lapis/openApi/OpenApiDocs.kt +++ b/lapis2/src/main/kotlin/org/genspectrum/lapis/openApi/OpenApiDocs.kt @@ -354,13 +354,7 @@ private fun getAggregatedResponseProperties(filterProperties: Map