zashto
zashto

Reputation: 13

Spring Cloud Gateway API exposure of united OpenAPI specification

Our application use microservice architecture and we use Java/Spring for the implementation. Recently we started the integration with other systems. The requirement is to provide an OpenAPI specification for the endpoints that we expose.

For our entry point we use Spring Cloud Gateway and we just forward the requests, nothing special. The problem is that we have Swagger that groups APIs for every microservice but we can't find a way to create dynamically one OpenAPI specification (or Swagger page) that unites endpoints that we are interested of. Keep in mind that we do not expose everything from our microservices, so our pure forward to particular microservice Swagger page is not fully correct.

My question is, is there a way to infer what we expose from our services, Spring Gateway has this mappings, and describe it dynamically as OpenAPI specification?

Such functionality has Spring Cloud Gateway for VMWare Tanzu - OpenAPI version 3 auto-generated documentation

PS Of course we could create and maintain OpenAPI specification manually and serve it, but this is not the case.

Upvotes: 0

Views: 37

Answers (1)

zashto
zashto

Reputation: 13

We start using this library: https://github.com/jbretsch/openapi-route-definition-locator

In the configuration file you can point out the locations of the micro services OpenAPI specification. In this way the Spring Gateway collects from many services and expose all defined API endpoints.

## Get OpenAPI specification for dynamic route mapping
openapi-route-definition-locator:
  services:
    - id: replenishment
      uri: ${REPLENISHMENT_SERVICE_API:var_REPLENISHMENT_SERVICE_API_undefined}
      openapi-definition-uri: /OpenApi.yml

    - id: customer-configuration
      uri: ${CUSTOMER_CONFIGURATION_API:var_CUSTOMER_CONFIGURATION_API_undefined}
      openapi-definition-uri: /OpenApi.yml

Unfortunately, the library to not create an united OpenAPI spec.

PS In the future releases you can use rules to restrict endpoints exposure. See following feature request: https://github.com/jbretsch/openapi-route-definition-locator/issues/12

Upvotes: 0

Related Questions