Reputation: 3211
I am working with Grails 3.1.4 and I am having problems documenting my Controller classes with the Swagger Api.
grails -version
gives me this output:
| Grails Version: 3.1.4
| Groovy Version: 2.4.6
| JVM Version: 1.8.0_73
I tried to integrate Swagger into the project using these sources:
- https://grails.org/plugin/swaggydoc
- https://rahulsom.github.io/swaggydoc/
build.gradle
:compile 'io.swagger:swagger-core:1.5.7'
compile 'io.swagger:swagger-jaxrs:1.5.7'
compile "com.github.rahulsom:swaggydoc-commons:0.24.0"
compile "org.grails.plugins:swaggydoc:0.27.0"
build.gradle
:`jcenter()`
@Api(value = "myValue", description = "this controller does something")
@Path("/myapproot/myDomainClassX")
MyDomainClassXController{
@GET
@Path("/myFunction")
def myFunction(){
render "MyDomainClassXController, myFunction(), did something"
}
}
application.yml
I added:grails:
mime:
disable:
accept:
header:
userAgents: []
Config.groovy
which I do not have, so instead of writing:swaggydoc {
contact = "[email protected]"
description = "API description"
title = "My Swagger Doc for my awesome project"
apiVersion = "0.2cents"
}
Config.groovy
, I added the same text into the file application.yml
using the yml syntax:swaggydoc:
contact: "[email protected]"
description: "API Description"
title: "My Swagger Doc for my awesome project"
apiVersion: "0.2cents"
I am running my Grails application with the bootRun
task and browse to http://localhost:8080/myapproot/myDomainClassX/myFunction
and see the String "MyDomainClassXController, myFunction(), did something" in my browser.
When I browse to http://localhost:8080/myapproot/api
I get the "Page Not Found (404)" Error. Here i expected to see the magic of the Swagger annotations producing a documentation.
What did I do wrong in the configuration of the Swagger plugin mentioned in the sources?
Upvotes: 3
Views: 1210
Reputation: 571
If you are getting a 404 on /myapproot/api check your UrlMappings.groovy file.
Either leave this default mapping in there:
"/$controller/$action?/$id?(.$format)?"{
constraints {
// apply constraints here
}
}
or at least allow
get "/api/$action?"(controller: 'api')
That should let you at least hit the swaggy controller with that URL.
Upvotes: 0