当前位置:   article > 正文

swagger-ui 入参JSONObject 时,设置默认参数_swagger 怎么添加入参是jsonobject的默认测试参数

swagger 怎么添加入参是jsonobject的默认测试参数

swagger-ui jsonobject 动态显示参数

0、请先配置好swagger-ui 的依赖等,

1、配置文件

@EnableSwaggerBootstrapUI
@EnableSwagger2
@Configuration
public class SwaggerConfig {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any()).build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("工作计划")
                .description("工作计划详细描述")
                .version("0.0.1")
                .build();
    }
}


2、注解使用

@PostMapping("/createOrder421")
@ApiOperation(value = "fastjson-JSONObject-动态创建显示参数")
@ApiOperationSupport(params = @DynamicParameters(name = "CreateOrderModel",properties = {
@DynamicParameter(name = "id",value = "注解id",example = "X000111",required = true,dataTypeClass = Integer.class),
@DynamicParameter(name = "name",value = "订单编号",required = false)
}))
public Rest<JSONObject> createOrder12222(@RequestBody JSONObject jsonObject){
Rest<JSONObject> r=new Rest<>();
r.setData(jsonObject);
return r;
}

@PostMapping("/createOrder422")
@ApiOperation(value = "jdk-Map-动态创建显示参数")
@DynamicParameters(name = "CreateOrderMapModel",properties = {
@DynamicParameter(name = "id",value = "注解id",example = "X000111",required = true,dataTypeClass = Integer.class),
@DynamicParameter(name = "name",value = "订单编号"),
@DynamicParameter(name = "name1",value = "订单编号1"),
@DynamicParameter(name = "orderInfo",value = "订单信息",dataTypeClass = Order.class),
})
public Rest<Map> createOrder12232(@RequestBody Map map){
Rest<Map> r=new Rest<>();
r.setData(map);
return r;
}

//我自己的   复制红色的即可

@ApiOperation(value = "入參json ok", response = Result.class)

@DynamicParameters(name = "CreateOrderModel", properties = {

@DynamicParameter(name = "id", value = "注解id", example = "X000111", required = true, dataTypeClass = Integer.class),

@DynamicParameter(name = "name", value = "订单编号", required = false), }) @PostMapping("/postjson3")

public String postjson3(@RequestBody JSONObject json) {

try {// 参数验证 String[] keys = {"id", "name"};

ValidateJson.validate(json, keys);

return json.getString("name");

} catch (ValidateJsonException e) {

e.printStackTrace();

}

return "123";

}

//也可看这个文章  

Swagger-boostrap-ui Map/JSONObject -动态创建显示参数_墨着染霜华的博客-CSDN博客_swagger 动态参数

https://blog.csdn.net/chengmin123456789/article/details/108345669

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号