ZuulProperties return no routes

3/26/2019

In am trying to create a consolidated Swagger UI for all my micro services in my Zuul Edge Service. The Edge Service is running in Kubernetes and has Service Discovery using Spring Cloud Kubernetes.

When querying actuator/endpoints, I see all my micro services.

However, when using ZuulProperties -> getRoutes().values() I just get an empty array.

Do I need to hardcode the routes in application.properties or is there a way to utilize the service discovery to dynamically fetch all the routes?

application.properties:

spring.application.name=gateway-service
eureka.client.enabled=false
zuul.sensitiveHeaders=
zuul.ignoreSecurityHeaders=false
management.endpoints.web.exposure.include=*
server.port=8080

swaggerconfig.java:

@Autowired
ZuulProperties properties;

@Primary
@Bean
public SwaggerResourcesProvider swaggerResourcesProvider() {
    return () -> {
        List<SwaggerResource> resources = new ArrayList<>();

        System.out.println("Zuul routes " + properties.getRoutes().values().toString());

        properties.getRoutes().values().stream().forEach(route -> 
                resources.add(createResource(route.getId(), "2.0")));
        return resources;
    };
}

private SwaggerResource createResource(String location, String version) {

    System.out.println("Location: " + location);
    System.out.println("Version: " + version);

    SwaggerResource swaggerResource = new SwaggerResource();
    swaggerResource.setName(location);
    swaggerResource.setLocation("/" + location + "/v2/api-docs");
    swaggerResource.setSwaggerVersion(version);
    return swaggerResource;
}   
-- Anders Lassen
java
kubernetes
netflix-zuul
swagger-2.0
swagger-ui

1 Answer

4/11/2019

ZuulProperties will get you your routes from application.properties, you should have something like:

zuul.routes.<some_service>.path = /<your_path>/**
zuul.routes.<some_service>.serviceId = <your_service_id>
...

But that will not answer your question, what you need is microservices swagger ui documentation, check this

-- Milenko Jevremovic
Source: StackOverflow