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/06/01 17:08:00 UTC

[jira] (CAMEL-22116) camel-openapi-validator doesn't work for contract-first api's with Spring Boot

    [ https://issues.apache.org/jira/browse/CAMEL-22116 ]


    Bjorn Beskow deleted comment on CAMEL-22116:
    --------------------------------------

was (Author: beskow):
Still doesn't work when server.servlet.context-path is non-empty.

> camel-openapi-validator doesn't work for contract-first api's with Spring Boot
> ------------------------------------------------------------------------------
>
>                 Key: CAMEL-22116
>                 URL: https://issues.apache.org/jira/browse/CAMEL-22116
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-spring-boot, rest
>    Affects Versions: 4.10.4, 4.11.0, 4.12.0
>            Reporter: Bjorn Beskow
>            Assignee: Claus Ibsen
>            Priority: Minor
>             Fix For: 4.8.8, 4.10.6, 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 400 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 by SpringBootPlatformHttpConsumer, 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.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)