toomuchdesign/openapi-ts-json-schema

Generator fails on Windows systems due to `|` character being unsupported on the platform

Closed this issue ยท 4 comments

๐Ÿ› Bug Report

Generator fails to create root path file on Windows 11. Probably a mismatched separator.

To reproduce, I've created a test repository and a test workflow. Compared to #186 this issue happens only windows and not linux.

Reproduction

Expected behavior

Specification should be considered valid and schemas should be generated normally.

Actual behavior

Error: ENOENT: no such file or directory, open 'C:\Users\marek\GitHub\openapi-ts-json-schema-poc\generated-root-path-error\paths\|.ts'
      at async open (node:internal/fs/promises:633:25)
      at async Object.writeFile (node:internal/fs/promises:1212:14)
      at async saveFile (C:\Users\marek\GitHub\openapi-ts-json-schema-poc\node_modules\openapi-ts-json-schema\dist\utils\saveFile.js:13:5)
      at async makeTsJsonSchemaFiles (C:\Users\marek\GitHub\openapi-ts-json-schema-poc\node_modules\openapi-ts-json-schema\dist\utils\makeTsJsonSchemaFiles.js:17:9)
      at async openapiToTsJsonSchema (C:\Users\marek\GitHub\openapi-ts-json-schema-poc\node_modules\openapi-ts-json-schema\dist\openapiToTsJsonSchema.js:101:5)
      at async waitForActual (node:assert:800:5)
      at async Function.doesNotReject (node:assert:941:33)
      at async generate (C:\Users\marek\GitHub\openapi-ts-json-schema-poc\test-root-path-error.cjs:19:2) {
    errno: -4058,
    code: 'ENOENT',
    syscall: 'open',
    path: 'C:\\Users\\marek\\GitHub\\openapi-ts-json-schema-poc\\generated-root-path-error\\paths\\|.ts'
  }

Run npx envinfo --preset jest

Paste the results here:

System:
    OS: Windows 11 10.0.22631
    CPU: (24) x64 13th Gen Intel(R) Core(TM) i7-13700K
  Binaries:
    Node: 21.6.2 - ~\scoop\apps\nodejs\current\node.EXE
    Yarn: 1.22.19 - ~\scoop\apps\nodejs\current\yarn.CMD
    npm: 10.2.4 - ~\scoop\apps\nodejs\current\npm.CMD
    pnpm: 8.15.3 - ~\scoop\apps\nodejs\current\pnpm.CMD

After further investigation, it seems to be caused simply by Windows not supporting | character in a filename. The repository actually can't be even cloned on a Windows system.

PS C:\Users\marek> git clone https://github.com/toomuchdesign/openapi-ts-json-schema.git
Cloning into 'openapi-ts-json-schema'...
remote: Enumerating objects: 1328, done.
remote: Counting objects: 100% (619/619), done.
remote: Compressing objects: 100% (310/310), done.
Receiving objects: 100% (1328/1328), 583.00 KiB | 8.10 MiB/s, done. 709

Resolving deltas: 100% (798/798), done.
error: invalid path 'examples/fastify-integration-plugin/definitions/petstore/schemas-autogenerated/paths/pets|{petId}.ts'
fatal: unable to checkout working tree
warning: Clone succeeded, but checkout failed.
You can inspect what was checked out with 'git status'
and retry with 'git restore --source=HEAD :/'

A usable workaround is to run the generation under WSL and rename the files manually later.

Hi @tajnymagm! Thanks for opening this issue!
This should be an easy one, we should just find a replacement for | when naming openAPI paths definitions file names, given that we cannot use forbidden caharacters.

Any suggestion?

  • v1[foo[bar
  • v1[]foo[]bar
  • v1_foo_bar
  • v1!foo!bar

I'd like not to expose a specific option for this, but happy to consider the possibility if the case.

Hi @tajnymagm! Thanks for opening this issue! This should be an easy one, we should just find a replacement for | when naming openAPI paths definitions file names, given that we cannot use forbidden caharacters.

Any suggestion?

  • v1[foo[bar
  • v1[]foo[]bar
  • v1_foo_bar
  • v1!foo!bar

I'd like not to expose a specific option for this, but happy to consider the possibility if the case.

I would stick with underscores, so v1_foo_bar. That's how 7-zip and Windows Explorer translates the character when unzipping an archive. It's simple and readable.