This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-jbang-examples.git


The following commit(s) were added to refs/heads/main by this push:
     new fba5f9c  chore: openapi-client turns on client request validation (#96)
fba5f9c is described below

commit fba5f9cb2041c7dacdff7e1a51093308c0cd5350
Author: Claus Ibsen <[email protected]>
AuthorDate: Sun Oct 4 16:34:35 2026 +0200

    chore: openapi-client turns on client request validation (#96)
    
    The rest-openapi client now validates each request against the contract
    before sending it (camel.component.rest-openapi.request-validation-enabled
    in application.properties): a call without a value for a path parameter, a
    required header or query parameter, or a required body is refused with a
    message naming what is missing, instead of going out with {sku} in the path.
    The path parameter check is CAMEL-25321 (Camel 4.23). The README's "Try
    changing" no longer claims that a reservation without qty is refused (the
    validation does not check the body against the schema).
    
    
    Claude-Session: https://claude.ai/code/session_01STT6whBgK1AqsSsUKrnE8m
    
    Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
---
 contracts/openapi-client/README.md              | 9 +++++++--
 contracts/openapi-client/application.properties | 4 ++++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/contracts/openapi-client/README.md 
b/contracts/openapi-client/README.md
index bee0624..5290ffe 100644
--- a/contracts/openapi-client/README.md
+++ b/contracts/openapi-client/README.md
@@ -44,6 +44,10 @@ can be repeated. `stock.api.url` in `application.properties` 
says where the serv
   `POST /api/stock/{sku}/reserve`. `host` is the server; `componentName: http` 
picks the HTTP client to use.
 - The path parameter `sku` is taken from the header of the same name; the 
request body is the message body,
   built here as the JSON the contract's `Reservation` schema describes.
+- Client request validation is on 
(`camel.component.rest-openapi.request-validation-enabled=true` in
+  `application.properties`): a call without a value for a path parameter, a 
required header or query parameter,
+  or a required body is refused before it is sent, with a message that names 
what is missing, instead of going out
+  with `{sku}` in the path.
 - The order id and SKU are also kept in exchange properties for the log, since 
the response replaces the body
   and headers are sent on the wire, as the `http-client` example explains.
 - A 409 or 400 from the server is an `HttpOperationFailedException`; the 
`onException` logs its status code
@@ -58,8 +62,9 @@ can be repeated. `stock.api.url` in `application.properties` 
says where the serv
 
 ## Try changing
 
-- Set `requestValidationEnabled: true` on the endpoint and send a reservation 
without `qty`: the client
-  refuses it before any HTTP call.
+- Remove the `sku` header before the call: the validation refuses it with 
"Path parameter 'sku' is required but
+  none found" before any HTTP call. Turn the validation off in 
`application.properties` and the request goes out
+  with `{sku}` in the path and gets a 404.
 - Point `stock.api.url` at a server that is not running and watch the 
connection error reach the error handler.
 - Replace the contract's server with a public one, 
`https://petstore3.swagger.io/api/v3/openapi.json`, and
   call `getPetById`.
diff --git a/contracts/openapi-client/application.properties 
b/contracts/openapi-client/application.properties
index cfc23ac..d64c81e 100644
--- a/contracts/openapi-client/application.properties
+++ b/contracts/openapi-client/application.properties
@@ -16,3 +16,7 @@
 # under the License.
 
 stock.api.url=http://localhost:8080
+
+# client request validation: a request without a required body, header, query 
or path parameter is refused before
+# it is sent (a line without a sku header would otherwise be sent as 
/stock/{sku}/reserve)
+camel.component.rest-openapi.request-validation-enabled=true

Reply via email to