2

We're considering using grails 4.0.0 for our project, and i see that this new version has Micronaut as new parent application context, and that many Micronaut features are handled (seen in grails doc: http://docs.grails.org/latest/guide/introduction.html#micronautSupport)

We would like to use the Micronaut Swagger/OpenAPI documentation generator feature (https://micronaut-projects.github.io/micronaut-openapi/latest/guide/index.html) with grails, and would like to know if this is possible.

I tried it on a grails 4 project by adding the right dependecies and use the Micronaut and Swagger V3 annotations, but it does not work when i run the grails app (no *.yml generated in the the META-INF/swagger)

The micronaut dependecies:

    annotationProcessor "io.micronaut:micronaut-validation"
    annotationProcessor "io.micronaut.configuration:micronaut-openapi"
    compile "io.micronaut:micronaut-inject"
    compile "io.micronaut:micronaut-validation"
    compile "io.micronaut:micronaut-runtime"
    compile "io.swagger.core.v3:swagger-annotations"
    compile "io.micronaut:micronaut-http-client"
    compile "io.micronaut:micronaut-http-server-netty"

Thank you very much!

ztwal
  • 21
  • 2

2 Answers2

2

Adding the following under dependencies in build.gradle solved the issue for me (in Micronaut, not tested with Grails)

annotationProcessor "io.micronaut.configuration:micronaut-openapi:1.4.0"
compile "io.swagger.core.v3:swagger-annotations:2.1.1"
compileOnly "io.micronaut.configuration:micronaut-openapi:1.4.0"

notice the compileOnly "io.micronaut.configuration:micronaut-openapi:1.4.0" that is missing in your dependency declaration!

omixer
  • 21
  • 1
  • 6
  • @ztwal were you able to access swagger-ui by this implementation. please share the solution if working or any suggestions. thank you – Space Jun 02 '21 at 16:58
  • @omixer was this under Grails v4? – David Brown Mar 15 '22 at 18:02
  • @DavidBrown it was with Micronaut 1.1.0 which is Grails 4.0.0 parent application context! – omixer Mar 17 '22 at 04:28
  • @omixer unfortunately that doesn't mean it's going to work out of the box, as you'd need to allow Micronauts routing and views to work alongside grails URL mappings/controllers. Unless you know otherwise and have a working example of a grails app using micronauts swagger library. Else this is just an untested assumption. – David Brown Mar 18 '22 at 16:20
0

As Grails is Groovy I don't think that you need the "annotationProcessor" line. All of the Micronaut documentation that I've seen states that when using Groovy "annotationProcessor" is replaced by "compileOnly". I also found that I needed to provide the version numbers. I first copied the lines from a Micronaut project, which didn't have version numbers, and it didn't work.

sk8geek
  • 31
  • 5