2

Following the documentation over here - https://micronaut-projects.github.io/micronaut-openapi/1.3.4/guide/index.html

I configured my build.gradle to include compile time tasks for swagger yaml generation as follows-

tasks.withType(JavaCompile){
    options.encoding = "UTF-8"
    options.compilerArgs.add('-parameters')
    options.fork = true
    options.forkOptions.jvmArgs << '-Dmicronaut.openapi.views.spec=rapidoc.enabled=true,swagger-ui.enabled=true,swagger-ui.theme=flattop'
}

This is how my application.yaml looks like-

micronaut:
  server:
    port: 9090
    cors:
      enabled: true
  router:
    static-resources:
      swagger:
        paths: classpath:META-INF/swagger
        mapping: /swagger/**
      redoc:
        paths: classpath:META-INF/swagger/views/redoc
        mapping: /redoc/**
      rapidoc:
        paths: classpath:META-INF/swagger/views/rapidoc
        mapping: /rapidoc/**
      swagger-ui:
        paths: classpath:META-INF/swagger/views/swagger-ui
        mapping: /swagger-ui/**

Like the doc said, I also annotated by Application.java as shown below-

package com.api.backend;

import io.micronaut.runtime.Micronaut;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.info.Contact;
import io.swagger.v3.oas.annotations.info.Info;

@OpenAPIDefinition(
    info = @Info(
            title = "API Backend",
            version = "0.0",
            description = "API backend"
    )
)
public class Application {

    public static void main(String[] args) {
        Micronaut.run(Application.class);
    }
}

After doing all this, when I try to open http://localhost:9090/swagger/api-backend-0.0.yaml it opens the generated open API spec yaml. However, if I try opening http://localhost:9090/swagger-ui/, I get a 404.

Can anyone help me figure out the problem or suggest an alternative?

Abhishek
  • 681
  • 1
  • 6
  • 25
  • May I know is this issue solved somehow? I am having the same problem. I see yaml file & index.html files generated. But seeing 401 error when trying to access the swagger-ui – Buddha Jun 09 '20 at 14:13
  • My issue is not solved, however, 401 indicates credential problem. Try whitelisting swagger URL pattern. – Abhishek Jun 11 '20 at 13:59
  • Thanks for the update @Abhishek. I came to know the issue because of security enabled for the service. Here is another question I asked: https://stackoverflow.com/questions/62286864/micronaut-gradle-java-swagger-integration-views-not-accessible-with-securi . If you have any idea on this issue, please answer – Buddha Jun 11 '20 at 14:10
  • Did you ultimately solve this issue? – David Brown Mar 15 '22 at 17:27

3 Answers3

2

Can you add the below code and check, since all the files are inside the swagger-ui

  router:
    static-resources:
      default:
        enabled: true
        mapping: /**
        paths: classpath:swagger
      swagger:
        paths: classpath:META-INF/swagger
        mapping: /swagger/**
      swagger-ui:
        paths: classpath:META-INF/swagger/views/swagger-ui
        mapping: /swagger-ui/**
San Jaisy
  • 15,327
  • 34
  • 171
  • 290
0

All the steps looks correct to me.

Could you please check that after you build your project, is index.html file is created under META-INF/swagger/views/swagger-ui in your artifact.

From maven perspective, we see this in under target folder after running mvn compile as: target/classes/META_INF/swagger/views/swagger-ui

  • Apologies for delayed response. I have checked this. `index.html` file is present in the folder mentioned by you. – Abhishek May 13 '20 at 19:59
0

The configs looks ok , swagger-ui should be available in browser at http://localhost:8080/swagger-ui

Jimmy Obonyo Abor
  • 7,335
  • 10
  • 43
  • 71