1

I have a below project structure

enter image description here

Project product and API gateway share the common project as common. Since in the parent project settings.Gradle I have included the project as below

rootProject.name = 'src'
include 'common', 'fetebird-apigateway', 'fete-bird-product'

In the API gateway build.gradle I have included the below dependency

    dependencies {
        annotationProcessor("io.micronaut.openapi:micronaut-openapi:2.1.1")
        implementation("io.swagger.core.v3:swagger-annotations")
        implementation project(':common')
        }

In the product build.gradle I have include the below dependency

dependencies {
         annotationProcessor("io.micronaut.openapi:micronaut-openapi:2.1.1") 
         implementation("io.swagger.core.v3:swagger-annotations")
         implementation project(':common')

        }

When I run the command $ gradle build I can see the view is generated

enter image description here

Swagger expose end point

micronaut:
  application:
    name: feteBirdProduct
  server:
    port: 8083
  router:
    versioning:
      enabled: true
    static-resources:
      swagger:
        paths: classpath:META-INF/swagger
        mapping: /swagger/**
      swagger-ui:
        paths: classpath:META-INF/swagger/views/swagger-ui
        mapping: /swagger-ui/**

But when I access the URL

http://localhost:8084/swagger-ui/index.html

I can see the below message and I don't have any security enable

{"message":"Page Not Found","_links":{"self":{"href":"/swagger-ui/index.html","templated":false}}}

While debugging io.micronaut.web.router.resource.StaticResourceResolver. The public URL findResource(String name) return null in the BuiltinClassLoader.java

enter image description here

San Jaisy
  • 15,327
  • 34
  • 171
  • 290

3 Answers3

1

Not sure if you did, but you might need to expose the generated API docs as static resources with a YML config such as the following stated in the Micronaut OpenAPI docs):

micronaut:
    router:
        static-resources:
            swagger:
                paths: classpath:META-INF/swagger
                mapping: /swagger/**

Then you should be able to access them using a route such as: http://localhost:8080/swagger/views/swagger-ui/index.html.

In case you enable the security module, you might need to specify security rules for that URL using "intercept URL map", otherwise you might not be able to reach it:

micronaut:
  security:
    intercept-url-map:
      - pattern: /swagger/**
        http-method: GET
        access:
          - isAnonymous()
tcrespog
  • 31
  • 5
  • I already did this, In my yaml file, I already expose the swagger ui – San Jaisy Oct 19 '20 at 14:12
  • Could you share the config? In your question you said you were trying to access the docs through `http://localhost:8084/swagger-ui/index.html`, if the config is as I posted, then some path fragments are missing in the URL, it should read: `http://localhost:8084/swagger/views/swagger-ui/index.html`. – tcrespog Oct 19 '20 at 18:07
  • Updated the question with the config, please have a look – San Jaisy Oct 20 '20 at 01:45
  • You have versioning enabled. May you need a `default-version`? I'm not sure, I'm running out of ideas. You can also try debugging the `io.micronaut.web.router.resource.StaticResourceResolver` class in order to check if the requested resource is being found. – tcrespog Oct 20 '20 at 05:21
  • version is not an issue, can you please have a look at this repo https://github.com/anandjaisy/micronautMultiproject. you can run the API gateway project – San Jaisy Oct 20 '20 at 14:57
  • I've been able to run the `fetebird-apigateway` and I see no problems accessing the API docs. I've tried putting an extra `swagger-ui` mapping to `application.yml` and I still can access both. I had to remove the `fetebird-apigateway/settings.gradle` file and the app stops after a while, but until then I don't find any problems. – tcrespog Oct 21 '20 at 06:26
  • The issue is URL url = findResourceOnClassPath(name); on the BuildinClassLoader.java the URL is null – San Jaisy Nov 03 '20 at 05:27
0

The solution was to include the setting.gradle file of each project, however on Intellj if you navigate to the Gradle task and run the build, it will give you an error or if you run gradle run it give you an error

San Jaisy
  • 15,327
  • 34
  • 171
  • 290
0

Documentation says the default value for enabled flag is true but for some reason I had to set this value explicitly to display the swagger ui.

micronaut:
  router:
    static-resources:
      swagger:
        enabled: true  # docs says this is already the default value
        paths: classpath:META-INF/swagger
        mapping: /swagger/**
      swagger-ui:
        enabled: true  # but this only works if it is explicitly set
        paths: classpath:META-INF/swagger/views/swagger-ui
        mapping: /swagger-ui/**
xvronny
  • 84
  • 5