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)
Wed, Mar 12, 11:01 AM
Unknown Object (File)
Mon, Mar 3, 9:02 AM
Unknown Object (File)
Feb 19 2025, 5:30 PM
Unknown Object (File)
Feb 19 2025, 5:30 PM
Unknown Object (File)
Feb 19 2025, 5:30 PM
Unknown Object (File)
Feb 19 2025, 5:30 PM
Unknown Object (File)
Jan 11 2025, 1:34 PM
Unknown Object (File)
Dec 24 2024, 8:42 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