openapi-generator: [Node.js] server doesn't work
Description
The errors on when run npm start in nodejs server sample folder:
Error: Unsupported Swagger version: undefined
$ bin/openapi3/nodejs-petstore-server.sh
$ cd samples/server/petstore/nodejs
$ npm start
> swagger-petstore@1.0.0 start /Users/akihito1/src/github.com/ackintosh/openapi-generator/samples/server/petstore/nodejs
> node index.js
/Users/akihito1/src/github.com/ackintosh/openapi-generator/samples/server/petstore/nodejs/node_modules/swagger-tools/lib/helpers.js:169
throw new Error('Unsupported Swagger version: ' + version);
^
Error: Unsupported Swagger version: undefined
at Object.module.exports.getSpec (/Users/akihito1/src/github.com/ackintosh/openapi-generator/samples/server/petstore/nodejs/node_modules/swagger-tools/lib/helpers.js:169:15)
at Object.initializeMiddleware (/Users/akihito1/src/github.com/ackintosh/openapi-generator/samples/server/petstore/nodejs/node_modules/swagger-tools/index.js:44:18)
at Object.<anonymous> (/Users/akihito1/src/github.com/ackintosh/openapi-generator/samples/server/petstore/nodejs/index.js:24:14)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:389:7)
npm ERR! Darwin 17.4.0
npm ERR! argv "/Users/akihito1/.nodebrew/node/v6.11.1/bin/node" "/Users/akihito1/.nodebrew/current/bin/npm" "start"
npm ERR! node v6.11.1
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! swagger-petstore@1.0.0 start: `node index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the swagger-petstore@1.0.0 start script 'node index.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the swagger-petstore package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node index.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs swagger-petstore
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls swagger-petstore
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /Users/akihito1/src/github.com/ackintosh/openapi-generator/samples/server/petstore/nodejs/npm-debug.log
openapi-generator version
current master
Suggest a fix/enhancement
The error is due to the swagger-tools does not support OAS3.
(It is also occurs with OAS2 as api/openapi.yaml is always output as OAS 3.)
Users using swagger-tools did ask for it:
https://github.com/apigee-127/swagger-tools/issues/529 https://github.com/apigee-127/swagger-express/issues/20
But no reply from Apigee.
In the medium/long term, we’ll need to provide another NodeJS server generator based on other (active) frameworks: https://nordicapis.com/13-node-js-frameworks-to-build-web-apis/
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 19
- Comments: 23 (11 by maintainers)
Commits related to this issue
- Merge pull request #34 from OpenAPITools/master merge master — committed to OpenAPITools/openapi-generator by bflamand 3 years ago
- interfaceOnly support for Helidon SE, fix issue with build.gradle (#34) Signed-off-by: aserkes <andrii.serkes@oracle.com> — committed to aserkes/openapi-generator by aserkes 2 years ago
Is there any update on this? Would it be possible to document the fact that nodejs-server doesn’t work with 3.0 specs somewhere more obvious? I just wasted more time than I’d like to admit because of this.
Hello, When are you guys planning to release support for NodeJS? Thanks
Totally agree with creating another NodeJS server generator for other frameworks and later mark “nodejs-server” as deprecated.
Hi all,
I’ve filed https://github.com/OpenAPITools/openapi-generator/pull/2566 to add a new NodeJS (Fastify) server generator as an alternative as the existing NodeJS server generator won’t work due to limitations in the dependency (not supporting OpenAPI v3).
It’s still work-in-progress but worth sharing here to start collecting feedbacks.
Please check it out when you’ve time.
Thanks, William
Is this still an issue given that a NodeJs server has been added? Note that I cannot still get the new nodejs server to run.
@wing328 , @ackintosh, @emilianobonassi , with regard to an alternative OpenAPI v3 parser and object representation: you might want to look at KaiZen OpenAPI Parser.
It’s written in Java, but it also includes its own metadata description of an OAS3 object model, with mappings to the JSON/YAML representation of an OAS3 document. The classes and parsing logic are all driven from this declarative configuration file. I believe most of that code generation and runtime serialization/deserialization are handled by a related project called JSON Overlay.
It might be practical for you to port this to JavaScript/NodeJS, generating code from the same metadata format. Both KaiZen Parser and JSON Overlay were written by @andylowry , who might be able to provide some pointers if you decide to try this approach.
Still no progress. Just used the JAR on command line and got the same output as @ackintosh 😦
cc @emilianobonassi @CodeNinjai @frol @cliffano (TechnicalCommittee)
Added
nodejs-express-servergenerator (included in v4.1.0 release).Please check out the branch
nodejs-express-server(alpha) and let us know if you’ve any feedback.Thanks @YishTish for contributing the new generator.
I have forked both openapi-generator and oas3-tools and made just enough changes to get it working for my case. It is relatively untested and I make no guarantees that it will solve others’ problems, but you might like to have a look at the changes and/or use it: ellipsistechnology/openapi-generator ellipsistechnology/oas3-tools
Is there any work in progress regarding this issue? I defined my API (OAS 3.0) in swagger with the assumption that the code generation works as the openapi-generator documentation states.
If a generator is not supported or erroneous, it maybe would help to remove it from the list of supported generators in the documentation. Giving hints on the start pages of swagger.io and/or openapi-generator.tech would help as well. At least a warning which states: “Warning: Check support of target code generator.” or similar.
@ackintosh , I agree with you, we should absolutely remove
swagger-toolsdependency from this generator. Around there’s some work, e.g. https://github.com/atlassian/koa-oas3 (in TypeScript) We can draft a new Node.js gen.