bcherny/json-schema-to-typescript

Inconsistent cwd options 'defaulting'

Open

#392 aperta il 27 apr 2021

Vedi su GitHub
 (0 commenti) (0 reazioni) (0 assegnatari)TypeScript (449 fork)github user discovery
buggood first issuehelp wanted

Metriche repository

Star
 (3302 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

Hello,

I noticed a inconsistent handling of the cwd option in compile because of the default function argument assignation and the merging of a default cwd value.

Case 1: no options

compileFromFile('dir/schema.json');

When providing no options, the argument will be assigned a default value options: Partial<Options> = DEFAULT_OPTIONS. The later assignation of cwd will be ignored as DEFAULT_OPTIONS already specified a cwd.

>>cwd is the execution directory of the script

Case 2: empty options

compileFromFile('dir/schema.json', {});

When providing an empty object, the default argument value won't be used. When calling compile though, a value will be assigned to cwd.

>>cwd is the directory of the schema

I think both use-case should have a consistent cwd as in both case, it hasn't been specified. I would be in favor of not providing a default function argument as the provided options and DEFAULT_OPTIONS will be merged anyway later on in compile.

Guida contributor