bcherny / json-schema-to-typescript

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

"SyntaxError: Unexpected token in JSON at position 0" when running CLI on MacOS #582

Closed gino-m closed 8 months ago

gino-m commented 9 months ago

This occurs when running using paths to process multiple files:

npx json2ts --no-declareExternallyReferenced --cwd=schemas/ -i schemas/ -o dist/generated

The offending file is the OS-specific:

"schemas/.DS_Store"

This file should be ignored. Since I wasn't able to get $refs to work correctly with nested folders, I flattened the schema dirs . As such this workaround works:

npx json2ts --no-declareExternallyReferenced --cwd=schemas/ -i 'schemas/*.schema.json' -o dist/generated
bcherny commented 8 months ago

This is working as expected. We could filter for JSON and Yaml files explicitly, but this may break consumers that use other file extensions.

PRs are welcome if you'd like to update the last example in the CLI docs to make this more apparent: https://github.com/bcherny/json-schema-to-typescript?tab=readme-ov-file#cli

gino-m commented 8 months ago

This is working as expected. We could filter for JSON and Yaml files explicitly, but this may break consumers that use other file extensions.

Thanks for the reply. On Linux and Linux-like OSes, .* indicates a hidden file. Is it expected that json2ts CLI would pick up hidden files as well?