fmvilas / swagger-node-codegen

An OpenAPI 3.x/Swagger 2 code generator for Node.js
Apache License 2.0
200 stars 55 forks source link

Target dir can't handle relative paths properly #21

Closed Vaelor closed 6 years ago

Vaelor commented 6 years ago

Running snc -t ./api-templates -o ./src/app/services/gen/ schema.yaml

Results in some files being moved to the output folder, but not all. Update Only files that do not begin with ___ are moved to the correct folder.

The rest is put into the template folder.

My folder structure:

./api-templates/___.service.ts
./api-templates/api.module.ts
# generate to:
./src/app/services/gen/

Edit: The below was not correct! See my other comment

Location of the issue seems to be

target_dir: program.output,
  templates: program.templates ? path.resolve(process.cwd(), program.templates) : undefined

Where templates: uses path.resolve, target_dir: does not.

Vaelor commented 6 years ago

Correction: https://github.com/fmvilas/swagger-node-codegen/blob/83cee35d23dd19986f4ec22d207d03026d4f8db5/lib/codegen.js#L70 Leaving out subdir, fixes the issue. Guess subdir is needed if templates are in subdirectories.. I guess checking if subdir is the same as config.templates_dir and then 'leave subdir out for the path.resolve' could fix this issue by not breaking anything else.. Not 100% sure though.

fmvilas commented 6 years ago

Oh, good catch @Vaelor. Will investigate and try to fix it. Thanks for reporting!

fmvilas commented 6 years ago

This is now fixed, released and on npm. Thanks!

Vaelor commented 6 years ago

Well that was really fast! Thanks a lot! Can confirm this works now!

fmvilas commented 6 years ago

Great! You're welcome!