bcherny / json-schema-to-typescript

Compile JSON Schema to TypeScript type declarations
https://bcherny.github.io/json-schema-to-typescript-browser/
MIT License
2.94k stars 391 forks source link

Wildcard not working - not output #505

Open magick93 opened 1 year ago

magick93 commented 1 year ago

I'm trying to generate ts for several files, using the example in the readme:

json2ts -i 'schemas/**/*.json'
# or
json2ts -i schemas/ -o types/

However I'm only able to get output for a single specified .json file. For example at RateType.json | json2ts > RateType.d.ts does generate.

What I've tried

The following did not generate any output.

 json2ts -i *.json --output./types
 json2ts -i ./*.json --output./types
 json2ts -i base/ -o base/
 json2ts -i base/*.json -o base/
 json2ts -i base/*.json -o base/ --help
 json2ts -i base/*.json -o base/ --help --cwd ./base
 json2ts -i base/*.json -o base/ --help --cwd=./base
 json2ts -i base/*.json -o base/ --cwd=./base
 json2ts -i base/*.json -o base/base.d.ts --cwd=./base
 json2ts -i ./base/*.json -o base/base.d.ts --cwd=./base
 json2ts -i ./base/*.json -o ./base/base.d.ts --cwd=./base
 json2ts -i ./base/*.json
 json2ts -i ./base/*.json --cwd=./base
 json2ts -i ./base/*.json --cwd=./base > > output.d.ts
 json2ts -i ./base/*.json --cwd=./base > output.d.ts
 json2ts -i *.json
 json2ts -i */*.json
 json2ts -i */*.json --cwd=base
 json2ts -i */*.json --cwd=base -out common.d.ts
 json2ts -i */*.json --cwd=base -o common.d.ts
 json2ts -i */**.json --cwd=base -o common.d.ts
 json2ts -i **/**.json --cwd=base -o common.d.ts
 json2ts -i **/**.json --cwd=base -o ./common.d.ts
 json2ts -i **/**.json --cwd=./base -o ./common.d.ts
 json2ts -i **/**.json -o ./common.d.ts
 json2ts -i **/**.json -o ./common.d.ts --cwd=base
bcherny commented 1 year ago

It's hard to know what the issue is from your description. This case is well-covered by tests, so is expected to work.

Can you comment with your directory structure (using bullets) and the contents of your schemas? A whittled down repro case would be best (ie. a single property per schema, with 2 files, should be enough to repro from the info you've shared so far).

keul commented 1 year ago

@bcherny I've the same problem with wildcardas (tried both globbing in single quote or directly a folder name).

The error I get: CLI script seems to find files properly, but then resolve them in the wrong path:

I'm in /Users/keul/projects/MYPROJECT/stac-spec, the I run…

json2ts -i '*-spec/json-schema/*.json' -o types/

[
  {
    stack: 'ResolverError: Error opening file "/Users/keul/projects/item-spec/json-schema/item.json" \n' +
      "ENOENT: no such file or directory, open '/Users/keul/projects/item-spec/json-schema/item.json'\n" +
      '    at ReadFileContext.callback (/Users/keul/projects/hedp/jsonschema-to-ts/node_modules/@bcherny/json-schema-ref-parser/cjs/resolvers/file.js:96:32)\n' +
      '    at FSReqCallback.readFileAfterOpen [as oncomplete] (node:fs:325:13)',
    code: 'ERESOLVER',
    message: 'Error opening file "/Users/keul/projects/item-spec/json-schema/item.json" \n' +
      "ENOENT: no such file or directory, open '/Users/keul/projects/item-spec/json-schema/item.json'",
    source: '/Users/keul/projects/item-spec/json-schema/item.json',
    path: null,
    toJSON: [Function: toJSON],
    ioErrorCode: 'ENOENT',
    name: 'ResolverError',
    footprint: 'null+/Users/keul/projects/item-spec/json-schema/item.json+ERESOLVER+Error opening file "/Users/keul/projects/item-spec/json-schema/item.json" \n' +
      "ENOENT: no such file or directory, open '/Users/keul/projects/item-spec/json-schema/item.json'",
    toString: [Function: toString]
  }
]

One of the resolved file is /Users/keul/projects/item-spec/json-schema/item.json. The file name is OK, but is missing some intermediate subfolders.

This should be easy to reproduce as I'm trying to generate TS interfaces for the STAC spec repo.