openapistack / openapi-client-axios

JavaScript client library for consuming OpenAPI-enabled APIs with axios
https://openapistack.co
MIT License
558 stars 67 forks source link

TypeError: Expected `input` to be a `string`, got `undefined` #8

Closed magick93 closed 5 years ago

magick93 commented 5 years ago

Hello

Im trying to use openapi-client-axios to generate a TS client, however, when I try either typegen http://localhost:8080/openapi > src/modules/client.d.ts or typegen /home/magick93/Downloads/openapi_vaults > src/modules/client.d.ts I get the below error.

OpenAPI definition

---
openapi: 3.0.1
info:
  title: Generated API
  version: "1.0"
paths:
  /vaults:
    get:
      responses:
        200:
          description: OK
          content:
            application/json: {}
  /vaults/vault:
    post:
      requestBody:
        content:
          application/json:
            schema:
              type: string
      responses:
        200:
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Namespace'
components:
  schemas:
    Namespace:
      type: object
      properties:
        apiVersion:
          type: string
        kind:
          type: string
        metadata:
          type: object
          properties:
            annotations:
              type: object
              additionalProperties:
                type: string
            clusterName:
              type: string
            creationTimestamp:
              type: string
            deletionGracePeriodSeconds:
              format: int64
              type: integer
            deletionTimestamp:
              type: string
            finalizers:
              type: array
              items:
                type: string
            generateName:
              type: string
            generation:
              format: int64
              type: integer
            initializers:
              type: object
              properties:
                pending:
                  type: array
                  items:
                    type: object
                    properties:
                      name:
                        type: string
                result:
                  type: object
                  properties:
                    apiVersion:
                      type: string
                    code:
                      format: int32
                      type: integer
                    details:
                      type: object
                      properties:
                        causes:
                          type: array
                          items:
                            type: object
                            properties:
                              field:
                                type: string
                              message:
                                type: string
                              reason:
                                type: string
                        group:
                          type: string
                        kind:
                          type: string
                        name:
                          type: string
                        retryAfterSeconds:
                          format: int32
                          type: integer
                        uid:
                          type: string
                    kind:
                      type: string
                    message:
                      type: string
                    metadata:
                      type: object
                      properties:
                        _continue:
                          type: string
                        resourceVersion:
                          type: string
                        selfLink:
                          type: string
                    reason:
                      type: string
                    status:
                      type: string
            labels:
              type: object
              additionalProperties:
                type: string
            name:
              type: string
            namespace:
              type: string
            ownerReferences:
              type: array
              items:
                type: object
                properties:
                  apiVersion:
                    type: string
                  blockOwnerDeletion:
                    type: boolean
                  controller:
                    type: boolean
                  kind:
                    type: string
                  name:
                    type: string
                  uid:
                    type: string
            resourceVersion:
              type: string
            selfLink:
              type: string
            uid:
              type: string
        spec:
          type: object
          properties:
            finalizers:
              type: array
              items:
                type: string
        status:
          type: object
          properties:
            phase:
              type: string

Error

typegen http://localhost:8080/openapi > src/modules/client.d.ts
(node:9561) UnhandledPromiseRejectionWarning: TypeError: Expected `input` to be a `string`, got `undefined`
    at Object.module.exports [as default] (/usr/lib/node_modules/openapi-client-axios-typegen/node_modules/indent-string/index.js:11:9)
    at /usr/lib/node_modules/openapi-client-axios-typegen/typegen.js:148:36
    at Array.map (<anonymous>)
    at generateOperationMethodTypings (/usr/lib/node_modules/openapi-client-axios-typegen/typegen.js:114:39)
    at /usr/lib/node_modules/openapi-client-axios-typegen/typegen.js:96:40
    at step (/usr/lib/node_modules/openapi-client-axios-typegen/typegen.js:32:23)
    at Object.next (/usr/lib/node_modules/openapi-client-axios-typegen/typegen.js:13:53)
    at fulfilled (/usr/lib/node_modules/openapi-client-axios-typegen/typegen.js:4:58)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:9561) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 4)
(node:9561) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
anttiviljami commented 5 years ago

Looks like your OpenAPI definition is missing operationIds. Currently openapi-client-axios expects each operation to have an operationId.

anttiviljami commented 5 years ago

Closing issue due to no activity for 30 days

talolard commented 4 years ago

Just got here after reading #24 and finding swagger2openapi.

That converter doesn't add operationIds. Not sure what can be done but wanted that documented for the next person