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

openapi 3.0.0 Can not load the content of the Swagger specification file #34

Closed ivtm86 closed 6 years ago

ivtm86 commented 6 years ago

Hi, if i try to start cli command snc .\swagger\swagger.yaml -o .\api i get displayed follow Exception:

Can not load the content of the Swagger specification file { Error: ENOENT: no such file or directory, open 'C:...\swagger\swagger.yaml' errno: -4058, code: 'ENOENT', syscall: 'open', path: 'C:\...\swagger\swagger.yaml' } Aaww �. Something went wrong: TypeError: Cannot read property 'basePath' of undefined at swagger2 (C:...\swagger-node-codegen\lib\swagger2.js:57:30) at

here is servers definition in yaml

_servers: url: http://localhost:10010/v1

fmvilas commented 6 years ago

This is super weird. I can see you're using Windows and I've never tested it on that OS. I wonder if it has something to with slashes/backslashes difference in Windows/Unix, given that the error says it can't find the file.

Could you help me debug this issue? Your help here would be very valuable.

ivtm86 commented 6 years ago

Hi, i want to try help make package windows usable. I moved yaml file to Project root and restart command again.

_snc .\swagger.yaml -o .\api

Now i get new Exception.

Aaww �. Something went wrong:
TypeError: Cannot read property 'basePath' of undefined
    at swagger2 (C:\..\AppData\Roaming\npm\node_modules\swagger-node-codegen\lib\swagger2.js:57:30)
    at <anonymous> 

the Question is why swagger2.js file? My yaml file is wrote in openapi 3.0.0 version. Line 57 : swagger.basePath = swagger.basePath || ''; typeof swagger is undifined

fmvilas commented 6 years ago

Yeah, swagger2.js file name is just legacy stuff, but it's fine. This file is in charge of beautifying the swagger/openapi file. Honestly, I don't think the error is happening there, my guess is that your Swagger file is not being read at all. The reason I don't know.

adrienucp commented 6 years ago

Hi, just for information, I also tried to use it on Windows with OAS 3.0.0 inputs and it worked but with some problems:

So executing a second time will produce expected result but template folder is modified which is not expected.

fmvilas commented 6 years ago

@adrienucp you mean you tried this package or the openapi-generator package?

fmvilas commented 6 years ago

Sorry, I meant the openapi3-generator package: https://github.com/fmvilas/openapi3-generator.

adrienucp commented 6 years ago

This package

fmvilas commented 6 years ago

Yeah, what I mean is that this package is going to get deprecated soon, and wanted to know if you've tried https://github.com/fmvilas/openapi3-generator. Probably, it will solve the issues you're having. Sorry if I'm not of much help here, but I really don't have time to try it on Windows and figure out what's happening. Any help would be very appreciated.