Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize output of non-required properties
For this schema: ``` { "properties": { "a": { "const": "a" }, "b": { "const": "b" }, "c": { "const": "c" } } } ``` We currently produce the following regex (spacing added around alternatives for clarity) ``` \{("a":"a"(,"b":"b")?(,"c":"c")? |("a":"a",)?"b":"b"(,"c":"c")? |("a":"a",)?("b":"b",)?"c":"c")?\} ``` This works perfectly well, but contains redundancy. This is seen by the fact that all three alternatives would match JSON with all three fields. The difference between cases at the moment, is which field is mandatory. I propose that we make the alternatives model the choice of last field. This will produce a regex like this: ``` \{("a":"a" |("a":"a",)?"b":"b" |("a":"a",)?("b":"b",)?"c":"c")?\} ``` This will give us a shorter, but 100% equivalent regex.
- Loading branch information