Swagger Springfox 注释不起作用
Swagger Springfox annotations not working
这些是我尝试创建的示例应用程序的方法 headers。不幸的是,我没有看到 @ApiOperation 或 @ApiResponse 或 @ApiResponses 注释生效。
我还有一个示例 class 和一个应用程序 class(其中包含 swagger 配置信息等)
@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 查看我的 UI。
有人可以告诉我我做错了什么吗?
谢谢!
我在玩弄并从
更改了我的导入
导入com.wordnik.swagger.annotations.;
至
导入io.swagger.annotations.;
并且所有注释似乎都有效。
所以,看起来 com.wordnik.swagger.annotations 导入不再有效,或者至少不能正常工作?
Dilip Krish 确认here
这些是我尝试创建的示例应用程序的方法 headers。不幸的是,我没有看到 @ApiOperation 或 @ApiResponse 或 @ApiResponses 注释生效。 我还有一个示例 class 和一个应用程序 class(其中包含 swagger 配置信息等)
@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 查看我的 UI。
有人可以告诉我我做错了什么吗? 谢谢!
我在玩弄并从
更改了我的导入导入com.wordnik.swagger.annotations.;
至
导入io.swagger.annotations.;
并且所有注释似乎都有效。 所以,看起来 com.wordnik.swagger.annotations 导入不再有效,或者至少不能正常工作?
Dilip Krish 确认here