I’ve created an interceptor that generates a new request-id and adds an additional X-Request-Id header to the response. And I want to see the header info in the Swagger response definitions.
The endpoint.out(header(...)) option is not suitable, it will add a new dynamic or fixed header value to the response. I’ve tried a hack to use a fixed header and substitute it in the interceptor with the real value. It works, but it’s still an ugly hack and my tests based on the sttp-client are failing since the expected fixed header value is not equal to the generated value.
Still a workaround, but how about an optional header? (.endpoint.out(header[Option[T]](...)). This may help with the tests and expectations. The specification will not be accurate, but maybe it’s acceptable in this direction, where required: false but in reality it’s always set.
If you have a list of endpoints for which you want to generate documentation, you can modify that list before passing it to the documentation interpreter. E.g.:
val myEndpoints: List[AnyEndpoint] = ???
val myEndpointsWithHeader = myEndpoints.map(_.out(header(...)))
val swaggerEndpoints = SwaggerInterpreter().fromEndpoints[Future](myEndpointsWithHeader, "My App", "1.0")