在swagger api doc中使用数组的引用

时间:2017-09-27 13:31:58

标签: javascript node.js npm swagger

我试图在swagger api-doc中引用数组中的对象(使用更多对象但是使用相同的模式):

  definitions: {
    obj: {
      type: 'object',
      properties: {
        login: {
          type: 'string',
        },
        password: {
          type: 'string',
        },
      },
    },


 objArray: {
          type: 'array',
          items: {
            type: 'object',
            $ref: '#/definitions/obj',
          },
        },
}

但是我收到了这个错误:

error TS2345: Argument of type '{ paths: { path: string; module: any; }[]; app: any; apiDoc: { 'x-express-openapi-additional-midd...' is not assignable to parameter of type 'Args'.
  Types of property 'apiDoc' are incompatible.
    Type '{ 'x-express-openapi-additional-middleware': any[]; swagger: string; basePath: string; info: { ti...' is not assignable to type 'ApiDefinition'.
      Types of property 'definitions' are incompatible.
        Type '{ Error: { type: string; properties: { status: { type: string; }; message: { type: string; }; tra...' is not assignable to type 'DefinitionsObject | undefined'.
          Type '{ Error: { type: string; properties: { status: { type: string; }; message: { type: string; }; tra...' is not assignable to type 'DefinitionsObject'.
            Property 'Orders' is incompatible with index signature.
              Type '{ type: string; properties: { client: { type: { type: string; }; }; metadata: { type: string; pro...' is not assignable to type 'SchemaObject'.
                Types of property 'properties' are incompatible.
                  Type '{ client: { type: { type: string; }; }; metadata: { type: string; properties: { client: { type: s...' is not assignable to type '{ [name: string]: SchemaObject; } | undefined'.
                    Type '{ client: { type: { type: string; }; }; metadata: { type: string; properties: { client: { type: s...' is not assignable to type '{ [name: string]: SchemaObject; }'.
                      Property 'client' is incompatible with index signature.
                        Type '{ type: { type: string; }; }' is not assignable to type 'SchemaObject'.
                          Types of property 'type' are incompatible.
                            Type '{ type: string; }' is not assignable to type 'string | string[] | undefined'.
                              Type '{ type: string; }' is not assignable to type 'string[]'.
                                Property 'length' is missing in type '{ type: string; }'.

知道为什么吗?

1 个答案:

答案 0 :(得分:0)

我认为您不应在apt-build内定义类型。只需将其删除即可。

items: { }

您已经引用了对象。此对象的类型在其定义中声明。