Java 在Spring boot microservice中配置Swagger UI以接受映射
我已经创建了一个api,它从UI中接收值映射(筛选、排序、分页等),如下所示:Java 在Spring boot microservice中配置Swagger UI以接受映射,java,spring-boot,swagger,Java,Spring Boot,Swagger,我已经创建了一个api,它从UI中接收值映射(筛选、排序、分页等),如下所示: /** * Retrieves audit records for events * * @param allRequestParams filters * @return search results with list of {@link Event} */ @ApiOperation(value = "Retrieve audit record
/**
* Retrieves audit records for events
*
* @param allRequestParams filters
* @return search results with list of {@link Event}
*/
@ApiOperation(value = "Retrieve audit records for events")
@GetMapping("/audit")
public ResponseEntity getAuditRecords(
@RequestParam MultiValueMap<String, String> allRequestParams
) throws PermissionsDeniedException, GenericException, GeneralSecurityException {
log.info("Retrieving audit records of all events...");
List<Event> events = eventService.getAuditRecords(userPrincipleService.getUserPrinciple(), allRequestParams);
if (isEmpty(events)) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
return new ResponseEntity<>(getPaginatedResponse(allRequestParams, events), HttpStatus.OK);
}
/**
*检索事件的审核记录
*
*@param allRequestParams过滤器
*@返回带有{@link Event}列表的搜索结果
*/
@ApiOperation(value=“检索事件的审核记录”)
@GetMapping(“/audit”)
公众反应记录(
@RequestParam多值映射allRequestParams
)抛出PermissionsDeniedException、GenericException、GeneralSecurityException{
log.info(“检索所有事件的审核记录…”);
List events=eventService.getAuditRecords(userPrincipleService.getUserPrinciple(),allRequestParams);
如果(isEmpty(事件)){
返回新的ResponseEntity(未找到HttpStatus.NOT_);
}
返回新的ResponseEntity(getPaginatedResponse(allRequestParams,events),HttpStatus.OK);
}
在这里,我将从地图中的UI捕获所有信息:
@RequestParam MultiValueMap<String, String> allRequestParams
@RequestParam多值映射allRequestParams
这是来自UI的实际请求:
https://<base-url>/api/contract/restructure-event/audit?cb=1622617155911&page=0&size=20&fromDate=2021-06-02T23:00:00.000Z
https:///api/contract/restructure-event/audit?cb=1622617155911&page=0&size=20&fromDate=2021-06-02T23:00:00.000Z
但当我查看这些大摇大摆的文档时,它看起来是这样的:
这使得测试变得不可能
是否有任何方法可以通过Swigger UI以人类可读的方式提供映射值?允许您以微调的方式手动定义参数
我已经根据您的实际请求定义了两个示例参数(页面和大小)
@ApiOperation(value=“检索事件的审核记录”)
@ApitParams({
@apimplicitparam(name=“page”,value=“enter page value.”,dataTypeClass=Integer.class,paramType=“query”)
,@apimplicitparam(name=“size”,value=“enter size value.”,dataTypeClass=Integer.class,paramType=“query”)
})
@GetMapping(“/audit”)
公众反应记录(
@RequestParam多值映射allRequestParams
)抛出PermissionsDeniedException、GenericException、GeneralSecurityException{
//...
}
非常感谢。这几乎100%地解决了这个问题。但是,我仍然可以看到旧映射参数,我必须输入一个随机值才能成功发出api请求。如果您想在端点中隐藏旧映射参数,可以将@ApiIgnore作为@ApiIgnore@RequestParam MultiValueMap allRequestParams
添加到此参数。
@ApiOperation(value = "Retrieve audit records for events")
@ApiImplicitParams({
@ApiImplicitParam(name = "page", value = "enter page value.", dataTypeClass = Integer.class, paramType = "query")
,@ApiImplicitParam(name = "size", value = "enter size value.", dataTypeClass = Integer.class, paramType = "query")
})
@GetMapping("/audit")
public ResponseEntity getAuditRecords(
@RequestParam MultiValueMap<String, String> allRequestParams
) throws PermissionsDeniedException, GenericException, GeneralSecurityException {
//...
}