2015-07-21 109 views
0

這些是我試圖創建的示例應用程序的方法標題。不幸的是,我沒有看到@ApiOperation或@ApiResponse或@ApiResponses註解生效。 我也有一個示例類和應用類(包含招搖配置信息等)Swagger Springfox註釋不起作用

@Api(value = "/v1/", description = "Test API", produces = "application/json") 
@RestController 
@RequestMapping("/v1/") 
class SampleRestController { 

    @ApiResponses(value = { 
      @ApiResponse(code = 200, message = "Successfully added"), 
      @ApiResponse(code = 416, message = "List is empty") }) 
    @RequestMapping(produces = MediaType.APPLICATION_JSON_VALUE, value = "samples/{sb}", 
    method = RequestMethod.GET) 
    public Map<String, String> sbs(@PathVariable("sb") String sb) { 

    } 

    @ApiOperation(
     value = "Seeing where this shows up", 
     notes = "we should see this in the implememtation notes", 
     response = Sample.class, 
     httpMethod = "GET" 
    ) 
     @ApiResponses(value = { 
      @ApiResponse(code = 200, message = "Successfully added"), 
      @ApiResponse(code = 416, message = "List is empty") }) 

    @RequestMapping(produces = MediaType.APPLICATION_JSON_VALUE, value = "samples/{pb}", 
    method = RequestMethod.GET) 
    public Sample ps(@PathVariable String pb) { 

    } 

    @RequestMapping(produces = MediaType.APPLICATION_JSON_VALUE, value = "samples", 
    method = RequestMethod.GET) 
    public Collection<Map<String, String>> cs(@RequestParam(value = "cid", required = true, defaultValue = "") 
    String cid) { 

    } 


} 

這是我昂首闊步JSON

{"swagger":"2.0","info":{"description":"All about the Samples","title":"Samples API","contact":{},"license":{}},"host":"localhost:8080","basePath":"/","tags":[{"name":"sample-rest-controller","description":"Sample Rest Controller"}], 



"paths":{ 


"/v1/samples":{"get":{"tags":["sample-rest-controller"],"summary":"cs","operationId":"csUsingGET","consumes":["application/json"],"produces":["application/json"],"parameters":[{"name":"cid","in":"query","description":"cid","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"$ref":"#/definitions/Collection«Map«string,string»»"}},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}}}}, 


"/v1/samples/{pb}":{"get":{"tags":["sample-rest-controller"],"summary":"ps","operationId":"psUsingGET","consumes":["application/json"],"produces":["application/json"],"parameters":[{"name":"pb","in":"path","description":"pb","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"$ref":"#/definitions/Sample"}},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}}}}, 


"/v1/samples/{sb}":{"get":{"tags":["sample-rest-controller"],"summary":"sbs","operationId":"sbsUsingGET","consumes":["application/json"],"produces":["application/json"],"parameters":[{"name":"sb","in":"path","description":"sb","required":true,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"type":"object","additionalProperties":{"type":"string"}}},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden"},"404":{"description":"Not Found"}}}}}, 

我使用springfox-的相關部分swagger2版本2.1.1,我正在通過他們的現場演示應用程序中的swagger提供的默認UI查看我的用戶界面。

有人能告訴我我做錯了什麼嗎? 謝謝!

回答

5

我打得周圍,改變了我的進口從

進口com.wordnik.swagger.annotations;

import io.swagger.annotations .;

和所有註釋似乎工作。 那麼,看起來像com.wordnik.swagger.annotations導入不再起作用,或者至少不能正常工作?

由Dilip Krish確認here