【发布时间】:2020-11-16 16:45:30
【问题描述】:
我有这个post请求方法:
@PostMapping(value = "personnePhysique", produces = { MediaType.APPLICATION_OCTET_STREAM_VALUE })
public ResponseEntity<InputStreamResource> getRapportSolvabilitePPUsingPOST(
@ApiParam(value = "rapportPP", required = true) @Valid @RequestHeader Map<String, String> apiHeader, @RequestBody RapportPP rapportPP)
throws BusinessException {
RapportPPDTO dto = mapper.convertValue(rapportPP, RapportPPDTO.class);
String apiId = null;
String apiPwd = null;
/* Iterate over apiHeaders map */
for (Map.Entry<String, String> entry : apiHeader.entrySet()) {
if(entry.getKey().equals(ApiConstants.CB_API_USER_ID) && entry.getValue().equals(ApiConstants.CB_API_USER_PWD))
{
apiId = entry.getKey();
apiPwd = entry.getValue();
}
System.out.println("Item : " + entry.getKey() + " Count : " + entry.getValue());
System.out.println("apiId : " + apiId);
System.out.println("apiPwd : " + apiPwd);
}
/* Iterate over apiHeaders map */
try {
ByteArrayInputStream array = this.rapportSolvabiliteService.getRapportSolvabilitePhysique(dto, apiId, apiPwd);
return toSubscribeContractModel(array, "rapportSolvabilite.pdf");
} catch (BusinessException e) {
throw new BusinessException(500, message.getString(ApiConstants.TECHNICAL_ERROR_MESSAGE_KEY), e);
}
}
如你所见,因为@ApiParam required 选项为真,所以@RequestHeader apiHeader 也是必需的, 我想知道如何使 apiHeader 隐藏和可选,因此它不会出现在我的 Swagger 文档中,并且只需要我的正文 (rapportPP)。
谢谢
【问题讨论】:
-
我想你只需要删除@ApiParam。
-
您好,感谢您的回复,但是如果您删除@ApiParam,它们都将是默认值(必需且不隐藏)
标签: java spring spring-boot spring-mvc swagger-ui