https://kotlinlang.org logo
#http4k
Title
# http4k
r

Razvan

02/20/2021, 6:36 PM
Hi, in a contractRoute I use an object that contains a list of map. the OAS specification declares the map as a SingletonMap but that reference does not exist. there is a JS error in the swagger because of that.
heres the router:
Copy code
data class TestObj(val keys: List<Map<String, String>>)
    private val bodyTestLens = Body.auto<TestObj>("Object with map").toLens()

    private fun testRoute(): ContractRoute {
        val spec = "/test" meta {
            summary = "Test showing error on map object"
            tags += Tag("Test")
            returning(
                OK,
                bodyTestLens to TestObj(listOf(mapOf("testKey" to "testValue"))),
                "Okresponse",
                "TestObj"
            )
        } bindContract Method.GET

        return spec to testHandler()
    }
    fun testHandler(): HttpHandler = {
        Response(OK).with(
            bodyTestLens of TestObj(listOf(mapOf("responseKey" to "responseValue")))
        )
    }
The JS error
Copy code
Resolver error at paths./test.get.responses.200.content.application/json.schema.properties.keys.items.oneOf.0.$ref
Could not resolve reference: Not Found
The json definition of that object
Copy code
TestObj":{"properties":{"keys":{"items":{"oneOf":[{"$ref":"SingletonMap"}]},"example":[{"testKey":"testValue"}],"type":"array"}},"example":{"keys":[{"testKey":"testValue"}]},"type":"object","required":["keys"]}
No other declaration of
SingletonMap
in the JSON
If the object is not a list of map but just a map it works ok:
Copy code
data class TestObj(val keys: Map<String, String>)
Copy code
"TestObj":{"properties":{"keys":{"additionalProperties":{"properties":{"testKey":{"example":"testValue","type":"string"}},"example":{"testKey":"testValue"},"type":"object","required":["testKey"]},"type":"object"}
4 Views