Search code examples
microservicesjhipsterswagger-uiapi-gatewayopenapi-generator

API-first rest endpoint not listed in jhipster-gateway API section (swagger-ui)


Using jhipster 5.7.2

I created an api-gateway, and two micro-services. In the first one, I created an entity and it works perfectly behind the gateway. The gateway displays the api endpoints for the generated entity.

I generated the second micro-service but this time I had already an api defined in a yml file so I chose 'API-first'. My api was defined using open-api 3. I successfully generated the code for my api, using the instructions there, and tested calling direcly my micro-service endpoint using curl : it worked as expected at this point.

The problem : when I put that micro-service behind the gateway, the gateway does not see the api. When I go to the api menu, my micro-service shows in the dropdown but when I select it, it shows no endpoints.

One weird thing I found while searching is that when I call the following url on my micro-service directly : http://localhost:8082/v2/api-docs (as pointed in the 'welcome page' of the micro-service), I get :

{"swagger":"2.0","info":{"description":"my micro-service API documentation","version":"0.0.1","title":"api-first micro-service API","contact":{},"license":{}},"host":"localhost:8082","basePath":"/"}

It says 'swagger 2.0' when my yml file declared openapi 3.0.1. I searched and found this issue, which says :

Swagger UI very old version (2.2.10) is used which does not provide the support for Open API

I though openapi was the problem, so I rewrote the yml file to swagger 2.0 and finally I have the same exact problem : micro-service API works but seems not visible to the gateway.

I'm starting to wonder if it's a problem on my side only.


Solution

  • By default, JHipster configures Swagger to only list API endpoints beginning with api. This is configured in application.yml, change default-include-pattern to include other paths. For example, to include endpoints beginning with either /api/ or /expires/, you can use the following:

    swagger:
        default-include-pattern: /(api|expires)/.*