FeatherJS和SwaggerUI:无法解析指针:/ definitions / messages

时间:2018-06-18 16:06:06

标签: javascript node.js swagger-ui feathersjs

我尝试在我的项目中基于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

2 个答案:

答案 0 :(得分:1)

显然,从错误消息中,您必须在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中阅读完整的示例。

答案 1 :(得分:0)

如果您正在使用Sequelize,则可能要尝试https://github.com/alt3/sequelize-to-json-schemas。它将自动为您生成模型架构。