Manweill / swagger-axios-codegen

swagger client to use axios and typescript
MIT License
306 stars 83 forks source link

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'startsWith' of undefined #62

Closed OndraRehounek closed 4 years ago

OndraRehounek commented 4 years ago

Using version 0.9.4, I am getting following error (node version 10.17.0)

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'startsWith' of undefined

when trying to generate from following json:

{
  "swagger": "2.0",
  "info": {
    "title": "services/auth.proto",
    "version": "version not set"
  },
  "schemes": [
    "http",
    "https"
  ],
  "consumes": [
    "application/json"
  ],
  "produces": [
    "application/json"
  ],
  "paths": {
    "/auth/v1/change_password/{sub}": {
      "put": {
        "operationId": "ChangePassword",
        "responses": {
          "200": {
            "description": "A successful response.",
            "schema": {
              "$ref": "#/definitions/pbChangePasswordResponse"
            }
          }
        },
        "parameters": [
          {
            "name": "sub",
            "in": "path",
            "required": true,
            "type": "string"
          },
          {
            "name": "body",
            "in": "body",
            "required": true,
            "schema": {
              "$ref": "#/definitions/pbChangePasswordRequest"
            }
          }
        ],
        "tags": [
          "Users"
        ]
      }
    },
    "/auth/v1/reset_user": {
      "post": {
        "operationId": "ResetUser",
        "responses": {
          "200": {
            "description": "A successful response.",
            "schema": {
              "$ref": "#/definitions/pbResetUserResponse"
            }
          }
        },
        "parameters": [
          {
            "name": "body",
            "in": "body",
            "required": true,
            "schema": {
              "$ref": "#/definitions/pbResetUserRequest"
            }
          }
        ],
        "tags": [
          "Users"
        ]
      }
    },
    "/auth/v1/user": {
      "post": {
        "operationId": "CreateUser",
        "responses": {
          "200": {
            "description": "A successful response.",
            "schema": {
              "$ref": "#/definitions/pbCreateUserResponse"
            }
          }
        },
        "parameters": [
          {
            "name": "body",
            "in": "body",
            "required": true,
            "schema": {
              "$ref": "#/definitions/pbCreateUserRequest"
            }
          }
        ],
        "tags": [
          "Users"
        ]
      }
    },
    "/auth/v1/user/list": {
      "get": {
        "operationId": "ListUsers",
        "responses": {
          "200": {
            "description": "A successful response.",
            "schema": {
              "$ref": "#/definitions/pbListUsersResponse"
            }
          }
        },
        "parameters": [
          {
            "name": "pagination.enabled",
            "in": "query",
            "required": false,
            "type": "boolean",
            "format": "boolean"
          },
          {
            "name": "pagination.limit",
            "in": "query",
            "required": false,
            "type": "integer",
            "format": "int32"
          },
          {
            "name": "pagination.page",
            "in": "query",
            "required": false,
            "type": "integer",
            "format": "int32"
          },
          {
            "name": "pagination.skip",
            "in": "query",
            "required": false,
            "type": "integer",
            "format": "int32"
          },
          {
            "name": "pagination.total_rows",
            "in": "query",
            "required": false,
            "type": "integer",
            "format": "int32"
          },
          {
            "name": "pagination.total_pages",
            "in": "query",
            "required": false,
            "type": "integer",
            "format": "int32"
          },
          {
            "name": "pagination.prev_page",
            "in": "query",
            "required": false,
            "type": "integer",
            "format": "int32"
          },
          {
            "name": "pagination.next_page",
            "in": "query",
            "required": false,
            "type": "integer",
            "format": "int32"
          },
          {
            "name": "ordering.field",
            "in": "query",
            "required": false,
            "type": "string"
          },
          {
            "name": "ordering.dir",
            "in": "query",
            "required": false,
            "type": "string"
          }
        ],
        "tags": [
          "Users"
        ]
      }
    },
    "/auth/v1/user/{id}": {
      "get": {
        "operationId": "GetUser",
        "responses": {
          "200": {
            "description": "A successful response.",
            "schema": {
              "$ref": "#/definitions/pbGetUserResponse"
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "type": "string",
            "format": "uint64"
          }
        ],
        "tags": [
          "Users"
        ]
      }
    }
  },
  "definitions": {
    "errorsStatus": {
      "type": "object",
      "properties": {
        "code": {
          "type": "integer",
          "format": "int32",
          "description": "The status code, which should be an enum value of\n[google.rpc.Code][google.rpc.Code]."
        },
        "message": {
          "type": "string",
          "description": "A developer-facing error message, which should be in English. Any\nuser-facing error message should be localized and sent in the\n[google.rpc.Status.details][google.rpc.Status.details] field, or localized\nby the client."
        },
        "details": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/protobufAny"
          },
          "description": "A list of messages that carry the error details.  There is a common set of\nmessage types for APIs to use."
        }
      },
      "description": "- Simple to use and understand for most users\n- Flexible enough to meet unexpected needs\n\n# Overview\n\nThe `Status` message contains three pieces of data: error code, error\nmessage, and error details. The error code should be an enum value of\n[google.rpc.Code][google.rpc.Code], but it may accept additional error codes\nif needed.  The error message should be a developer-facing English message\nthat helps developers *understand* and *resolve* the error. If a localized\nuser-facing error message is needed, put the localized message in the error\ndetails or localize it in the client. The optional error details may contain\narbitrary information about the error. There is a predefined set of error\ndetail types in the package `google.rpc` that can be used for common error\nconditions.\n\n# Language mapping\n\nThe `Status` message is the logical representation of the error model, but it\nis not necessarily the actual wire format. When the `Status` message is\nexposed in different client libraries and different wire protocols, it can be\nmapped differently. For example, it will likely be mapped to some exceptions\nin Java, but more likely mapped to some error codes in C.\n\n# Other uses\n\nThe error model and the `Status` message can be used in a variety of\nenvironments, either with or without APIs, to provide a\nconsistent developer experience across different environments.\n\nExample uses of this error model include:\n\n- Partial errors. If a service needs to return partial errors to the client,\n    it may embed the `Status` in the normal response to indicate the partial\n    errors.\n\n- Workflow errors. A typical workflow has multiple steps. Each step may\n    have a `Status` message for error reporting.\n\n- Batch operations. If a client uses batch request and batch response, the\n    `Status` message should be used directly inside batch response, one for\n    each error sub-response.\n\n- Asynchronous operations. If an API call embeds asynchronous operation\n    results in its response, the status of those operations should be\n    represented directly using the `Status` message.\n\n- Logging. If some API errors are stored in logs, the message `Status` could\n    be used directly after any stripping needed for security/privacy reasons.",
      "title": "The `Status` type defines a logical error model that is suitable for\ndifferent programming environments, including REST APIs and RPC APIs. It is\nused by [gRPC](https://github.com/grpc). The error model is designed to be:"
    },
    "paginationPager": {
      "type": "object",
      "properties": {
        "enabled": {
          "type": "boolean",
          "format": "boolean"
        },
        "limit": {
          "type": "integer",
          "format": "int32"
        },
        "page": {
          "type": "integer",
          "format": "int32"
        },
        "skip": {
          "type": "integer",
          "format": "int32"
        },
        "total_rows": {
          "type": "integer",
          "format": "int32"
        },
        "total_pages": {
          "type": "integer",
          "format": "int32"
        },
        "prev_page": {
          "type": "integer",
          "format": "int32"
        },
        "next_page": {
          "type": "integer",
          "format": "int32"
        }
      }
    },
    "pbChangePasswordRequest": {
      "type": "object",
      "properties": {
        "sub": {
          "type": "string"
        },
        "old_password": {
          "type": "string"
        },
        "password": {
          "type": "string"
        },
        "password_confirmation": {
          "type": "string"
        }
      }
    },
    "pbChangePasswordResponse": {
      "type": "object"
    },
    "pbCreateUserRequest": {
      "type": "object",
      "properties": {
        "username": {
          "type": "string"
        },
        "password": {
          "type": "string"
        },
        "password_confirmation": {
          "type": "string"
        }
      }
    },
    "pbCreateUserResponse": {
      "type": "object",
      "properties": {
        "status": {
          "$ref": "#/definitions/errorsStatus"
        },
        "user": {
          "$ref": "#/definitions/pbUser"
        }
      }
    },
    "pbGetUserResponse": {
      "type": "object",
      "properties": {
        "status": {
          "$ref": "#/definitions/errorsStatus"
        },
        "user": {
          "$ref": "#/definitions/pbUser"
        }
      }
    },
    "pbListUsersResponse": {
      "type": "object",
      "properties": {
        "status": {
          "$ref": "#/definitions/errorsStatus"
        },
        "pagination": {
          "$ref": "#/definitions/paginationPager"
        },
        "users": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/pbUser"
          }
        }
      }
    },
    "pbOrdering": {
      "type": "object",
      "properties": {
        "field": {
          "type": "string"
        },
        "dir": {
          "type": "string"
        }
      }
    },
    "pbResetUserRequest": {
      "type": "object",
      "properties": {
        "email": {
          "type": "string"
        }
      }
    },
    "pbResetUserResponse": {
      "type": "object",
      "properties": {
        "status": {
          "$ref": "#/definitions/errorsStatus"
        },
        "mail_response": {
          "type": "string"
        }
      }
    },
    "pbUser": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "format": "uint64"
        },
        "username": {
          "type": "string"
        }
      }
    },
    "pbUserFilter": {
      "type": "object"
    },
    "protobufAny": {
      "type": "object",
      "properties": {
        "type_url": {
          "type": "string",
          "description": "A URL/resource name that uniquely identifies the type of the serialized\nprotocol buffer message. The last segment of the URL's path must represent\nthe fully qualified name of the type (as in\n`path/google.protobuf.Duration`). The name should be in a canonical form\n(e.g., leading \".\" is not accepted).\n\nIn practice, teams usually precompile into the binary all types that they\nexpect it to use in the context of Any. However, for URLs which use the\nscheme `http`, `https`, or no scheme, one can optionally set up a type\nserver that maps type URLs to message definitions as follows:\n\n* If no scheme is provided, `https` is assumed.\n* An HTTP GET on the URL must yield a [google.protobuf.Type][]\n  value in binary format, or produce an error.\n* Applications are allowed to cache lookup results based on the\n  URL, or have them precompiled into a binary to avoid any\n  lookup. Therefore, binary compatibility needs to be preserved\n  on changes to types. (Use versioned type names to manage\n  breaking changes.)\n\nNote: this functionality is not currently available in the official\nprotobuf release, and it is not used for type URLs beginning with\ntype.googleapis.com.\n\nSchemes other than `http`, `https` (or the empty scheme) might be\nused with implementation specific semantics."
        },
        "value": {
          "type": "string",
          "format": "byte",
          "description": "Must be a valid serialized protocol buffer of the above specified type."
        }
      },
      "description": "`Any` contains an arbitrary serialized protocol buffer message along with a\nURL that describes the type of the serialized message.\n\nProtobuf library provides support to pack/unpack Any values in the form\nof utility functions or additional generated methods of the Any type.\n\nExample 1: Pack and unpack a message in C++.\n\n    Foo foo = ...;\n    Any any;\n    any.PackFrom(foo);\n    ...\n    if (any.UnpackTo(\u0026foo)) {\n      ...\n    }\n\nExample 2: Pack and unpack a message in Java.\n\n    Foo foo = ...;\n    Any any = Any.pack(foo);\n    ...\n    if (any.is(Foo.class)) {\n      foo = any.unpack(Foo.class);\n    }\n\n Example 3: Pack and unpack a message in Python.\n\n    foo = Foo(...)\n    any = Any()\n    any.Pack(foo)\n    ...\n    if any.Is(Foo.DESCRIPTOR):\n      any.Unpack(foo)\n      ...\n\n Example 4: Pack and unpack a message in Go\n\n     foo := \u0026pb.Foo{...}\n     any, err := ptypes.MarshalAny(foo)\n     ...\n     foo := \u0026pb.Foo{}\n     if err := ptypes.UnmarshalAny(any, foo); err != nil {\n       ...\n     }\n\nThe pack methods provided by protobuf library will by default use\n'type.googleapis.com/full.type.name' as the type URL and the unpack\nmethods only use the fully qualified type name after the last '/'\nin the type URL, for example \"foo.bar.com/x/y.z\" will yield type\nname \"y.z\".\n\n\nJSON\n====\nThe JSON representation of an `Any` value uses the regular\nrepresentation of the deserialized, embedded message, with an\nadditional field `@type` which contains the type URL. Example:\n\n    package google.profile;\n    message Person {\n      string first_name = 1;\n      string last_name = 2;\n    }\n\n    {\n      \"@type\": \"type.googleapis.com/google.profile.Person\",\n      \"firstName\": \u003cstring\u003e,\n      \"lastName\": \u003cstring\u003e\n    }\n\nIf the embedded message type is well-known and has a custom JSON\nrepresentation, that representation will be embedded adding a field\n`value` which holds the custom JSON in addition to the `@type`\nfield. Example (for message [google.protobuf.Duration][]):\n\n    {\n      \"@type\": \"type.googleapis.com/google.protobuf.Duration\",\n      \"value\": \"1.212s\"\n    }"
    }
  }
}
Manweill commented 4 years ago

@OndraRehounek Hei, I use this json to generated success version 0.9.4,node version 10.16.0

OndraRehounek commented 4 years ago

Hi @Manweill , thank you for the fast reply. That's curious. So it should be just my error then. Thank you very much for your time!