NutzCN Logo
问答 swagger ui页面参数不能输入
发布于 2348天前 作者 pengmingxing 11863 次浏览 复制 上一个帖子 下一个帖子
标签:

集成swagger后,页面上能显示,但是参数输入那栏,操作不了,是参数注解写的不对?跪求大神解答

package com.panport.raiis.nutz.module;

import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.util.NutMap;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.GET;
import org.nutz.mvc.annotation.Ok;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@Api(value = "raiis")
@IocBean
@At("")
public class SwaggerTestModule extends BaseModule {

	@GET
	@ApiOperation(value = "接口说明", notes = "接口发布说明", httpMethod="GET", response = NutMap.class)
	@At("/ping")
	@Ok("json:full")
	public Object ping(
			@ApiParam(required = false, name = "a", value = "第一个参数")String a,
			@ApiParam(required = false, name = "b", value = "第二个参数")String b) {
		return new NutMap("ok", true).setv("a", a).setv("b", b);
	}
	
}

28 回复

页面报什么错误吗?

如果不行,可以试试用纯swagger-core的注解标注一下试试 https://github.com/swagger-api/swagger-core/wiki/Annotations-1.5.X

错误倒是没有,就是输入参数那点不开,看了下你发的链接,好像参数注解输入跟我这也是一样的?

@ApiParam(required = false, name = "a", value = "第一个参数")String a,
			@ApiParam(required = false, name = "b", value = "第二个参数")String b

F12看看报啥

F12没报错,在页面对应的url下,点击Example value没反应,前端懂得确实不多,能给个带参数注解的例子不?

额,那么神奇? 我下午找时间试试

谢谢大神,试了不少网上的注解方法,输入那都点不进去

https://online.swagger.io/validator/debug?url=https://nutz.cn/swagger/swagger.json
{"messages":["attribute info is missing"],"schemaValidationMessages":[{"level":"error","domain":"validation","keyword":"required","message":"object has missing required properties ([\"info\"])","schema":{"loadingURI":"#","pointer":""},"instance":{"pointer":""}}]}

貌似少了点什么,待我查查

嗯,试了下面这种注解方式,好像也不行
@ApiImplicitParams({
@ApiImplicitParam(name = "a", value = "a", required = true, dataType = "String"),
@ApiImplicitParam(name = "b", value = "b", required = true, dataType = "String")
})

我试出来了,小写的string

    @POST
    @ApiOperation(value = "回显接口", notes = "发我一个字符串,原样回复一个字符串")
    @ApiImplicitParams({@ApiImplicitParam(name = "text", paramType="form", value = "想发啥就发啥", dataType="string", required = true)})
    @At
    @Ok("raw")
    public String echo(@Param("text") String text) {
        return text;
    }

确实可以了,谢谢大神!

额,试了下GET请求,居然就不行了~

@POST 限制了只能Post请求

查到原因了,paraType = "form"只支持POST,改成paraType = "query"就都支持了,有个问题,那个路径的@Path为啥找不到依赖的包呢??

@Path ?? swagger的某个注解?

嗯,找不到依赖的,包是从你之前给通过maven直接导入的

Jersey的注解吧

这个查询的url是http://localhost:8080/raiis/ping?a=1&b=2
swagger UI页面上的url是 http://localhost:8080/raiis/ping/query?a=1&b=2
有没办法,让swagger的url不去读取query

@Api(value = "raiis/ping")
@IocBean
@At("/ping")
public class SwaggerTestModule extends BaseModule {

	@GET
	@Ok("raw")
	@At("")
	@ApiOperation(value = "接口说明", notes = "接口发布说明")
	@ApiImplicitParams(
	{  @ApiImplicitParam(name = "a", paramType="query", value = "第一个", dataType="string", required = true),
	   @ApiImplicitParam(name = "b", paramType="query", value = "第二个", dataType="string", required = true)
	})
	public Object query(@Param("a")String a, @Param("b")String b) {
		return new NutMap("ok", true).setv("a", a).setv("b", b);
	}
}

ApiOperation好像可以设置

确实可以,请问下,swagger注解后台只能接收一个对象?

	@At("")
	@PUT
	@AdaptBy(type = JsonAdaptor.class)
	@ApiOperation(value = "更新目的地语言信息", notes = "更新一个目的地语言信息", nickname = "destLang", tags = "destLang", response = ResponseCode.class)
    @ApiImplicitParams({
    @ApiImplicitParam(name = "newValue", paramType="body", value = "新的目的地语言信息", dataType="com.panport.raiis.fids.bean.DestLang", required = true),
    @ApiImplicitParam(name = "oldValue", paramType="body", value = "旧的目的地语言信息", dataType="com.panport.raiis.fids.bean.DestLang", required = true)
    })
	public Object update(@Param("newValue")DestLang newValue, @Param("oldValue")DestLang oldValue) throws SQLException
{
.......
}

我在页面提交 newValue跟oldValue对象值,后台只能接收到一个

swagger的注解不会影响nutz的行为

是不会影响nutz,我是说在swagger ui上,测试输入两个对象值,后台只能接收到一个

哦,这个不清楚了

如果是自定义的VO作为参数,需要一个个写@ApiImplicitParam吗?

添加回复
请先登陆
回到顶部