我尝试在我的项目中基于FeathersJS框架实现Swagger UI模块,如下所示:
...
messageService.docs = {
description: 'A service to send and receive messages',
definitions: {
messages: {
"type": "object",
"required": [
"text"
],
"properties": {
"text": {
"type": "string",
"description": "The message text"
}
}
}
}
};
const app = feathers()
....
.configure(swagger({
docsPath: '/docs',
info: {
title: 'A test',
description: 'A description'
}
}))
.use('/messages', messageService);
但是我收到了这条错误消息。我该如何解决?
Resolver error at paths./messages.get.responses.200.schema.$ref
Could not resolve reference because of: Could not resolve pointer: /definitions/messages list does not exist in document
从错误消息显然,您必须在messageService.docs定义属性中添加“消息列表”。
如下:
messageService.docs = {
description: 'A service to send and receive messages',
definitions: {
messages: {
"type": "object",
"required": [
"text"
],
},
"properties": {
"text": {
"type": "string",
"description": "The message text"
}
},
// add message list definitions
'messages list': {
"type": "object",
"required": [
"text"
],
"properties": {
"text": {
"type": "string",
"description": "The message text"
}
}
}
};
您可以阅读docs中的完整示例。