diff --git a/lapis2/src/main/kotlin/org/genspectrum/lapis/controller/Headers.kt b/lapis2/src/main/kotlin/org/genspectrum/lapis/controller/Headers.kt index a2189423..de8ce02d 100644 --- a/lapis2/src/main/kotlin/org/genspectrum/lapis/controller/Headers.kt +++ b/lapis2/src/main/kotlin/org/genspectrum/lapis/controller/Headers.kt @@ -10,4 +10,5 @@ object LapisMediaType { const val TEXT_CSV = "text/csv" const val TEXT_CSV_WITHOUT_HEADERS = "text/csv;$HEADERS_ACCEPT_HEADER_PARAMETER=false" const val TEXT_TSV = "text/tab-separated-values" + const val APPLICATION_YAML = "application/yaml" } diff --git a/lapis2/src/main/kotlin/org/genspectrum/lapis/controller/InfoController.kt b/lapis2/src/main/kotlin/org/genspectrum/lapis/controller/InfoController.kt index 4bfbb567..b5b2436a 100644 --- a/lapis2/src/main/kotlin/org/genspectrum/lapis/controller/InfoController.kt +++ b/lapis2/src/main/kotlin/org/genspectrum/lapis/controller/InfoController.kt @@ -3,6 +3,7 @@ package org.genspectrum.lapis.controller import io.swagger.v3.oas.annotations.Operation import org.genspectrum.lapis.config.DatabaseConfig import org.genspectrum.lapis.config.ReferenceGenome +import org.genspectrum.lapis.controller.LapisMediaType.APPLICATION_YAML import org.genspectrum.lapis.model.SiloQueryModel import org.genspectrum.lapis.request.LapisInfo import org.springframework.http.MediaType @@ -28,9 +29,9 @@ class InfoController( return LapisInfo(siloInfo.dataVersion) } - @GetMapping(DATABASE_CONFIG_ROUTE, produces = [MediaType.APPLICATION_JSON_VALUE]) + @GetMapping(DATABASE_CONFIG_ROUTE, produces = [MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML]) @Operation(description = DATABASE_CONFIG_ENDPOINT_DESCRIPTION) - fun getDatabaseConfig(): DatabaseConfig = databaseConfig + fun getDatabaseConfigAsJson(): DatabaseConfig = databaseConfig @GetMapping(REFERENCE_GENOME_ROUTE, produces = [MediaType.APPLICATION_JSON_VALUE]) @Operation(description = REFERENCE_GENOME_ENDPOINT_DESCRIPTION) diff --git a/lapis2/src/main/kotlin/org/genspectrum/lapis/controller/YamlHttpMessageConverter.kt b/lapis2/src/main/kotlin/org/genspectrum/lapis/controller/YamlHttpMessageConverter.kt new file mode 100644 index 00000000..7242fdc8 --- /dev/null +++ b/lapis2/src/main/kotlin/org/genspectrum/lapis/controller/YamlHttpMessageConverter.kt @@ -0,0 +1,13 @@ +package org.genspectrum.lapis.controller + +import org.genspectrum.lapis.util.YamlObjectMapper +import org.springframework.http.MediaType +import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter +import org.springframework.stereotype.Component + +@Component +class YamlHttpMessageConverter(yamlObjectMapper: YamlObjectMapper) : + AbstractJackson2HttpMessageConverter( + yamlObjectMapper.objectMapper, + MediaType.parseMediaType(LapisMediaType.APPLICATION_YAML), + ) diff --git a/lapis2/src/test/kotlin/org/genspectrum/lapis/controller/InfoControllerTest.kt b/lapis2/src/test/kotlin/org/genspectrum/lapis/controller/InfoControllerTest.kt index fcf23a47..a99925ed 100644 --- a/lapis2/src/test/kotlin/org/genspectrum/lapis/controller/InfoControllerTest.kt +++ b/lapis2/src/test/kotlin/org/genspectrum/lapis/controller/InfoControllerTest.kt @@ -2,13 +2,16 @@ package org.genspectrum.lapis.controller import com.ninjasquad.springmockk.MockkBean import io.mockk.every +import org.genspectrum.lapis.controller.LapisMediaType.APPLICATION_YAML import org.genspectrum.lapis.model.SiloQueryModel import org.genspectrum.lapis.response.InfoData +import org.hamcrest.Matchers.startsWith import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc import org.springframework.boot.test.context.SpringBootTest import org.springframework.test.web.servlet.MockMvc +import org.springframework.test.web.servlet.result.MockMvcResultMatchers.content import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status @@ -40,6 +43,21 @@ class InfoControllerTest( .andExpect(jsonPath("\$.schema.metadata[0].type").value("string")) } + @Test + fun `GET databaseConfig as YAML`() { + val yamlStart = """ + --- + schema: + instanceName: "sars_cov-2_minimal_test_config" + opennessLevel: "OPEN" + """.trimIndent() + + mockMvc.perform(getSample(DATABASE_CONFIG_ROUTE).accept(APPLICATION_YAML)) + .andExpect(status().isOk) + .andExpect(content().contentType(APPLICATION_YAML)) + .andExpect(content().string(startsWith(yamlStart))) + } + @Test fun `GET referenceGenome`() { mockMvc.perform(getSample(REFERENCE_GENOME_ROUTE))