swagger 전역 응답 상태 코드 추가

1468 단어 springbootswagger
@Bean
public Docket createRestApi()
{
    //         
    List responseMessageList = new ArrayList<>();
    Arrays.stream(ErrorEnum.values()).forEach(errorEnum -> {
        responseMessageList.add(
                new ResponseMessageBuilder().code(errorEnum.getCode()).message(errorEnum.getMsg()).responseModel(
                        new ModelRef(errorEnum.getMsg())).build()
        );
    });
    return new Docket(DocumentationType.SWAGGER_2)
            //          
            .globalResponseMessage(RequestMethod.GET, responseMessageList)
            .globalResponseMessage(RequestMethod.POST, responseMessageList)
            .globalResponseMessage(RequestMethod.PUT, responseMessageList)
            .globalResponseMessage(RequestMethod.DELETE, responseMessageList)

//.............생략하다
매거류
public enum ErrorEnum {

    /*
     *     
     * */
    E_200(200, "    "),
    E_201(201,"      "),
    E_202(202,"       "),
    E_400(400,"      (  ,     )"),
    E_401(401,"   "),
    E_403(403,"    ,    "),
    E_404(404,"  ,     "),
    ;

    private Integer Code;
    private String Msg;
    ErrorEnum(Integer Code, String Msg) {
        this.Code = Code;
        this.Msg = Msg;
    }
    public Integer getCode() {
        return Code;
    }
    public String getMsg() {
        return Msg;
    }
}

좋은 웹페이지 즐겨찾기