我正在使用Grails 3.1.4,我在使用Swagger Api记录我的Controller类时遇到问题。
grails -version
给了我这个输出:
| Grails Version: 3.1.4
| Groovy Version: 2.4.6
| JVM Version: 1.8.0_73
我尝试使用这些来源将Swagger集成到项目中: - 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"
我正在使用bootRun
任务运行我的Grails应用程序并浏览到http://localhost:8080/myapproot/myDomainClassX/myFunction
并在我的浏览器中看到字符串“MyDomainClassXController,myFunction(),做了些什么”。
当我浏览到http://localhost:8080/myapproot/api
时,我收到“找不到页面(404)”错误。在这里,我希望看到Swagger注释产生文档的神奇之处。
在源代码中提到的Swagger插件的配置中我做错了什么?
如果您在/ myapproot / api上获得404,请检查您的UrlMappings.groovy文件。
在此处保留此默认映射:
"/$controller/$action?/$id?(.$format)?"{
constraints {
// apply constraints here
}
}
或者至少允许
get "/api/$action?"(controller: 'api')
这应该让你至少用那个URL击中swaggy控制器。