查询参数注释在Swagger中以身体参数生成?
我有一个使用Restlet Swagger Extention的雷神API应用程序,通过Swagger2SpecificationRestlet
生成Swagger JSON。
// route to generated swagger json
swagger2SpecificationRestlet.attach(router, "/docs");
我的路线是这样定义的:
router.attach("/path/{pathParam}", MyResource.class);
我已经在本地实施了Swagger-UI,并设置了初始化器URL,以读取/docs
的Swagger JSON。在包括所需路径参数输入的所有路由的所有路线上,UI的工作原理,但是查询参数的注释在没有其他定义的字段的情况下呈现为邮局(?)。参数输入:
"parameters": [
{
"name": "pathParam",
"in": "path",
"required": true,
"type": "string"
},
{
"in": "body",
"name": "body",
"required": false,
"schema": {
"type": "string"
}
],
带注释的我的资源方法:
@ApiOperation(
value="test desc",
httpMethod = "GET",
produces = "application/json",
notes="testing notes"
)
@Get("txt")
public String represent(
@ApiParam(name="queryParam", value = "testing desc")
@QueryParam("queryParam") String queryParam
) throws SQLException { ... }
我如何注释查询参数,以生成正确的JSON配置?
I have a Restlet API application using the Restlet Swagger extenstion to generate the Swagger json via Swagger2SpecificationRestlet
.
// route to generated swagger json
swagger2SpecificationRestlet.attach(router, "/docs");
My routes are defined like this:
router.attach("/path/{pathParam}", MyResource.class);
I have implemented swagger-ui locally and set the initializer url to read the swagger json from /docs
. The UI works as expected for all of the routes including the required path parameter inputs however the annotations for the query params are rendering as post body(?) without any of the other defined fields. param inputs:
"parameters": [
{
"name": "pathParam",
"in": "path",
"required": true,
"type": "string"
},
{
"in": "body",
"name": "body",
"required": false,
"schema": {
"type": "string"
}
],
My resource method with annotations:
@ApiOperation(
value="test desc",
httpMethod = "GET",
produces = "application/json",
notes="testing notes"
)
@Get("txt")
public String represent(
@ApiParam(name="queryParam", value = "testing desc")
@QueryParam("queryParam") String queryParam
) throws SQLException { ... }
How can I annotate query params so that swagger generates the correct json configuration?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在进一步查看了文档之后,我遇到了这一点:
noreferrer“> https://docs.swagger.io/swagger-core/apidocs/com/wordnik/wordnik/swagger/annotations/apiimpliticparam.html#paramtype
我用
apiparam
apiimpliticparam
,该有一个字段来声明param类型,并将注释移动上述注释该方法:它导致正确生成的JSON:
After looking further into the documentation I came across this:
https://docs.swagger.io/swagger-core/apidocs/com/wordnik/swagger/annotations/ApiImplicitParam.html#paramType()
which states:
I replaced
ApiParam
withApiImplicitParam
which has a field to declare param type and moved the annotation above the method:Which results in the correctly generated json: