FeathersJS 和 Swagger UI:无法解析指针:/definitions/messages
FeatherJS and SwaggerUI: Could not resolve pointer: /definitions/messages
我尝试在我的项目中基于 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 定义属性中添加 'messages list'。
如下:
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 中阅读完整示例。
如果您正在使用 Sequelize,您可能想尝试 https://github.com/alt3/sequelize-to-json-schemas。它会自动为您生成模型架构。
我尝试在我的项目中基于 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 定义属性中添加 'messages list'。
如下:
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 中阅读完整示例。
如果您正在使用 Sequelize,您可能想尝试 https://github.com/alt3/sequelize-to-json-schemas。它会自动为您生成模型架构。