Page MenuHomePhabricator

[lib] Handle other tcomb types in extendResponderValidatorBase
ClosedPublic

Authored by inka on May 23 2024, 6:41 AM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Nov 7, 4:42 PM
Unknown Object (File)
Thu, Nov 7, 4:44 AM
Unknown Object (File)
Oct 16 2024, 3:32 PM
Unknown Object (File)
Oct 16 2024, 3:32 PM
Unknown Object (File)
Oct 16 2024, 3:32 PM
Unknown Object (File)
Oct 16 2024, 3:32 PM
Unknown Object (File)
Oct 15 2024, 8:22 PM
Unknown Object (File)
Oct 14 2024, 2:20 PM
Subscribers
None

Details

Summary

issue :ENG-8179
maybe, union and interface were handled in the previous diff
dict, list, enums, irreducible cannot be the top-level type returned by the endpoint and at the same time have AdditionalResponseFields added
So subtype is the only type we have to handle. subtype is a TRefinement. It is a type + function that specifies some additional properties, narrowing the possible values. For example t.Number and (item) => item % 2 === 1, which defines odd numbers.

Test Plan

Changed inviteLinkVerificationResponseValidator to be

export const inviteLinkVerificationResponseValidator: TUnion<InviteLinkVerificationResponse> =
  t.union([
    tShape({
      status: t.enums.of(['valid', 'already_joined']),
      community: tShape({
        name: t.String,
        id: tID,
      }),
    }),
    t.refinement(
      tShape({
        status: t.enums.of(['invalid', 'expired']),
      }),
      input => true,
    ),
  ]);

and checked that invite links work

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable