openapi-generator-cli icon indicating copy to clipboard operation
openapi-generator-cli copied to clipboard

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

Open RichardBradley opened this issue 2 years ago • 18 comments
trafficstars

🐛 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.

RichardBradley avatar Mar 03 '23 17:03 RichardBradley

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)

DanielHabenicht avatar Oct 14 '23 19:10 DanielHabenicht

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.

a-stangl avatar Dec 04 '23 12:12 a-stangl

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.

RobinMeow avatar Dec 10 '23 16:12 RobinMeow

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

RichardBradley avatar Feb 08 '24 09:02 RichardBradley

thanks for the confirmation

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

wing328 avatar Feb 08 '24 09:02 wing328

Experiencing this as well. Only on Windows. https://github.com/provectus/kafka-ui/issues/1582

Haarolean avatar Feb 09 '24 15:02 Haarolean

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

Haarolean avatar Feb 09 '24 15:02 Haarolean

Can confirm it still happens on 7.4.0

tajnymag avatar Mar 11 '24 15:03 tajnymag

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

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

wing328 avatar Mar 11 '24 16:03 wing328

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: https://github.com/OpenAPITools/openapi-generator-cli/issues/43.

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

tajnymag avatar Mar 11 '24 17:03 tajnymag

Found the issue. At least in my case.

Openapi-generator-cli is using INIT_CWD as its working directory: https://github.com/OpenAPITools/openapi-generator-cli/blob/7e43a4e4f91148dede80fb7849eb473db759eb17/apps/generator-cli/src/app/services/config.service.ts#L10

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.

tajnymag avatar Mar 11 '24 17:03 tajnymag

thanks for sharing the details.

as a workaround, please use npm instead.

wing328 avatar Mar 12 '24 03:03 wing328

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

wilml avatar Mar 19 '24 16:03 wilml

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

https://github.com/OpenAPITools/openapi-generator-cli/pull/754

wing328 avatar Mar 20 '24 03:03 wing328

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.

wilml avatar Mar 20 '24 17:03 wilml

Hello @wing328, My situation is similar to the one described on https://github.com/OpenAPITools/openapi-generator-cli/issues/690#issuecomment-1989068808 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 [email protected]
npm info using [email protected]
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 https://github.com/OpenAPITools/openapi-generator-cli/issues/758#issuecomment-1979938324, 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.

lpinto-adn avatar Mar 25 '24 08:03 lpinto-adn