Search code examples
node.jslinuxnpmopenapiopenapi-generator

SERVER generators using OpenAPI Generator


I am using the OpenAPI Generator https://openapi-generator.tech/ for generating clients and servers as listed in the OpenApi generator list https://openapi-generator.tech/docs/generators.

I have installed openapi-generator-cli using npm i.e. $ npm install @openapitools/openapi-generator-cli -g.

Output on terminal:

/usr/local/bin/openapi-generator -> /usr/local/lib/node_modules/@openapitools/openapi-generator-cli/bin/openapi-generator /usr/local/lib └── @openapitools/openapi-generator-cli@1.0.15-4.3.1

However, after I am trying to generate a ruby client from a valid petstore.yaml doc:

$ openapi-generator generate -i petstore.yaml -g ruby -o /tmp/test/

I keep getting an error:

/usr/local/lib/node_modules/@openapitools/openapi-generator-cli/bin/openapi-generator:3
const {spawn} = require('child_process');
      ^

SyntaxError: Unexpected token {
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:374:25)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Function.Module.runMain (module.js:442:10)
    at startup (node.js:136:18)
    at node.js:966:3

PS! I've $ npm -v version 3.5.2 and $ nodejs -v version v4.2.6.

Any insight into this issue?

Thanks & looking forward.


Solution

  • I actually solved the issue and the error was due to the npm & nodejs version.

    Previsouly, I had $npm -v version 3.5.2 and $ nodejs -v version v4.2.6. .

    But after I pull node-v12.18.3 source code from https://nodejs.org/en/download/ and install it from source using:

    cd ~/node-v12.18.3
    ./configure
    make -j 4
    sudo make install
    
    

    And then I have installed openapi-generator-cli using npm i.e. $ npm install @openapitools/openapi-generator-cli -g. And finally, I can generate a ruby client from a valid petstore.yaml doc using:

    openapi-generator generate -i petstore.yaml -g ruby -o /tmp/test/
    
    arslan@arslan:/tmp/test$ ls
    docs  Gemfile  git_push.sh  lib  openapi_client.gemspec  Rakefile  README.md  spec
    

    PS! After compiling node-v12.18.3 from source It show up $ npm -v 6.14.6 $ node -v v12.18.3.