Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: merge compatible definitions in union types #722

Draft
wants to merge 7 commits into
base: next
Choose a base branch
from

Commits on Mar 25, 2021

  1. fix: Merge compatible definitions in union types

    Most validation keywords apply to only one of the basic types, so a
    "string" type and an "array" type can share a definition without
    colliding as a ["string", "array"] type, as long as they don't have any
    incompatibilities with each other. Modify UnionTypeFormatter to collapse
    these disjoint types into a single definition, without using anyOf.
    dmchurch committed Mar 25, 2021
    Configuration menu
    Copy the full SHA
    246b65c View commit details
    Browse the repository at this point in the history
  2. Update src/Utils/mergeDefinitions.ts

    Change the array.flat() call to use spread notation, since both members are guaranteed to be arrays (unlike the types call, above). Thanks for the suggestion, @domoritz!
    
    Co-authored-by: Dominik Moritz <domoritz@gmail.com>
    dmchurch and domoritz committed Mar 25, 2021
    Configuration menu
    Copy the full SHA
    6b0e19b View commit details
    Browse the repository at this point in the history

Commits on Mar 26, 2021

  1. Updating test snapshots; fixing reachability tests

    The vega-lite test originally worked after updating the snapshot, but
    there was a broken reference that got mistakenly purged by
    removeUnreachable (which assumed that any definition would
    only ever have a single property that could hold references).
    
    Added a validation check to vega-lite.test to register the failure,
    updated addReachable to check all possible properties (unless
    $ref is set; the spec says that everything else gets ignored in
    that case).
    dmchurch committed Mar 26, 2021
    Configuration menu
    Copy the full SHA
    109b78e View commit details
    Browse the repository at this point in the history

Commits on Mar 27, 2021

  1. Configuration menu
    Copy the full SHA
    291ebf9 View commit details
    Browse the repository at this point in the history

Commits on Mar 28, 2021

  1. Adding functional tests, mergeDefinitions tests

    In addition to the raw schema tests which just check that nothing has
    changed since the last snapshot, this adds makeExemplar, which builds
    a raw value using the parsed BaseType representation of a TypeScript
    type tree. This way, tests can specify valid/invalid data to be verified
    using the Ajv validator in addition to raw schema output tests.
    dmchurch committed Mar 28, 2021
    Configuration menu
    Copy the full SHA
    30c22f7 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    58f0dc9 View commit details
    Browse the repository at this point in the history
  3. mergeDefinitions works on trivially-mergable types

    In a few simple cases like (1 | number), mergeDefinitions will now
    correctly collapse two not-quite-disjoint type definitions together,
    by discarding the validation restrictions on the more-restricted type.
    This replaces the string-merging logic in UnionTypeFormatter, which
    was discarding annotations.
    dmchurch committed Mar 28, 2021
    Configuration menu
    Copy the full SHA
    79d1855 View commit details
    Browse the repository at this point in the history