Manweill / swagger-axios-codegen

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

Error when generating from openApi 3.0.1 version #90

Closed mort3za closed 4 years ago

mort3za commented 4 years ago

Hi, After updating our API to openApi 3, this tool is not working anymore. The output error is:

openApi version: 3.0.1
isV3 true
(node:24279) UnhandledPromiseRejectionWarning: TypeError: Expected the input to be `string | string[]`
    at Object.camelCase [as default] (/home/***/www/***/node_modules/camelcase/index.js:34:9)
    at Object.requestCodegen (/home/***/www/***/node_modules/swagger-axios-codegen/src/requestCodegen/index.ts:89:41)
    at /home/***/www/***/node_modules/swagger-axios-codegen/src/index.ts:67:22
    at Generator.next (<anonymous>)
    at fulfilled (/home/***/www/***/node_modules/swagger-axios-codegen/dist/index.js:5:58)
    at processTicksAndRejections (internal/process/task_queues.js:94:5)
(node:24279) 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: 1)
(node:24279) [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.

My codegen config is:

const { codegen } = require('swagger-axios-codegen');
const { BASE_API } = require('../constants/connection');

codegen({
  methodNameMode: 'operationId',
  remoteUrl: `${BASE_API}/swagger/v0/swagger.json`,
  useStaticMethod: true,
  outputDir: './temp/',
  fileName: 'resources.ts'
});

This is the Swagger page: https://api-ctyar.fandogh.cloud/index.html

fairking commented 4 years ago

I am using API v3 and everything is working fine so far. I am using swagger-axios-codegen v. 0.9.12. Could you please check if that version is working for you?

mort3za commented 4 years ago

@fairking Tried 0.9.12, returns this error:

error TypeError: Expected the input to be `string | string[]`
    at Object.camelCase [as default] (/home/***/www/***/node_modules/camelcase/index.js:34:9)
    at Object.requestTemplate (/home/***/www/***/node_modules/swagger-axios-codegen/src/templates/template.ts:204:55)
    at /home/***/www/***/node_modules/swagger-axios-codegen/src/index.ts:205:19
    at Array.forEach (<anonymous>)
    at /home/***/www/***/node_modules/swagger-axios-codegen/src/index.ts:203:18
    at Array.forEach (<anonymous>)
    at /home/***/www/***/node_modules/swagger-axios-codegen/src/index.ts:201:22
    at Generator.next (<anonymous>)
    at fulfilled (/home/***/www/***/node_modules/swagger-axios-codegen/dist/index.js:5:58)
    at processTicksAndRejections (internal/process/task_queues.js:94:5)
finish: 2262.249ms
(node:29601) UnhandledPromiseRejectionWarning: TypeError: Expected the input to be `string | string[]`
    at Object.camelCase [as default] (/home/***/www/***/node_modules/camelcase/index.js:34:9)
    at Object.requestTemplate (/home/***/www/***/node_modules/swagger-axios-codegen/src/templates/template.ts:204:55)
    at /home/***/www/***/node_modules/swagger-axios-codegen/src/index.ts:205:19
    at Array.forEach (<anonymous>)
    at /home/***/www/***/node_modules/swagger-axios-codegen/src/index.ts:203:18
    at Array.forEach (<anonymous>)
    at /home/***/www/***/node_modules/swagger-axios-codegen/src/index.ts:201:22
    at Generator.next (<anonymous>)
    at fulfilled (/home/***/www/***/node_modules/swagger-axios-codegen/dist/index.js:5:58)
    at processTicksAndRejections (internal/process/task_queues.js:94:5)
(node:29601) 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: 1)
(node:29601) [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.
Manweill commented 4 years ago

@mort3za The request dose not has operationId on your swagger spec . Please set options.methodNameMode:path or generate operationId