1

How would I enable swagger ui in jhipster generator for microservice application? I notice it only supports swagger for gateway, so how do I configure swagger ui so that it works on microservice application as well?

Configuration Progress

Added springfox-swagger2 and springfox-swagger-ui dependencies to pom.xml

<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.9.2</version>
    </dependency>

<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.9.2</version>
    </dependency>

Created this class and added to spring directory

import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(paths())
                .build();
    }

    // Describe your apis
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Swagger Sample APIs")
                .description("This page lists all the rest apis for Swagger Sample App.")
                .version("1.0-SNAPSHOT")
                .build();
    }

    // Only select apis that matches the given Predicates.
    private Predicate<String> paths() {
        // Match all paths except /error
        return Predicates.and(
            PathSelectors.regex("/.*"), 
            Predicates.not(PathSelectors.regex("/error.*"))
        );
    }
}
}
jche
  • 129
  • 2
  • 16
  • It's not configurable, you'll have to code it yourself. Any reason why you don't want to use the gateway? – Gaël Marziou Jul 13 '19 at 11:03
  • Is there instruction on how to add swagger ui to microservice application on jhipster generator? – jche Jul 18 '19 at 20:58
  • Yes read the springfox doc. And you did not answer my question. – Gaël Marziou Jul 18 '19 at 21:13
  • Regarding your question, I need to integrate swagger ui with microservice application for business needs. Is there a more specific instruction doc that caters towards adding swagger ui to microservice on jhipster? I've been looking at this post: https://github.com/jhipster/generator-jhipster/issues/2990, is this still relevant, because the issue was last updated in 2017. – jche Jul 18 '19 at 22:20
  • Ok, so I integrated swagger ui into microservice application on jhipster. But why does my localhost changed from localhost:8080 to localhost:8080/services/{package_name} after spring boot application started? – jche Jul 19 '19 at 06:00
  • Yes it is still relevant but mostly for development use case, for production it would not help due to low security. Could you clarify your business needs? – Gaël Marziou Jul 19 '19 at 08:05

0 Answers0