OpenAPITools/openapi-generator-cli

[BUG] "Required option '-i' is missing"

RichardBradley opened this issue ยท 17 comments

๐Ÿ› Bug Report:

Describe the bug

When I run npx openapi-generator-cli generate, I get the following error:

$ npx openapi-generator-cli genera
[error] Required option '-i' is missing

Steps to Reproduce

I'm on v 2.5.2 (latest at time of writing), Cygwin on Windows, Node 14. Here's all relevant info I can think of:

$ npx --version
6.14.17
$ npm --version
6.14.17
$ node --version
v14.20.0
$ npx openapi-generator-cli version
6.0.1
$ grep openapi-generator ../../package.json
    "@openapitools/openapi-generator-cli": "^2.5.2",
$ cat openapitools.json
{
  "$schema": "../../node_modules/@openapitools/openapi-generator-cli/config.schema.json",
  "spaces": 2,
  "generator-cli": {
    "version": "6.0.0",
    "generators": {
      "my-spec-gen": {
        "generatorName": "typescript-rxjs",
        "output": "./generated",
        "inputSpec": "./reference/my-spec.yaml"
      }
    }
  }
}
$ npx openapi-generator-cli generate
Download 6.0.1 ...
Downloaded 6.0.1
[error] Required option '-i' is missing

Expected behavior

openapi-generator-cli should invoke openapi-generator-cli with correct args in order to regenerate my models

Operation System (please complete the following information):

  • OS: Windows 10, Cygwin

Package System (please complete the following information):

npm 6.14.17, node v14.20.0

I get the same on Node 18

Additional context

This appears to be the same issue described in #43 that is marked fixed.

I was able to work around by invoking Java directly:

java -jar ../../node_modules/@openapitools/openapi-generator-cli/versions/6.0.1.jar generate -i ./reference/my-api.yaml -o generated -g typescript-rxjs

I can't see what's up with openapi-generator-cli or how to diagnose further. I wasn't able to get any diagnostic logs, and the main.js seems minified so I couldn't investigate further.

I can confirm the bug, after a fresh install of @openapitools/openapi-generator-cli": "^2.7.0" in the package.json and invoking it through npm run in a linux github codespace.
Also the openapitools.json is overwritten for me.

Installing it globally and using only the command line options worked for me (as a workaround)

I had the same issue while trying to run generate without arguments from within a subfolder of my project. I โ€œfixedโ€ it by putting my openapitools.json in the project root (the same level as my package.json) and adjusting my paths (inputSpec, output, config, etc.) relative to the project root.

After invoking the generator via a NPM script from my package.json, e.g.

"scripts": {
    "generate": "openapi-generator-cli generate"
},

via npm run generate all worked as expected.

To get the issue back on track: The problem is not that "-i is missing", but that the openapitools.json is simply ignored when running openapi-generator-cli generate --generator-key v1.0. (or openapi-generator-cli generate)

Im pretty sure of this, because when i specify -i manually the cmd complains about generator name as so on.. even tho they are all defined in the json.

This seems to have been fixed in the latest version.
It's no longer happening for me at any rate

thanks for the confirmation

just so you know we just released openapi-generator v7.3.0

Experiencing this as well. Only on Windows.
provectus/kafka-ui#1582

@wing328 it's not fixed in 7.3.0, just tried that out.

Can confirm it still happens on 7.4.0

are you guys using Windows? are you using DOS prompt?

it works for me on Windows 11, JDK17 with DOS command prompt.

are you guys using Windows? are you using DOS prompt?

it works for me on Windows 11, JDK17 with DOS command prompt.

Running both Windows 11 and JDK17.

Can reproduce in conhost too, but I mainly use pwsh in Windows Terminal. That doesn't seem to be the issue.

I'm probably in a wrong issue though, my issue is mainly related to this issue: #43.

I'm using pnpm and I'm calling the generator from a package.json script.

Found the issue. At least in my case.

Openapi-generator-cli is using INIT_CWD as its working directory:

public readonly cwd = process.env.PWD || process.env.INIT_CWD || process.cwd()

When I ran my pnpm test script from a different directory (pnpm -r or pnpm run --dir) I got:

> node cwd-test.js

process.env.PWD undefined
process.env.INIT_CWD C:\Users\marek\GitHub\vsb-eink-services
process.cwd() C:\Users\marek\GitHub\vsb-eink-services\packages\facade-api-client

There's an issue in pnpm discussing where INIT_CWD is supposed to point.

thanks for sharing the details.

as a workaround, please use npm instead.

Hi @wing328 using npm (assuming below is what you meant) does not work. I tried the following,

npm install -g @openapitools/openapi-generator-cli

And then ran,

openapi-generator-cli generate

Still same error,

[error] Required option '-i' is missing

Edit: Using version 7.4.0 on Ubuntu 22.04

the latest version of the npm wrapper allows you to specify the openapitools.json file. can you please give it a try?

#754

Hi @wing328 thanks for the follow up. After much debugging I discovered that the same error is given if the openapitools.json file does not follow the openapi-generator-cli schema (I didn't have the generators within the generator object).

Its now working as expected on the latest release.

Hello @wing328,
My situation is similar to the one described on #690 (comment)
The difference is that in my windows environment the process.env.PWD is filled but it has the wrong project path, as showed below

- process.env.PWD: /c/Users/lpinto/xxxxx
- process.env.INIT_CWD: C:\Users\lpinto\xxxxx
- process.cwd(): C:\Users\lpinto\xxxxx

I'm using npm to run "openapi-generator-cli generate" command

npm --version
npm verb cli C:\Users\lpinto\.nvs\default\node.exe C:\Users\lpinto\.nvs\default\node_modules\npm\bin\npm-cli.js
npm info using npm@9.6.7
npm info using node@v18.17.1
npm verb title npm
npm verb argv "--version"
npm verb logfile logs-max:10 dir:C:\Users\lpinto\AppData\Local\npm-cache\_logs\2024-03-25T08_16_04_423Z-
npm verb logfile C:\Users\lpinto\AppData\Local\npm-cache\_logs\2024-03-25T08_16_04_423Z-debug-0.log
9.6.7
npm verb exit 0
npm info ok

I found this comment #758 (comment), and I believe it could solve my situation.

Has a workaround I have to define all the configurations like this "openapi-generator-cli generate -i xx -g xxx -o xxx -c openapitools.json", but this way I am repeating the settings that exist within the openapitools.json file.

I think openapi-generator-cli should really just use process.cwd()... With INIT_CWD it seems to often gen invoked in the current directory even when running scripts recursively from a different folder. And PWD is essentially process.cwd() on Linux/macOS, but doesn't exist in Windows, which causes the behavior to vary...