You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Bjorn Beskow (Jira)" <ji...@apache.org> on 2025/05/28 11:12:00 UTC
[jira] [Created] (CAMEL-22116) camel-openapi-validator doesn't work for contract-first api's
Bjorn Beskow created CAMEL-22116:
------------------------------------
Summary: camel-openapi-validator doesn't work for contract-first api's
Key: CAMEL-22116
URL: https://issues.apache.org/jira/browse/CAMEL-22116
Project: Camel
Issue Type: Bug
Affects Versions: 4.11.0, 4.10.4
Reporter: Bjorn Beskow
Using camel-openapi-validator with an contract-first api such as [https://github.com/apache/camel-spring-boot-examples/openapi-contract-first] results in an HTTP 404 for all endpoints:
{code:java}
> curl http://localhost:8080/api/v3/pet/1
Validation failed.
[ERROR][GET ] No API path found that matches request ''.{code}
This is caused by the CamelHttpPath set to '' by camel-platform-http, which is used to select endpoint from the openapi specification.
The "CamelPlatformHttpContextPath" is however correctly set, and hence the correct value for path can be calculated:
{code:java}
String path = exchange.getMessage().getHeader(Exchange.HTTP_PATH, String.class);
// Workaround for camel-platform-http which does not properly set HTTP_PATH header
if (StringUtils.isEmpty(path)) {
String uri = exchange.getMessage().getHeader(Exchange.HTTP_URI, String.class);
String contextPath = exchange.getMessage().getHeader("CamelPlatformHttpContextPath", String.class);
if (StringUtils.isNotEmpty(contextPath) && uri.startsWith(contextPath)) {
path = uri.substring(contextPath.length());
}
} {code}
With path correctly set, the corresponding endpoint can be found in the openapi specification, which corrects the problem.
I'll submit a merge request with the above patch.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)