Hi all,
I’m using Camel’s Rest DSL (with the servlet component) and generating an
OpenAPI specification via camel-openapi-java-starter
In one of my routes, I’d like to have *different content types for
different response codes* in the generated OpenAPI spec — specifically:
-
201 → application/json
-
400 → application/problem+json
Here’s a simplified version of my setup:
restConfiguration()
.component("servlet")
.bindingMode(RestBindingMode.json)
.dataFormatProperty("contentTypeHeader", "false")
.apiContextPath("/openapi");
And my route:
rest("/v1/public-announcements")
.post()
.id("create-public-announcement")
.type(CreatePublicAnnouncementRequest.class)
.responseMessage().code(201).message("Created")
.responseModel(CreateIncidentResponse.class).endResponseMessage()
.responseMessage().code(400).message("Bad Request")
.responseModel(ZoneApiErrorMessage.class).endResponseMessage()
.to("direct:createPublicAnnouncement");
This works fine at runtime — the HTTP responses have the correct
Content-Type headers —
but in the generated OpenAPI spec, both 201 and 400 responses are listed
with:
"content": {
"application/json": { ... }}
Is there a way in the Rest DSL or via OpenAPI configuration to override the
response content type per response (e.g. make the 400 response use
application/problem+json)?
Thanks in advance for any pointers!
— Laurin Niemeyer