Manweill / swagger-axios-codegen

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

Codegen fail when dash is present in definition #166

Closed nathanguigui closed 2 years ago

nathanguigui commented 2 years ago

Codegen fail when dash (-) is present in definitions

Swagger screenshot: Capture d’écran 2022-09-19 à 12 47 41

Env:

MacOS 21.6.0 (silicon)
Node version: v18.7.0
swagger-axios-codegen: 0.13.3

Error:

yarn run v1.22.19
$ node scripts/codegen.js
openApi version: 2.0
error SyntaxError: '{' expected. (220:37)
  218 |   
  219 | 
> 220 |   export interface github_com_company-name_services_id_submit_pkg_models_VerificationSteps {
      |                                     ^
  221 | 
  222 |     
  223 |   /**  */
    at t (node_modules/swagger-axios-codegen/node_modules/prettier/parser-typescript.js:1:285)
    at Object.parse (node_modules/swagger-axios-codegen/node_modules/prettier/parser-typescript.js:14:180461)
    at Object.parse (node_modules/swagger-axios-codegen/node_modules/prettier/index.js:9739:19)
    at coreFormat (node_modules/swagger-axios-codegen/node_modules/prettier/index.js:13252:23)
    at format (node_modules/swagger-axios-codegen/node_modules/prettier/index.js:13510:73)
    at formatWithCursor (node_modules/swagger-axios-codegen/node_modules/prettier/index.js:13526:12)
    at node_modules/swagger-axios-codegen/node_modules/prettier/index.js:44207:15
    at Object.format (node_modules/swagger-axios-codegen/node_modules/prettier/index.js:44226:12)
    at format (node_modules/swagger-axios-codegen/dist/index.js:445:31)
    at codegenAll (node_modules/swagger-axios-codegen/dist/index.js:235:68) {
  loc: { start: { line: 220, column: 37 } },
  codeFrame: '\x1B[0m \x1B[90m 218 | \x1B[39m  \x1B[0m\n' +
    '\x1B[0m \x1B[90m 219 | \x1B[39m\x1B[0m\n' +
    '\x1B[0m\x1B[31m\x1B[1m>\x1B[22m\x1B[39m\x1B[90m 220 | \x1B[39m  \x1B[36mexport\x1B[39m interface github_com_company\x1B[33m-\x1B[39mname_services_id_submit_pkg_models_VerificationSteps {\x1B[0m\n' +
    '\x1B[0m \x1B[90m     | \x1B[39m                                    \x1B[31m\x1B[1m^\x1B[22m\x1B[39m\x1B[0m\n' +
    '\x1B[0m \x1B[90m 221 | \x1B[39m\x1B[0m\n' +
    '\x1B[0m \x1B[90m 222 | \x1B[39m    \x1B[0m\n' +
    '\x1B[0m \x1B[90m 223 | \x1B[39m  \x1B[90m/**  */\x1B[39m\x1B[0m'
}
node:internal/process/promises:288
            triggerUncaughtException(err, true /* fromPromise */);
            ^
Node.js v18.7.0
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I found a temporary solution that is to fetch the content of the file and replace dash by underscore

const removeDashFromJson = async (url) => {
    const {data} = await axios.get(url)
    return JSON.stringify(data).replace(/-/gi, "_")
}
Manweill commented 2 years ago

The name cannot be specially symbol