json-schema-to-typescript icon indicating copy to clipboard operation
json-schema-to-typescript copied to clipboard

Inconsistent cwd options 'defaulting'

Open Booster2ooo opened this issue 4 years ago • 0 comments

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.

Booster2ooo avatar Apr 27 '21 14:04 Booster2ooo