Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openapitools.json + generate error: requires option '-i' #43

Closed
streetclaw opened this issue Oct 5, 2020 · 13 comments
Closed

openapitools.json + generate error: requires option '-i' #43

streetclaw opened this issue Oct 5, 2020 · 13 comments

Comments

@streetclaw
Copy link

Running openapi-generator-cli generate without additional parameter is not working: [error] Required option '-i' is missing

openapitools.json:

{
  "$schema": "node_modules/@openapitools/openapi-generator-cli/config.schema.json",
  "spaces": 2,
  "generator-cli": {
    "version": "5.0.0-beta2",
    "project-ts": {
        "generatorName": "typescript-axios",
        "output": "#{cwd}/src/api/#{name}",
        "glob": ".apiSchema/swagger/*.json"
    }
  }
}

package.json (excerpt):

"scripts": {
"generate:openapi": "openapi-generator-cli generate"
}
  • command: npm run generate:openapi in project root
  • valid openapi json in .apiSchema/swagger
  • CLI version: 2.0.2
  • Locally installed
@kay-schecker
Copy link
Contributor

I guess it's an issue with the current cwd. I'll fix it asap

@kay-schecker
Copy link
Contributor

which OS, Node and NPM you are using?

@streetclaw
Copy link
Author

streetclaw commented Oct 5, 2020

  • npm: 6.14.8
  • node: 14.12.0 / 14.13.0 (also present with the newest version)
  • os: macOS 10.15.7

edit: running npm with --verbose shows that CWD points to the project root where the openapitools.json is located in.

@kay-schecker
Copy link
Contributor

fixed with v2.0.3

@streetclaw
Copy link
Author

streetclaw commented Oct 9, 2020

The error still appears with version 2.0.3. At least for me. Minimal example (tested on macOS, arch linux and windows):
cli_example.zip

  1. run npm install to install openapi-generator-cli version 2.0.3
  2. run npm run generate:openapi

@kay-schecker
Copy link
Contributor

Thanks, I'll check

@kay-schecker
Copy link
Contributor

kay-schecker commented Oct 9, 2020

You missed the generators node:

{
  "$schema": "node_modules/@openapitools/openapi-generator-cli/config.schema.json",
  "spaces": 2,
  "generator-cli": {
    "version": "5.0.0-beta2",
    "generators": {
      "project-ts": {
        "generatorName": "typescript-axios",
        "output": "#{cwd}/src/api/#{name}",
        "glob": ".apiSchema/swagger/*.json"
      }
    }
  }
}

@kay-schecker
Copy link
Contributor

I'll add a new feature to validate the given config ...

@streetclaw
Copy link
Author

Yes, sorry I should have noticed.

@RichardBradley
Copy link

I still get this error on the latest version.

Is there a workaround? I can't even figure out how to get this tool to print what Java command it is invoking so I can work around.

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

Any ideas what I can do to diagnose or fix?

@RichardBradley
Copy link

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

.. still not sure 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.

@momesana
Copy link

momesana commented Feb 25, 2023

We have the same issue with pnpm. It happens when we invoke openapi-generator-cli (version 6.3.0) via pnpm (version 7.27.0) with the --dir flag from outside the project's root folder i.e.:

pnpm --dir <path to the projects root folder> run generate-sources

generate-sources in turn is defined as follows in the respective package.json's script section:

"generate-sources": "openapi-generator-cli generate"

The generation of types runs as part of the CI on windows, mac and linux. It only fails on windows. Furthermore it didn't cause any problems when used in conjunction with yarn and only appeared after switching to pnpm. The workaround for us is to change into the project directory and execute pnpm without --dir. It's worth noting that we have a bunch of different scripts all executed with --dir and they work flawlessly across all systems so this is likely an issue that pertains to openapi-generator-cli and not to pnpm.

@tajnymag
Copy link

Found the issue!

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.

tajnymag added a commit to vsb-eink/vsb-eink-services that referenced this issue Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants