2016-08-08 2 views
2

springweb 2.0을 사용하여 스프링 프로젝트를 구성했습니다. 나는 그것으로 오픈 API 규격을 생성 할 수있다. 당신이 operationId의 값을 볼 수 있듯이swagger로 api spec에서 생성 된 operationId 값을 사용자 정의하는 방법은 무엇입니까?

"paths": { 
    "/test/testinfo": { 
     "post": { 
     "tags": [ 
      "test-controller" 
     ], 
     "summary": "getTestInfo", 
     "operationId": "getTestInfoInfoUsingGET", 
     "consumes": [ 
      "application/json" 
     ], 
     "produces": [ 
      "application/json" 
     ] 

형식

[java_method_name_here]Using[HTTP_verb_here] 

예이다. getPetsUsingGET

이 작업 ID는 swagger-codegen을 사용하여 클라이언트를 생성하는 동안 사용됩니다. 누구나 그것을 사용자 정의하는 방법을 알고 있습니까? 나는 이것이 @ApiOperation을 사용하여 api 당 수행 될 수 있지만 모든 api에 대해이 형식을 정의하는보다 일반적인 방법이 있는지 알고 있습니까?

답변

2

create your own plugin 할 수 있습니다. 여기에 동일한 플러그인 기술을 사용하여 springfox에서 어떻게 수행하는지에 대한 an example입니다.

@Component 
@Order(YOUR_PLUGIN_ORDER) // > Ordered.HIGHEST_PRECEDENCE + 1000 
public class OperationNicknameIntoUniqueIdReader implements OperationBuilderPlugin { 
    @Override 
    public void apply(OperationContext context) { 

    //Create your own transformation to format the name in the way 
    //that you prefer 
    String operationNameStem = transformName(context.getName()); 
    //Update the method name stem that is used to generate a unique id 
    context.operationBuilder().codegenMethodNameStem(operationNameStem); 
    } 
    ... 
} 

참고 : 당신이 올 줄기 어떤, springfox은 모든 API를 통해 고유하게됩니다. 따라서 중복 된 명명 된 메서드가 있으면 고유 한 이름 끝에 번호 매기기 구성표가 시작됩니다. 예 : getCustomer이 고유하지 않은 경우 고유 한 ID getCustomer_1 등을 생성합니다.