We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
securityDefinitions 配置不仅需要在config加添加,也需要在control层添加对应的securityType 另外注意 apiKey的大小写。 ` // config.default.ts securityDefinitions: { apiKey: { type: 'apiKey', name: 'authorization', in: 'header', },
},
// controller.ts
/** * @summary 查询商品优惠信息 * @description 查询商品优惠信息 * @router post /v1/goods/searchGoodsCoupon * @request body searchGoodsCouponRequest *body * @apiKey // 这个注释必须要添加否则securityDefinitions 不起作用 * @response 200 */ async searchGoodsCoupon() {}
`
以上解决方案可以看源码 egg-swagger-doc/document/index.js/generateSecurity方法 只有满足 if (block.indexOf(@${security}) > -1) 条件时接口才会添加header
@${security}
` /**
The text was updated successfully, but these errors were encountered:
可以参考这个issue #72 (comment) 我的配置是这样的,如下图
Sorry, something went wrong.
No branches or pull requests
securityDefinitions 配置不仅需要在config加添加,也需要在control层添加对应的securityType
另外注意 apiKey的大小写。
`
// config.default.ts
securityDefinitions: {
apiKey: {
type: 'apiKey',
name: 'authorization',
in: 'header',
},
// controller.ts
`
以上解决方案可以看源码
egg-swagger-doc/document/index.js/generateSecurity方法
只有满足 if (block.indexOf(
@${security}
) > -1) 条件时接口才会添加header`
/**
*/
function generateSecurity(block, securitys, swagger) {
let securityDoc = [];
for (let security of securitys) {
if (block.indexOf(
@${security}
) > -1) {let securityItem = {};
if (swagger.securityDefinitions[security].type === 'apiKey') {
securityItem[security] = [];
securityItem[security].push(swagger.securityDefinitions[security]);
}
if (swagger.securityDefinitions[security].type === 'oauth2') {
securityItem[security] = [];
Object.keys(swagger.securityDefinitions[security].scopes).forEach(i => {
securityItem[security].push(i);
});
}
securityDoc.push(securityItem);
}
}
return securityDoc;
}
`
The text was updated successfully, but these errors were encountered: