How would you guys go about documenting example er...
# http4k
j
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
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
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
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
So there is no reference to baseUri as some link that gets made when a contract is bound?
Within contract definition
d
nope
j
:(
Thanks for the info!
d
np
j
But the error type URI is not the service URI, so you don't need the service URI
j
Yes I've noticed this also :)
So problem is moot
d
🍻
j
😄
j
It's a namespace, not telling anything about where a service may exist