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

Error: ENOENT when generating schema from multiple .yaml files from another directory #1198

Closed
2 tasks done
bergac opened this issue Jul 4, 2023 · 3 comments
Closed
2 tasks done
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library stale

Comments

@bergac
Copy link

bergac commented Jul 4, 2023

Description

Error when generating schema from multiple .yaml files from another directory in the parent folder (see directory structure below).
Thus, the yaml file is not in the same folder as where the package.json is (because we reuse it for generation of code of another language).

The error I get is the following (note: I replaced the real directory with $HOME):

node:fs:600
  handleErrorFromBinding(ctx);
  ^

Error: ENOENT: no such file or directory, open '$HOME/api-contracts/typescript-generation/schemas/apis/views/DetailView.ts'
at Object.openSync (node:fs:600:3)
    at Object.writeFileSync (node:fs:2221:35)
    at generateSchema (file:///$HOME/api-contracts/typescript-generation/node_modules/openapi-typescript/bin/cli.js:125:8)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async file:///$HOME/api-contracts/typescript-generation/node_modules/openapi-typescript/bin/cli.js:198:7
    at async Promise.all (index 0)
    at async main (file:///$HOME/api-contracts/typescript-generation/node_modules/openapi-typescript/bin/cli.js:188:3) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '$HOME/api-contracts/typescript-generation/schemas/apis/views/AllocationDetailView.ts'

Name Version
openapi-typescript 6.2.8
Node.js v18.14.1
OS + version macOS 13.4.1

Reproduction

I have the following directory structure:
Directory structure:

api-contracts
+- apis
|   +- views
|   |   +- DetailView.yaml
|   +- typescript-generation
|   |  +- package.json    

And package.json looks like the following:

{
  "name": "typescript-generation",
  "version": "1.0.0",
  "description": "Typescript library for the API models",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "generate-views": "npx openapi-typescript \"../apis/views/**.yaml\" --output schemas/views/"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "openapi-typescript": "6.2.8"
  }
}

However, when I run npx openapi-typescript ./../apis/views/**.yaml --output schemas/../../views/, it works!
But the DetailView.ts is created in the api-contracts/apis/views folder.

I think the outputFilePath is mixed with the inputFilePath, while it should not, in cli.js:

const filename = pathToSpec.replace(EXT_RE, ".ts");
const originalOutputFilePath = outputFilePath;
outputFilePath = new URL(filename, originalOutputFilePath);

Expected result

Generate the DetailView.ts file in api-contracts/typescript-generation/schemas/views/.

Checklist

@bergac bergac added bug Something isn't working openapi-ts Relevant to the openapi-typescript library labels Jul 4, 2023
@pvanagtmaal
Copy link
Contributor

this might be fixed by #1281

Copy link
Contributor

github-actions bot commented Aug 6, 2024

This issue is stale because it has been open for 90 days with no activity. If there is no activity in the next 7 days, the issue will be closed.

@github-actions github-actions bot added the stale label Aug 6, 2024
Copy link
Contributor

This issue was closed because it has been inactive for 7 days since being marked as stale. Please open a new issue if you believe you are encountering a related problem.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library stale
Projects
None yet
Development

No branches or pull requests

2 participants