I wonder if it is possible to use http4k-api-opena...
# http4k
c
I wonder if it is possible to use http4k-api-openapi without reflection... is it?
Nevermind, I just read in the documentation that "If you are using OpenAPI contracts, the only current option is to use Jackson." (https://www.http4k.org/ecosystem/http4k/reference/json/)
This pulls in a lot of dependencies, for what is now a very small API. I was also not using any reflection until now (at least that i know of; but Jackson is reflection-heavy a.s.a.i.k.)
a
Yes. There's a limited reflection-less OpenApi renderer that works ok-ish:
OpenApi3ApiRenderer
. Just plug in a
Json
backend;
KotlinxSerialization
should work.
Copy code
contract {
    // ....

    renderer = OpenApi3(
        apiInfo = ApiInfo("My App", "1"),
        apiRenderer = OpenApi3ApiRenderer(KotlinxSerialization),
        json = KotlinxSerialization
    )
}
We've been wanting to overhaul the OpenApi renderer for a while to either accept any serialization backend or at least move away from Jackson. Jackson 3 is kind of forcing our hand.
c
I get
any
in the ReDoc for request and response bodies. The openapi.json contains:
Copy code
"requestBody": {
          "content": {
            "application/json": {
              "schema": {}
            }
          },
          "required": true
        },
        "responses": {},
no errors or otherwise hints on what adapters i'm missing... I'm not sure how to fix it.
a
Try a different JSON backend; it's not perfect by any means, and the bodies are the easiest place for it to get tripped up. As is noted,
kotlinx-serialization
has the worst compatibility with http4k. iirc, even it's
Json
adapter is flawed. Moshi is what I use. You can even manually exclude the
kotlin-reflect
dependency from the
http4k-format-moshi
module. It shouldn't be needed, since the renderer just uses Moshi as a
Json
.
c
Thanks a lot Andrew! I've got it to work but needed a little glue for that. I've published it in a Gist as it may be of value to you of other on the http4k team when working on a new implementation of the openAPI module: https://gist.github.com/cies/fbf8859226b140dfd79021be112f8515 Your pointer were very helpful in getting this to work.