https://kotlinlang.org logo
Title
j

Jim

10/15/2021, 1:19 PM
How would you guys go about documenting example error responses in the following format: https://datatracker.ietf.org/doc/html/rfc7807 using the Contract module meta tags? The error response would include the complete path. Which you might not know when setting the meta info using returning() Because the contract might be composed at other places. To clarify: the actual response formatting is easy using the ErrorResponseRenderer. This is purely about generating / defining correct examples without hard coupling spec to code.
d

dave

10/15/2021, 1:25 PM
tricky - you'd need to put this into a Filter that wrapped your Contract. Then use some token replacement in the body to modify the response.
(you need access to the request and response at the same time so a filter is the only way)
j

Jim

10/15/2021, 1:28 PM
I am not talking about the actual responses. But specifically examples to provide the meta tag for the openapi documentation
The actual responses are done by filter and error rendering
d

dave

10/15/2021, 1:29 PM
yes - and you're going to need to modify the response in the call which returns the API json. but the OpenApi rendering machinery doesn't have access to the request.
so just hardcode the uri in the example response as
%%%%URI_PATH%%%%
and then do string replacement if the path matches in the filter
j

Jim

10/15/2021, 1:39 PM
So there is no reference to baseUri as some link that gets made when a contract is bound?
Within contract definition
d

dave

10/15/2021, 1:40 PM
nope
j

Jim

10/15/2021, 1:40 PM
:(
Thanks for the info!
d

dave

10/15/2021, 1:45 PM
np
j

James Richardson

10/15/2021, 2:21 PM
But the error type URI is not the service URI, so you don't need the service URI
j

Jim

10/15/2021, 2:21 PM
Yes I've noticed this also :)
So problem is moot
d

dave

10/15/2021, 2:22 PM
🍻
j

Jim

10/15/2021, 2:22 PM
😄
j

James Richardson

10/15/2021, 2:22 PM
It's a namespace, not telling anything about where a service may exist