2016-09-07 2 views
0

신난다. 나는 folowing 코드가 있습니다springfox swagger Json 오류

@RestController 
@RequestMapping(value = { V1P}) 
@Api(value = V1P, description= "My Operations Management API") 
public class MethodController { 


    /** 
    * @return - 
    */ 
    @ApiOperation(value = "retrieve task information", notes = "retrieve service instance information", response = String.class) 
    @ApiResponses(value = { 
       @ApiResponse(code = 200, message = "Success"), 
       @ApiResponse(code = 401, message = "Unauthorized"), 
       @ApiResponse(code = 500, message = "Failure")}) 
    @SuppressWarnings("nls") 
    @RequestMapping(value = BASE_PATH , method = RequestMethod.GET, consumes = MediaType.TEXT_PLAIN_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) 
    public ResponseEntity<String> retrieve() { 
     .... 
    } 

    @ApiOperation(nickname = "openTaskUsingGet", value = "Open a task", notes = "API to Open a task", response = String.class) 
    @ApiResponses(value = { 
       @ApiResponse(code = 200, message = "Success"), 
       @ApiResponse(code = 401, message = "Unauthorized"), 
       @ApiResponse(code = 500, message = "Failure")}) 
    @ApiImplicitParams({ 
     @ApiImplicitParam(name = "taskReferenceId", value = "Reference ID of the task", required = true, dataType = "string", paramType = "query"), 
     @ApiImplicitParam(name = "taskSummary", value = "The task's summary description", required = true, dataType = "string", paramType = "query"), 
     @ApiImplicitParam(name = "contentDocumentId", value = "The content document ID of the task", required = true, dataType = "string", paramType = "query"), 
     @ApiImplicitParam(name = "createdBy", value = "The name of the creating user", required = true, dataType = "string", paramType = "query"), 
     @ApiImplicitParam(name = "teamReferenceId", value = "The creating team reference ID", required = true, dataType = "string", paramType = "query"), 
     @ApiImplicitParam(name = "taskFromTime", value = "Task planned start time", required = true, dataType = "string", paramType = "query"), 
     @ApiImplicitParam(name = "taskDueTime", value = "Task planned due time", required = true, dataType = "string", paramType = "query"), 
     @ApiImplicitParam(name = "taskGroup", value = "Task group name", required = true, dataType = "string", paramType = "query"), 
     @ApiImplicitParam(name = "taskType", value = "Task type", required = true, dataType = "string", paramType = "query"), 
     @ApiImplicitParam(name = "siteLongitude", value = "Site longitude coordinate", required = true, dataType = "double", paramType = "query"), 
     @ApiImplicitParam(name = "siteLatitude", value = "Site latitude coordinate", required = true, dataType = "double", paramType = "query"), 
     @ApiImplicitParam(name = "siteZipCode", value = "Site zip code", required = true, dataType = "string", paramType = "query"), 
     @ApiImplicitParam(name = "siteName", value = "Site name", required = true, dataType = "string", paramType = "query"), 
     @ApiImplicitParam(name = "siteCountry", value = "Site country", required = true, dataType = "string", paramType = "query"), 
     @ApiImplicitParam(name = "siteState", value = "Site state", required = true, dataType = "string", paramType = "query"), 
     @ApiImplicitParam(name = "siteCity", value = "Site city", required = true, dataType = "string", paramType = "query"), 
     @ApiImplicitParam(name = "siteAddress", value = "Site address", required = true, dataType = "string", paramType = "query"), 
     @ApiImplicitParam(name = "siteComments", value = "Site comments", required = true, dataType = "string", paramType = "query"), 
     @ApiImplicitParam(name = "siteReferenceId", value = "Site reference ID", required = true, dataType = "string", paramType = "query"), 
     @ApiImplicitParam(name = "eqType", value = "Equipment type", required = true, dataType = "string", paramType = "query"), 
     @ApiImplicitParam(name = "eqReferenceId", value = "Equipment reference ID", required = true, dataType = "string", paramType = "query") 
     }) 
    @SuppressWarnings({ "nls", "javadoc" }) 
    @RequestMapping(value = BASE_PATH + "/mob/openTask" , method = RequestMethod.GET, consumes = MediaType.TEXT_PLAIN_VALUE, produces = MediaType.TEXT_PLAIN_VALUE) 
    public ResponseEntity<String> openTask(
      @RequestParam("taskReferenceId")    String taskReferenceId, 
      @RequestParam("taskSummary")     String taskSummary, 
      @RequestParam("contentDocumentId")   String contentDocumentId, 
      @RequestParam("createdBy")     String createdBy, 
      @RequestParam("teamReferenceId")    String teamReferenceId, 
      @RequestParam("taskFromTime")     String taskFromTime, 
      @RequestParam("taskDueTime")     String taskDueTime, 
      @RequestParam("taskGroup")     String taskGroup, 
      @RequestParam("taskType")      String taskType, 
      @RequestParam("siteLongitude")    double siteLongitude, 
      @RequestParam("siteLatitude")     double siteLatitude, 
      @RequestParam("siteZipCode")     String siteZipCode, 
      @RequestParam("siteName")      String siteName, 
      @RequestParam("siteCountry")     String siteCountry, 
      @RequestParam("siteState")     String siteState, 
      @RequestParam("siteCity")      String siteCity, 
      @RequestParam("siteAddress")     String siteAddress, 
      @RequestParam("siteComments")     String siteComments, 
      @RequestParam("siteReferenceId")    String siteReferenceId, 
      @RequestParam("eqType")      String eqType, 
      @RequestParam("eqReferenceId")    String eqReferenceId){ 
      .... 
    } 

    @ApiOperation(nickname = "openTaskUsingPOST", value = "Open a task", notes = "API to Open a task", response = String.class) 
    @ApiResponses(value = { 
       @ApiResponse(code = 200, message = "Success"), 
       @ApiResponse(code = 401, message = "Unauthorized"), 
       @ApiResponse(code = 500, message = "Failure")}) 
    @SuppressWarnings({ "nls", "javadoc" }) 
    @RequestMapping(value = BASE_PATH + "/mob/openTask" , method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.TEXT_PLAIN_VALUE) 
    public ResponseEntity<String> openTask(@RequestBody OpenTaskCmd cmd){ 
     ... 
    } 

    @ApiOperation(value = "Get an HTML summary of a package content", notes = "API to get an HTML summary of a package content", response = String.class) 
    @ApiResponses(value = { 
       @ApiResponse(code = 200, message = "Success"), 
       @ApiResponse(code = 401, message = "Unauthorized"), 
       @ApiResponse(code = 500, message = "Failure")}) 
    @ApiImplicitParams({ 
     @ApiImplicitParam(name = "packageName", value = "The name of the required package", required = true, dataType = "string", paramType = "query"), 
     @ApiImplicitParam(name = "packageVersion", value = "The required package version", required = true, dataType = "string", paramType = "query") 
    }) 
    @SuppressWarnings({ "nls", "javadoc" }) 
    @RequestMapping(value = BASE_PATH + "/mob/getContent" , method = RequestMethod.GET, consumes = MediaType.TEXT_PLAIN_VALUE, produces = MediaType.TEXT_HTML_VALUE) 
    public ResponseEntity<String> getContent(@RequestParam("packageName") String pkgName, 
           @RequestParam("packageVersion") String pkgVersion){ 
     .... 
    } 

    @ApiOperation(value = "Get the activities of a project as a Json array", notes = "API to get the activities of a project as a Json array") 
    @ApiResponses(value = { 
       @ApiResponse(code = 200, message = "Success"), 
       @ApiResponse(code = 401, message = "Unauthorized"), 
       @ApiResponse(code = 500, message = "Failure")}) 
    @ApiImplicitParams({ 
     @ApiImplicitParam(name = "startIndex", value = "The first activity index", required = true, dataType = "string", paramType = "query"), 
     @ApiImplicitParam(name = "pageSize", value = "The number of activities", required = true, dataType = "string", paramType = "query") 
    }) 
    @SuppressWarnings("javadoc") 
    @RequestMapping(value = BASE_PATH + "/mob/readActivities" , method = RequestMethod.GET, consumes = MediaType.TEXT_PLAIN_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) 
    public ResponseEntity<String> readActivities(@RequestParam("startIndex") int startIndex, 
            @RequestParam("pageSize") int pageSize){ 
     ... 
    } 
} 

THS은 JSON의 일부를 내가 얻을 :

  1. :

    {"swagger":"2.0","info":{"description":"Operation Management","version":"v1","title":"API","host":"127.0.0.1","basePath":"/","tags":[{"name":"v1","description":"Operations Management API"}], 
    "paths":{ 
    "/v1/proxy/resource":{..."responses":{"200":{"description":"Success","schema":{"type":"string"}},"401":{"description":"Unauthorized"},"500":{"description":"Failure","schema":{"$ref":"#/definitions/Error"}}}}}, 
    "/v1/proxy/resource/mob/getContent":{"get":{...,"responses":{"200":{"description":"Success","schema":{"type":"string"}},"401":{"description":"Unauthorized"},"500":{"description":"Failure","schema":{"$ref":"#/definitions/Error"}}}}}, 
    "/v1/proxy/resource/mob/openTask":{"post":{"tags":["v1"],"summary":"Open a task","description":"API to Open a task","operationId":"openTaskUsingPOSTUsingPOST","consumes":["application/json"],"produces":["text/plain"],"parameters":[{"in":"body","name":"cmd","description":"cmd","required":true,"schema":{"$ref":"#/definitions/OpenTaskCmd"}}],"responses":{"200":{"description":"Success","schema":{"type":"string"}},"401":{"description":"Unauthorized"},"500":{"description":"Failure"}}}}, 
    "/v1/proxy/resource/mob/readActivities":{"get":{...,"responses":{"200":{"description":"Success","schema":{"type":"string"}},"401":{"description":"Unauthorized"},"500":{"description":"Failure","schema":{"$ref":"#/definitions/Error"}}}}}}, 
    "definitions":{"OpenTaskCmd":{...}}}}} 
    

    은 JSON과 나는 알아낼 수 없습니다 두 가지 문제가 있습니다 두 개의 openTask 인터페이스 (하나는 GET, 하나는 POST)를 가지고 있지만, Json은 POST에만 포함되어 있습니다.

  2. 일부 인터페이스의 경우 500 응답에 대해 { "$ ref": "#/definitions/Error"}를 얻을 수 있지만이 스키마가 없으므로 이해할 수 없습니다 일부 서비스에만 해당됩니다. 무엇이 잘못 정의되어 있습니까? 감사합니다, Nir 씨 것들의

답변

0

커플 시도 :

  • 모든 자신감 주석을 제거하고 참조 (이 게시물시 2.6.0) 최신 라이브러리 버전에
    • 업그레이드 당신이 얻는 것. 출처 : the documentation :

      철학적으로, 우리는 런타임에 서비스 설명에 중요하지 않은 (swagger-core) 주석을 사용하지 않는 것이 좋습니다. 예 : 잭슨 주석은 항상 @ApiModelProperty보다 트럼프하거나 더 많은 가중치를 가져야합니다. @NotNull이거나 항상 @RequestParam#required을 지정해야합니다. 주석은 서비스/스키마 특성을 추론 할 수없는 경우 문서를 보완하거나 결과 사양을 무시하거나 조정할 때만 사용해야합니다.