ullgren commented on code in PR #26203:
URL: https://github.com/apache/camel/pull/26203#discussion_r4095263919
##########
components/camel-rest-openapi/src/main/docs/rest-openapi-component.adoc:
##########
@@ -202,6 +202,100 @@ If any of the validation checks fail, then a
`RestOpenApiValidationException` is
has a `getValidationErrors` method that returns the error messages from the
validator.
+== Unmatched requests
+
+By default, an incoming request that does not match any operation in the
OpenAPI specification is answered by the
+HTTP layer of the runtime, with HTTP 404, and a request that matches a path
but not the HTTP method is answered
+with HTTP 405 and an `Allow` header listing the allowed methods.
+
+To let Camel answer these requests instead, set the `unmatchedRequestHandling`
option to `camel` on the
+rest-openapi consumer endpoint or via the rest DSL `openApi` section. The
rest-openapi component then registers a
+catch-all for the API base path on the HTTP layer so requests that match no
operation are routed to Camel, where
+they are answered by the unmatched request handler.
+
+[tabs]
+====
+Java::
++
+[source,java]
+----
+from("rest-openapi:petstore-v3.json?missingOperation=ignore&unmatchedRequestHandling=camel")
+ .to("direct:businessLogic");
+
+// ... or using the rest DSL
+
+rest().openApi()
+ .specification("petstore-v3.json")
+ .missingOperation("ignore")
+ .unmatchedRequestHandling("camel");
+----
+
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: rest-openapi:petstore-v3.json
+ parameters:
+ missingOperation: ignore
+ unmatchedRequestHandling: camel
+ steps:
+ - to:
+ uri: direct:businessLogic
+
+# ... or using the rest DSL
+
+- rest:
+ openApi:
+ specification: petstore-v3.json
+ missingOperation: ignore
+ unmatchedRequestHandling: camel
+----
+====
+
+The option is supported by the built-in `platform-http` consumer component:
Camel Main when using
+xref:platform-http-vertx.adoc[camel-platform-http-vertx], and Spring Boot when
using the platform-http starter
+(`camel-platform-http-starter`). Other consumer components ignore the option.
+
+On Camel Main and Quarkus, the catch-all route is evaluated last on the HTTP
server, so it never shadows the
+operations of other APIs served by the same server, even when their base paths
are nested under this API.
+
+When the request has been routed to Camel, the response body (and headers) can
be customized by registering a
+bean in the xref:manual::registry.adoc[Registry] that implements the
`RestOpenApiUnmatchedRequestHandler` interface.
+The handler is called with the exchange, the status code (`404` or `405`) and
the list of allowed HTTP
+methods (empty for `404`), and can then set the response body, status code and
headers as needed.
+The handler can also be registered using a factory finder on the classpath.
This is done by adding a
+resource file
`META-INF/services/org/apache/camel/rest-openapi-unmatched-request-handler-factory`
+with the content `class=com.example.MyHandler`.
+
+A single handler bean in the registry takes precedence over a handler found
via the factory finder, which in
+turn takes precedence over the default handler. Regardless of how the handler
is registered *only one* handler
+is used: when two or more beans of this type are found in the registry, none
of them is used, instead the
Review Comment:
Rephrased to not include instead
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]