我使用swagger 2.0定义后端并尝试定义安全性。
我最终得到了:
---
swagger: "2.0"
info:
version: 1.0.0
title: Foo test
schemes:
- https
paths:
/foo:
get:
security:
- Foo: []
responses:
200:
description: Ok
securityDefinitions:
Foo:
type: apiKey
name: X-BAR
in: header
到目前为止一切都很好,java codegen给了我:
@ApiOperation(value = "", nickname = "fooGet", notes = "", authorizations = {
@Authorization(value = "Foo")
}, tags={ })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Ok") })
@RequestMapping(value = "/foo",
method = RequestMethod.GET)
default ResponseEntity<Void> fooGet() {
if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
} else {
log.warn("ObjectMapper or HttpServletRequest not configured in default FooApi interface so no example is generated");
}
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
我想知道在界面中如何“正确”检索X-BAR标头值。 我最终得到了:
@Autowired
private HttpServletRequest httpServletRequest;
httpServletRequest.getHeader("X-BAR")
哪个可行,但是还有更合适的方法吗? 定义一个类“ Foo”?一个doFilter吗?
谢谢