[ 
https://issues.apache.org/jira/browse/CAMEL-22116?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Claus Ibsen updated CAMEL-22116:
--------------------------------
    Component/s: rest

> 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
>          Components: rest
>    Affects Versions: 4.10.4, 4.11.0
>            Reporter: Bjorn Beskow
>            Priority: Minor
>             Fix For: 4.13.0
>
>
> 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)

Reply via email to