acacode / swagger-typescript-api

Generate the API Client for Fetch or Axios from an OpenAPI Specification
MIT License
3.38k stars 361 forks source link

command generate-templates is not working #853

Open MoJo2600 opened 3 months ago

MoJo2600 commented 3 months ago

I tried to generate the templates with the generate-templates command. I think it is not doing what it is supposed to do. I'm using version 13.0.14.

First try with pnpm:

npx swagger-typescript-api generate-templates -o src/provider/swagger-typescript-api-templates/ --http-client axios throws an error:

✨   swagger-typescript-api(13.0.12),npm/10.7.0 node/v18.20.3 linux x64 workspaces/false,debug mode DISABLED
⭐   start generating source templates ".ejs" for code generator
Error: ENOENT: no such file or directory, scandir '/workspace/backend/node_modules/.pnpm/swagger-typescript-api@13.0.12/templates/base'
    at Object.readdirSync (node:fs:1525:3)
    at G.readDir (file:///workspace/backend/node_modules/.pnpm/swagger-typescript-api@13.0.12/node_modules/swagger-typescript-api/dist/chunk-IQ7AWJFN.js:59:148)
    at Ke.getTemplateNamesFromDir (file:///workspace/backend/node_modules/.pnpm/swagger-typescript-api@13.0.12/node_modules/swagger-typescript-api/dist/chunk-IQ7AWJFN.js:61:3710)
    at Ke.getTemplates (file:///workspace/backend/node_modules/.pnpm/swagger-typescript-api@13.0.12/node_modules/swagger-typescript-api/dist/chunk-IQ7AWJFN.js:61:2588)
    at Ke.start (file:///workspace/backend/node_modules/.pnpm/swagger-typescript-api@13.0.12/node_modules/swagger-typescript-api/dist/chunk-IQ7AWJFN.js:61:1647)
    at ts (file:///workspace/backend/node_modules/.pnpm/swagger-typescript-api@13.0.12/node_modules/swagger-typescript-api/dist/chunk-IQ7AWJFN.js:61:3900)
    at K (file:///workspace/backend/node_modules/.pnpm/swagger-typescript-api@13.0.12/node_modules/swagger-typescript-api/dist/cli.js:34:5913) {
  errno: -2,
  syscall: 'scandir',
  code: 'ENOENT',
  path: '/workspace/backend/node_modules/.pnpm/swagger-typescript-api@13.0.12/templates/base'

The error is correct, the directory /workspace/backend/node_modules/.pnpm/swagger-typescript-api@13.0.12/templates/base does not exist. I think there is an issue with pnpm somehow.

But...

I tried it with npm as well, there the error is different, it does find the base directory in the node_modules package, but:

❯ ./node_modules/.bin/swagger-typescript-api generate-templates
✨   swagger-typescript-api(13.0.14),nodejs(v18.12.0),debug mode DISABLED
⭐   start generating source templates ".ejs" for code generator
Error: ENOENT: no such file or directory, scandir '/home/user/workspace/tmp/templates/base'
    at Object.readdirSync (node:fs:1451:3)
    at G.readDir (file:///home/user/workspace/tmp/node_modules/swagger-typescript-api/dist/chunk-FPPX3UNW.js:59:148)
    at qe.getTemplateNamesFromDir (file:///home/user/workspace/tmp/node_modules/swagger-typescript-api/dist/chunk-FPPX3UNW.js:61:3710)
    at qe.getTemplates (file:///home/user/workspace/tmp/node_modules/swagger-typescript-api/dist/chunk-FPPX3UNW.js:61:2588)
    at qe.start (file:///home/user/workspace/tmp/node_modules/swagger-typescript-api/dist/chunk-FPPX3UNW.js:61:1647)
    at ts (file:///home/user/workspace/tmp/node_modules/swagger-typescript-api/dist/chunk-FPPX3UNW.js:61:3900)
    at K (file:///home/user/workspace/tmp/node_modules/swagger-typescript-api/dist/cli.js:34:5981) {
  errno: -2,
  syscall: 'scandir',
  code: 'ENOENT',
  path: '/home/user/workspace/tmp/templates/base'
}

When I do create the /home/user/workspace/tmp/templates/base directory it asks for the http-clients directory and after that for default directory. Then the command seems to succeed with the message:

❯ ./node_modules/.bin/swagger-typescript-api generate-templates
✨   swagger-typescript-api(13.0.14),nodejs(v18.12.0),debug mode DISABLED
⭐   start generating source templates ".ejs" for code generator

But the directories I created are completely empty.

toxygene commented 3 months ago

I just encountered this issue as well. I tried a few previous versions of the library and it appears that both problems started with version 13.0.10.

uwucka commented 2 months ago

I installed version 12.0.4 and everything worked. For me, the trouble started with version 13 I use Node 20.12.2 and Npm 10.5.0