You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2022/02/10 17:54:04 UTC

[GitHub] [camel-spring-boot] klease opened a new pull request #435: CAMEL-17535: Fix server URL in generated swagger UI.

klease opened a new pull request #435:
URL: https://github.com/apache/camel-spring-boot/pull/435


   Account for both possible spring context path and Camel REST context path.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-spring-boot] klease merged pull request #435: CAMEL-17535: Fix server URL in generated swagger UI.

Posted by GitBox <gi...@apache.org>.
klease merged pull request #435:
URL: https://github.com/apache/camel-spring-boot/pull/435


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-spring-boot] davsclaus commented on a change in pull request #435: CAMEL-17535: Fix server URL in generated swagger UI.

Posted by GitBox <gi...@apache.org>.
davsclaus commented on a change in pull request #435:
URL: https://github.com/apache/camel-spring-boot/pull/435#discussion_r804377056



##########
File path: components-starter/camel-springdoc-starter/src/main/java/org/apache/camel/springboot/springdoc/SpringdocAutoConfiguration.java
##########
@@ -150,6 +166,28 @@ private OpenAPI createOpenAPI(final CamelContext camelContext) throws Exception
                 .orElse(null);
     }
 
+    /**
+     * Return the basePath for the REST services
+     * @param springContextPath the spring context path if set or empty
+     * @param basePath The apiProperty "base.path" from the REST configuration
+     * @param contextPath the REST contextPath or null. 
+     * Used instead of basePath if both are non-null.
+     * @return the combined contextPath
+     */
+    private String getBasePath(String springContextPath, Object basePath, String contextPath) {
+        if (contextPath == null) {
+            contextPath = (String)basePath; // could still be null
+        }
+        if (contextPath != null && !contextPath.isEmpty()) {
+            return springContextPath + contextPath;
+        }
+        else {
+            // This will cause problems when using the Camel servlet as the REST component! 
+            LOG.warn("No REST context path set in Camel!");

Review comment:
       in Camel Rest-DSL

##########
File path: components-starter/camel-springdoc-starter/src/main/java/org/apache/camel/springboot/springdoc/SpringdocAutoConfiguration.java
##########
@@ -124,14 +130,24 @@ private OpenAPI createOpenAPI(final CamelContext camelContext) throws Exception
 
         final BeanConfig bc = new BeanConfig();
         final Info info = new Info();
-
         final RestConfiguration rc = camelContext.getRestConfiguration();
-        initOpenApi(bc, info, Optional.ofNullable(rc.getApiProperties()).orElseGet(HashMap::new));
+        Map<String, Object> apiProps = Optional.ofNullable(rc.getApiProperties()).orElseGet(HashMap::new);
+        initOpenApi(bc, info, apiProps, 
+                getBasePath(springContextPath, apiProps.get("base.path"), rc.getContextPath()));
 
         final OasDocument openApi = reader.read(camelContext, rests, bc, null, camelContext.getClassResolver());
         if (!rc.isApiVendorExtension()) {
             clearVendorExtensions(openApi);
         }
+        // Set relative path in URL if basepath is set
+        if (bc.getBasePath()!=null && !bc.getBasePath().isEmpty() && openApi.is3xDocument()) {
+            for (Server server : ((Oas30Document)openApi).getServers()) {
+                if (server.url.endsWith(bc.getBasePath())) {
+                    LOG.info("Setting relative URL " + bc.getBasePath());

Review comment:
       Can this logging message be improved such as "Setting Server URL in ApiDoc to base path: {}"




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-spring-boot] klease commented on pull request #435: CAMEL-17535: Fix server URL in generated swagger UI.

Posted by GitBox <gi...@apache.org>.
klease commented on pull request #435:
URL: https://github.com/apache/camel-spring-boot/pull/435#issuecomment-1035238799


   If it looks OK to you Claus (or others), I'll merge it.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org