考虑示例:
@RequestMapping("myPath")
public Mono<MyDto> myMethod(@RequestParam(value = "amount") Long amount, @AuthenticationPrincipal MyUser user) {
}
要从参数列表中跳过MyUser
,我已将@AuthenticationPrincipal
添加到排除项和springfox生成的swagger文档中,如下所示:
"/myPath": {
"get": {
"tags": [
"my-controller"
],
"summary": "myMethod",
"operationId": "myMethodUsingGET",
"produces": [
"*/*"
],
"parameters": [
{
"name": "amount",
"in": "query",
"description": "amount",
"required": true,
"type": "integer",
"format": "int64"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/Mono«MyDto»"
}
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
},
"deprecated": false
}
}
这是弹簧配置:
@Configuration
@EnableSwagger2WebFlux
public class SwaggerConfig {
@Bean
public Docket api() {
Class[] clazz = {AuthenticationPrincipal.class};
return new Docket(DocumentationType.SWAGGER_2)
.select()
.paths(PathSelectors.any())
.build()
.ignoredParameterTypes(clazz);
}
}
是否有一种方法可以针对由@AuthenticationPrincipal
指定的每个路径,将标题添加到springfox项目生成的庞大文档中?
例如。对于找到了MyUser
的所有My-Auth-Header
方法,将@RequestMapping
类作为参数(或参数组)忽略,并用标头(例如@AuthenticationPrincipal
)替换它。
答案 0 :(得分:0)
这是一个示例,说明如何使用名为header
的{{1}}参数来添加JWT令牌
Auithorization