是否可以在 hapi-swagger 中根据用户角色从文档(swagger ui)中隐藏一些 API。我的意思是想我有/employee和/admin两个API所以每当管理员登录招摇UI或招摇文档,以便既/employee和/adminAPI应该在页面上显示,如果员工登录招摇的用户界面,那么它应该只显示/employeeAPI。
在我的本地主机中,我的 swagger UI 运行良好。localhost:3030/documentation 此 UI 也在服务器上运行,但从今天开始在服务器上不再运行https://digitalpathshalabd.com/documentation
错误
所以我有 Hapi (v17.5.1),当我的插件数组为
[
{
plugin: good,
options: {
reporters: {
errorReporter: [
{
module: 'good-squeeze',
name: 'Squeeze',
args: [{ error: '*' }],
}, {
module: 'good-console',
},
'stderr',
],
infoReporter: [
{
module: 'good-squeeze',
name: 'Squeeze',
args: [{ log: '*', response: '*' }],
}, {
module: 'good-console',
},
'stdout',
],
},
}
]
Run Code Online (Sandbox Code Playgroud)
让我们将其保存在变量中goodPlugin以供下一个示例使用。
也就是说,只有使用好的插件,它才能正常工作,但是当我尝试添加 Inert、Vision 或 Hapi-Swagger 时,它会中断并给出错误Cannot start server before plugins finished registration。
一个例子:
const HapiSwagger = require('hapi-swagger');
const Inert = require('inert');
const …Run Code Online (Sandbox Code Playgroud) 我在我们的应用程序中使用 hapi-swagger,其中一个 API 尝试使用自定义标头,但是当我使用自定义标头调用该 API 时出现以下错误
{
"statusCode": 400,
"error": "Bad Request",
"message": "Invalid request headers input"
}
Run Code Online (Sandbox Code Playgroud)
在我使用带有验证器的标头的 API 下方。
{
method: 'POST',
path: '/v1/testapi',
config: {
description: 'Greet user',
notes: ['Use to greet a user'],
tags: ['api'],
handler: function ( request, h ) {
console.log('sending response...');
return h.response('OK');
},
validate: {
headers: {
name: Joi.string().required()
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
以下是我们正在使用的版本。
"hapi": "17.2.2",
"hapi-swagger": "9.1.1",
"joi": "13.1.2",