Skip to content

Investigate a stricter JSONSchema interface #72

Closed
@cyrilletuzi

Description

@cyrilletuzi

This lib uses the JSON schema standard (which allow to describe the structure of a JSON) to validate data retrieved from local storage.

As the goal is to validate data, this lib always supported only a subset of the JSON schema standard. But while not supporting all the features of the standard, this lib has tried until now to:

  • stay compatible with a full JSON schema (so people can use it for other purposes if needed) ;
  • be as simple as possible, for example by making type: 'object' optional when the schema already has properties.

Unfortunately, due to differences and/or limitations of TypeScript, this has lead to a mess with the JSONSchema interface in this lib:

  • autocompletion is not accurate (for example, TypeScript will propose you maxItems in any schemas, while it should be only proposed for arrays) ;
  • as the implementation has been too complex, it has lead recently to a compilation issue because of TypeScript 3.2 regression (see Issue with v7 & TypeScript 3.2 for array or object validation #64).

For v8, it is planned to resolve these problems once and for all. Investigation is needed, but here what is being considered:

  • assume a limited subset of the JSON schema standard = drop support for full JSON schemas (it is very likely that the current interface is already not compatible with all the JSON schema standard, as the standard is becoming more and more complex ; also, I don't think it's a feature widely used)

  • if we want TypeScript to be OK, a discrimitated union type must have a common required property, meaning type will become required even for objects and arrays (which is the common usage by the way).

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions