bcherny/json-schema-to-typescript

Inconsistent cwd options 'defaulting'

Open

#392 opened on Apr 27, 2021

View on GitHub
 (0 comments) (0 reactions) (0 assignees)TypeScript (449 forks)github user discovery
buggood first issuehelp wanted

Repository metrics

Stars
 (3,302 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

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.

Contributor guide