You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by Pontus Ullgren <ul...@gmail.com> on 2026/08/31 08:20:50 UTC
Customize 404/405 response body when using REST OpenApi component
Hello,
We are using the REST OpenApi to publish rest services from a OAS (as
a consumer).
The OAS spec specifies that error responses, such as 400, 404 and so
on, should have a JSON body
that follows a specific schema.
Using a `RestClientRequestValidator` implementation we can achive this
for client request validation errors.
However when/if the client requests a path or a method on a path that
is not present in the OAS,
then there does not seem to be anyway to hook in and change the response body.
https://github.com/apache/camel/blob/main/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiProcessor.java#L128-L142
I would like to propose adding a new SPI, following the same pattern
as `RestClientRequestValidator` to make it possible to change the
response
produced when there is no match for the operation in the OAS.
My proposal is to create a new interface
```
public interface RestOpenApiUnmatchedRequestHandler {
/**
* Handles the incoming request that did not match any operation
in the OpenAPI specification.
*
* @param exchange the current exchange
* @param statusCode the HTTP status code (404 or 405)
* @param allowedMethods the list of allowed HTTP methods for the
requested path (empty for 404)
*/
void handle(Exchange exchange, int statusCode, List<String> allowedMethods);
}
```
And also a default handler that implements the current behaviour.
Does this sound like a resonable change ? If so I would be happy to
open a Jira issue and provide a PR with my proposed changes.
Best regards
Pontus Ullgren
Re: Customize 404/405 response body when using REST OpenApi component
Posted by Pontus Ullgren <ul...@gmail.com>.
Hi,
Issue created : https://issues.apache.org/jira/browse/CAMEL-24649
PR submitted:; https://github.com/apache/camel/pull/26203
// Pontus
On Sat, 5 Sept 2026 at 18:39, Claus Ibsen <cl...@gmail.com> wrote:
>
> Hi
>
> Yeah you are welcome to do that on the main branch
>
> On Mon, Aug 31, 2026 at 10:21 AM Pontus Ullgren <ul...@gmail.com> wrote:
>
> > Hello,
> >
> > We are using the REST OpenApi to publish rest services from a OAS (as
> > a consumer).
> >
> > The OAS spec specifies that error responses, such as 400, 404 and so
> > on, should have a JSON body
> > that follows a specific schema.
> >
> > Using a `RestClientRequestValidator` implementation we can achive this
> > for client request validation errors.
> >
> > However when/if the client requests a path or a method on a path that
> > is not present in the OAS,
> > then there does not seem to be anyway to hook in and change the response
> > body.
> >
> >
> > https://github.com/apache/camel/blob/main/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiProcessor.java#L128-L142
> >
> > I would like to propose adding a new SPI, following the same pattern
> > as `RestClientRequestValidator` to make it possible to change the
> > response
> > produced when there is no match for the operation in the OAS.
> >
> > My proposal is to create a new interface
> >
> > ```
> > public interface RestOpenApiUnmatchedRequestHandler {
> > /**
> > * Handles the incoming request that did not match any operation
> > in the OpenAPI specification.
> > *
> > * @param exchange the current exchange
> > * @param statusCode the HTTP status code (404 or 405)
> > * @param allowedMethods the list of allowed HTTP methods for the
> > requested path (empty for 404)
> > */
> > void handle(Exchange exchange, int statusCode, List<String>
> > allowedMethods);
> > }
> > ```
> >
> > And also a default handler that implements the current behaviour.
> >
> > Does this sound like a resonable change ? If so I would be happy to
> > open a Jira issue and provide a PR with my proposed changes.
> >
> > Best regards
> > Pontus Ullgren
> >
>
>
> --
> Claus Ibsen
Re: Customize 404/405 response body when using REST OpenApi component
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
Yeah you are welcome to do that on the main branch
On Mon, Aug 31, 2026 at 10:21 AM Pontus Ullgren <ul...@gmail.com> wrote:
> Hello,
>
> We are using the REST OpenApi to publish rest services from a OAS (as
> a consumer).
>
> The OAS spec specifies that error responses, such as 400, 404 and so
> on, should have a JSON body
> that follows a specific schema.
>
> Using a `RestClientRequestValidator` implementation we can achive this
> for client request validation errors.
>
> However when/if the client requests a path or a method on a path that
> is not present in the OAS,
> then there does not seem to be anyway to hook in and change the response
> body.
>
>
> https://github.com/apache/camel/blob/main/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiProcessor.java#L128-L142
>
> I would like to propose adding a new SPI, following the same pattern
> as `RestClientRequestValidator` to make it possible to change the
> response
> produced when there is no match for the operation in the OAS.
>
> My proposal is to create a new interface
>
> ```
> public interface RestOpenApiUnmatchedRequestHandler {
> /**
> * Handles the incoming request that did not match any operation
> in the OpenAPI specification.
> *
> * @param exchange the current exchange
> * @param statusCode the HTTP status code (404 or 405)
> * @param allowedMethods the list of allowed HTTP methods for the
> requested path (empty for 404)
> */
> void handle(Exchange exchange, int statusCode, List<String>
> allowedMethods);
> }
> ```
>
> And also a default handler that implements the current behaviour.
>
> Does this sound like a resonable change ? If so I would be happy to
> open a Jira issue and provide a PR with my proposed changes.
>
> Best regards
> Pontus Ullgren
>
--
Claus Ibsen