https://kotlinlang.org logo
Title
t

Tom Ellis

03/30/2019, 6:48 AM
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

dave

03/30/2019, 10:04 AM
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

Tom Ellis

03/30/2019, 10:20 AM
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

dave

03/30/2019, 10:32 AM
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

Tom Ellis

03/30/2019, 10:33 AM
yeah i thought about that too
d

dave

03/30/2019, 10:34 AM
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

Tom Ellis

03/30/2019, 10:34 AM
yes
d

dave

03/30/2019, 10:35 AM
so you're going to have to generate a schema based on the example kotlin class
(if you want to retain names)
t

Tom Ellis

03/30/2019, 10:35 AM
yeah i think we’re ok with that
d

dave

03/30/2019, 10:36 AM
ok - I'll unseal the HttpMessageMeta then
t

Tom Ellis

03/30/2019, 10:36 AM
thanks!
d

dave

03/30/2019, 10:36 AM
I was about to push out a release anyway today.
t

Tom Ellis

03/30/2019, 10:36 AM
oh nice! great timing 😄
thanks so much
d

dave

03/30/2019, 10:45 AM
releasing 3.129.0 now - all being well it should hit jcenter in 30, then maven in a couple of hours 🙂
🎉 1
👍 1
t

Tom Ellis

03/30/2019, 11:24 AM
hmm - `receiving`/`returning` actually takes ResponseMetas which i obv can’t extend.. is there another way i can pass my custom HttpMessageMeta through?
d

dave

03/30/2019, 11:42 AM
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

Tom Ellis

03/30/2019, 11:43 AM
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

dave

03/30/2019, 11:46 AM
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

Tom Ellis

03/30/2019, 11:46 AM
or that
🙂
d

dave

03/30/2019, 3:31 PM
@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

Tom Ellis

04/09/2019, 1:59 AM
just btw - this worked great! thanks mate
🤘 1