[ 
https://issues.apache.org/jira/browse/CAMEL-17491?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17477332#comment-17477332
 ] 

Karen Lease commented on CAMEL-17491:
-------------------------------------

[~davsclaus] I found that when I remove the context path from the operations in 
the generated swagger, the camel-spring-boot-examples/rest-openapi-springdoc is 
broken because the generated server URL doesn't include the "/api".

The main reason for this is the following comment in 
SpringdocAutoConfiguration.java:
{code:java}
// Note: do not copy servers, since we use the spring-boot configured 
setting{code}
So the configured context path is ignored.
Maybe there is some other way to specify it in the spring-boot configuration, 
but so far the only way I found is to add an annotation in the spring-boot 
Application.java:
{code:java}
@io.swagger.v3.oas.annotations.OpenAPIDefinition(
        servers = {@Server(url = "http://localhost:8080/api";)}    
)
{code}
It seems to make more sense to use the information in the generated OpenAPI 
which uses the RestConfiguration instead of having to specify it separately. I 
tried this and it works. If the annotation is also present it overrides the 
values in the openapi servers configuration.
I also noticed that the BeanConfig passed to RestOpenApiReader.read() in 
SpringdocAutoConfiguration doesn't read the same values from the 
RestConfiguration as the code in the camel-openapi-java component, for example, 
it actually ignores the contextPath. I could fix this.

Any feedback?

> camel-openapi-java - Operation paths are incorrect if contextPath is set
> ------------------------------------------------------------------------
>
>                 Key: CAMEL-17491
>                 URL: https://issues.apache.org/jira/browse/CAMEL-17491
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-openapi-java
>    Affects Versions: 3.13.0, 3.14.0
>            Reporter: James Netherton
>            Assignee: Karen Lease
>            Priority: Major
>             Fix For: 3.15.0
>
>
> Consider this REST configuration:
> {code}
> restConfiguration()
>     .host("localhost")
>     .apiHost("localhost")
>     .contextPath("/api")
>     .port(8080)
>     .apiContextPath("/api-docs");
> rest("/service")
>     .get("/testing").description("Test Service")
>     .outType(String.class)
>     .route().setBody().constant("Hello World");
> {code}
> The 'paths' object in the generated OpenAPI document is incorrect. It should 
> not have the '/api' context path prefix.
> {code}
> {
>   "openapi" : "3.0.2",
>   "info" : { },
>   "servers" : [ {
>     "url" : "/api"
>   } ],
>   "paths" : {
>     "/api/service/testing" : {
>       "get" : {
>         "tags" : [ "/service" ],
>         "responses" : {
>           "200" : { }
>         },
>         "operationId" : "verb1",
>         "summary" : "Test Service"
>       }
>     }
>   },
>   "components" : { },
>   "tags" : [ {
>     "name" : "/service"
>   } ]
> }
> {code}
> The OpenAPI spec states: 
> "Unless specified otherwise, all properties that are URLs MAY be relative 
> references as defined by RFC3986. Relative references are resolved using the 
> URLs defined in the Server Object as a Base URI.".
> If you try to execute the service in the Swagger UI, then it tries to hit 
> http://localhost:8080/api/api/service/testing (duplicate /api/api in the 
> path).
> Maybe the code we had before CAMEL-17063 was implemented was more correct?



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to