hi there - i’m having a go at writing my own contr...
# http4k
t
hi there - i’m having a go at writing my own contract renderer, but most of the fields/methods on ContractRoute are internal meaning you can’t really get the info from the routes. Is there a particular reason for this? is it possible to relax these?
the contract route meta also currently provides a way to override the definition id - but could it be possible to provide a way to override the schema generation (the asSchema method of HttpMessageMeta) of a request/response as well?
d
There isn't a particular reason for these being internal, other than encapsulation to minimise the API surface. Obviously we want people to be able to implement their own renderers, so we can open them up no problem.
👍 1
@Tom Ellis Regarding
asSchema()
, can you clarify? The implementation of that extension method is entirely private inside
OpenAPI
, so I think it may be entirely irrelevant if you're implementing your own Renderer
t
for my renderer, i’d like to retain the parameter/response example/object type so i can generate the schema with the correct names - at the moment because when using `receiving`/`returning` the lens is immediately applied to the example to get json and put it in the request/response, it loses that information. it seems that’s also why the current OpenAPI renderer generates object names with object-
$hash
. We can’t use this as clients want to generate libraries using the swagger json, and the names that get generated obviously don’t play nicely with that
i guess i could add the example as a header on the Response/Request object when creating a ResponseMeta to pass it down
d
this is going to definitely be a bit trickier, as the definition of the ResponseMeta is totally disconnected from the Schema generation.
one option would be to unseal the
HttpMessageMeta
class and allow you to define your own implementation which had this option
(which is specific to your renderer)
t
yeah i thought about that too
d
the problem is that the JsonSchema generation as it stands won't help because it works on a JSON document and generates names for all the child-fields
t
yes
d
so you're going to have to generate a schema based on the example kotlin class
(if you want to retain names)
t
yeah i think we’re ok with that
d
ok - I'll unseal the HttpMessageMeta then
t
thanks!
d
I was about to push out a release anyway today.
t
oh nice! great timing 😄
thanks so much
d
releasing 3.129.0 now - all being well it should hit jcenter in 30, then maven in a couple of hours 🙂
🎉 1
👍 1
t
hmm - `receiving`/`returning` actually takes ResponseMetas which i obv can’t extend.. is there another way i can pass my custom HttpMessageMeta through?
d
hmm - that's trickier. And since ResponseMeta isn't currently open either... 😞
the requestmeta is also handled inconsistently compared to the responses so think it will warrant further investigation.
t
rats!
for now i may cheat and pass the examples in a map to my custom renderer, and use the defintion id as a key to the example object
d
temporarily, you could redefine ResponseMeta to be open locally - that will allow you to at least test your schema generation (which I suspect will be the meatiest piece of this)? The rest is going to need a rejiggle..
t
or that
🙂
d
@Tom Ellis I think I’ve managed to crack the problem. Have generified the route dsl code to use the
HttpMessageMeta<X>
instead of the sub types. So I think you should be good to implement your own now.
Releasing now in 3.130.0
Let us know how it goes and if you do anything you can feed back in to the lib that would be great. 🙃
👍 1
t
just btw - this worked great! thanks mate
metal 1