参考:https://micronaut-projects.github.io/micronaut-openapi/latest/guide/index.html
开启swagger配置需要使用micronaut.openapi.views.spec配置,如下
micronaut.openapi.views.spec=redoc.enabled=true,rapidoc.enabled=true,swagger-ui.enabled=true,swagger-ui.theme=flattop
发现配置了没什么用,后面查资料才知道这个只是支持1.3.x版本(目前还没有正式发布)
只能用过渡方案:
1. 在class path下创建目录swagger,并在swagger目录中新建index.html文件
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>OpenAPI documentation</title> <link rel="icon" type="image/png" href="https://unpkg.com/swagger-ui-dist@3.23.0/favicon-32x32.png"> <link rel="stylesheet" type="text/css" href="https://unpkg.com/swagger-ui-dist@3.23.0/swagger-ui.css"> <script src="//unpkg.com/swagger-ui-dist@3.23.0/swagger-ui-standalone-preset.js"></script> <script src="//unpkg.com/swagger-ui-dist@3.23.0/swagger-ui-bundle.js"></script> </head> <body> <div id="swagger-ui"></div> <script> window.onload = function() { var ui = SwaggerUIBundle({ urls: [{ name: "API documentation", url: "/swagger/api-doc-0.0.yml" // TODO 设置你的api-doc文件 }], dom_id: ‘#swagger-ui‘, deepLinking: true, presets: [ SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset ], plugins: [ SwaggerUIBundle.plugins.DownloadUrl ], layout: "StandaloneLayout" }); window.ui = ui; } </script> </body> </html>
2. 设置配置文件
micronaut: router: static-resources: # swagger swagger: enabled: true paths: - classpath:META-INF/swagger - classpath:swagger mapping: /swagger/**
3. 请求http://localhost:8080/swagger
原文:https://www.cnblogs.com/lk568/p/12186458.html