2016-09-07 20 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と、私は理解できない二つの問題があります私は2つのopenTaskインターフェースを持っています.1つはGETと1つのPOSTですが、JsonにはPOSTだけが含まれています。

  2. いくつかのインターフェースでは、500応答の{"$ ref": "#/ definitions/Error"}が得られますが、私はこのスキーマを持っていません。それは一部のサービスのためだけです。 私は何を間違って定義していますか? おかげで、 ニール
  3. しようとするものの

答えて

0

カップル:最新のライブラリのバージョン(この記事の時点で2.6.0)

    • アップグレードは、すべての闊歩注釈を削除してご覧くださいあなたが得るもの。 the documentation

      哲学的に、私たちは実行時にサービス記述に重要でない(swagger-core)注釈を使用しないようにしたいと思います。例えば、ジャックソンの注釈は常に@ApiModelPropertyよりも優先されるべきです。 @NotNullまたは@RequestParam#requiredを指定すると常に勝つはずです。注釈は、サービス/スキーマの特性を推論することができない場合には、ドキュメントを補完するか、または結果の仕様を上書き/微調整するためにのみ使用されます。

  • 関連する問題