wcandillon/swagger-js-codegen

Is this codegen compatible with openapi 3.0.0?

gvlekke opened this issue · 3 comments

I have a openapi 3.0.0 swagger file and i want to create the code for that:

CodeGen.getReactCode({className: 'Api', swagger: swagger});

The result of this is that I get this error:

TypeError: Cannot read property 'forEach' of undefined
    at getViewForSwagger1 (/Users/gvlekke/myapp/node_modules/swagger-js-codegen/lib/codegen.js:202:17)
    at getCode (/Users/gvlekke/myapp/node_modules/swagger-js-codegen/lib/codegen.js:258:82)
    at Object.getReactCode (/Users/gvlekke/myapp/node_modules/swagger-js-codegen/lib/codegen.js:326:16)
    at Function.generateApiCode (/Users/gvlekke/myapp/tasks/generate-swagger-code.js:25:40)
    at Function.generateApi (/Users/gvlekke/myapp/tasks/generate-swagger-code.js:8:18)
    at Object.<anonymous> (/Users/gvlekke/myapp/tasks/generate-swagger-code.js:34:16)
    at Module._compile (module.js:573:30)
    at Object.Module._extensions..js (module.js:584:10)
    at Module.load (module.js:507:32)
    at tryModuleLoad (module.js:470:12)

Am I doing something wrong or is this generator not compatible with openapi 3.0.0 ?

@gvlekke I don't think this generator is compatible wtih 3.0.0, if you see this line of code

var data = opts.swagger.swagger === '2.0' ? getViewForSwagger2(opts, type) : getViewForSwagger1(opts, type);

it seems to only support 2 or 1. 😓

yeah I already thought that... hope it will update soon

Just now, you can simply replace "openapi": "3.0.0" => "swagger": "2.0". Сrutch, but works 😬