Skip to content

Commit

Permalink
feat: also get database config from info controller as YAML
Browse files Browse the repository at this point in the history
  • Loading branch information
fengelniederhammer committed Mar 6, 2024
1 parent f52d68d commit cd6536d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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),
)
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit cd6536d

Please sign in to comment.