influxdata / oats

An OpenAPI to TypeScript generator.
MIT License
13 stars 6 forks source link

Limited requestBody content types supported #16

Open glinton opened 4 years ago

glinton commented 4 years ago

given the following section of a swagger file:

      requestBody:
        description: InfluxQL query to execute.
        content:
          application/vnd.influxql:
            schema:
              type: string

I get the following error when generating a client:

(node:67136) UnhandledPromiseRejectionWarning: TypeError: Cannot read property '0' of undefined
    at Generator.collectBodyParam (/go/src/github.com/influxdata/influxdb/ui/node_modules/@influxdata/oats/dist/generate.js:91:65)
    at Generator.registerPathOperation (/go/src/github.com/influxdata/influxdb/ui/node_modules/@influxdata/oats/dist/generate.js:40:29)
    at new Generator (/go/src/github.com/influxdata/influxdb/ui/node_modules/@influxdata/oats/dist/generate.js:24:26)
    at generate (/go/src/github.com/influxdata/influxdb/ui/node_modules/@influxdata/oats/dist/generate.js:219:23)
    at async Command.<anonymous> (/go/src/github.com/influxdata/influxdb/ui/node_modules/@influxdata/oats/bin/oats:7:18)
(node:67136) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:67136) [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.

lines 89-92 of generate.js are as follows:

        const fallbackEntry = mediaTypeEntries[0];
        if (fallbackEntry) {
            return { description, required, mediaType: textEntry[0], type: "any" };
        }

The resolution was to change the content from application/vnd.influxql to text/plain and add a header parameter

        - in: header
          name: Content-Type
          schema:
            type: string
            enum:
              - application/vnd.influxql
glinton commented 3 years ago

application/octet-stream is another, more common, content type that oats doesn't support as a request body.

Given the following swagger:

openapi: "3.0.0"
info:
  title: Stuff service
  version: 0.0.0
servers:
  - url: ""
paths:
  /stuff:
    post:
      operationId: createStuff
      requestBody:
        description: thing
        content:
          application/octet-stream:
            schema:
              type: string
      responses:
        '204':
          description: No content

This error is returned:

/src/node_modules/@influxdata/oats/dist/generate.js:91
            return { description, required, mediaType: textEntry[0], type: "any" };
                                                                ^

TypeError: Cannot read property '0' of undefined
    at Generator.collectBodyParam (/src/node_modules/@influxdata/oats/dist/generate.js:91:65)
    at Generator.registerPathOperation (/src/node_modules/@influxdata/oats/dist/generate.js:40:29)
    at new Generator (/src/node_modules/@influxdata/oats/dist/generate.js:24:26)
    at generate (/src/node_modules/@influxdata/oats/dist/generate.js:219:23)
    at async Command.<anonymous> (/src/node_modules/@influxdata/oats/bin/oats:7:18)