make@requestheader hidden true&不需要

y0u0uwnf  于 2021-07-08  发布在  Java
关注(0)|答案(1)|浏览(238)

我有这样的发帖方式:

@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 option为true,因此@requestheader apiheader也是必需的,我想知道如何使apiheader隐藏和可选,这样它就不会出现在我的swagger文档中,并且只需要我的body(reportpp)。
谢谢

dl5txlt9

dl5txlt91#

我刚刚发现我们可以在几个字段上使用@apiparam:

@PostMapping(value = "personnePhysique", produces = { MediaType.APPLICATION_OCTET_STREAM_VALUE })
public ResponseEntity<InputStreamResource> getRapportSolvabilitePPUsingPOST(
        @ApiParam(value = "rapportPP", required = true) @Valid @RequestBody RapportPP rapportPP,
        @ApiParam(value = "apiHeader", required = false, hidden = true) @RequestHeader Map<String, String> apiHeader)
        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);
    }
}

因此,如您所见,您可以为每一个指定值,如本例中所示:
apiheader是隐藏的,不是必需的
没有隐藏和要求
谢谢

相关问题