mozilla/node-convict

Schema export consistency

Makeshift opened this issue · 5 comments

Before I open a pull request for this, I was curious if there was a design reason for it.

I've noticed that the schema that is exported with getSchema and getSchemaString are not the same as the schema that was originally supplied to Convict. In particular, two transformations happen:

  1. The format name is made lowercase
  2. The JSON object is flattened (I assume to make a.b.c work without having to deal with walking through a nested object)

In my fork I've commented out the line that makes the format name lowercase, and introduced an unflattening function that is applied to getSchema and getSchemaString to obtain an output consistent with the schema you put in. I also output properties instead.

I was just wondering if there was a reason behind these design decisions before I opened a pull request to change them (although that would require a major version bump).

A-312 commented

In e3e5171 (#353), I removed the .toLowerCase() to have the same consistent.

@Makeshift unflatten does the same thing of coerce function, is not it ?

@A-312 did you hear about json-schema drafts? If there will be a way to generate schemas in that format, some can utilize json-schema-to-typescript package and get typescript definitions for free!

A-312 commented

The last week, I take 4-5 hours to work on that to thintk if should implement json-schema or not. I choose to:

A-312 commented

@Makeshift I saw in netwok, you always pushed the same commit

image

It seems to me:

Your commit State v6
New: Force coercion even for things that aren't strings Implemented
Consistent schema exporting Improved
Stopped format name from being made lowercase Done

If that's the case, I'll take a look when I have a moment and close the issue if solved. Thanks!