Page MenuHomePhabricator

[lib] Handle other tcomb types in extendResponderValidatorBase
ClosedPublic

Authored by inka on May 23 2024, 6:41 AM.
Tags
None
Referenced Files
F3529683: D12205.id40616.diff
Tue, Dec 24, 8:42 PM
F3529682: D12205.id40579.diff
Tue, Dec 24, 8:42 PM
F3529664: D12205.id.diff
Tue, Dec 24, 8:42 PM
F3529661: D12205.diff
Tue, Dec 24, 8:41 PM
Unknown Object (File)
Nov 16 2024, 3:47 PM
Unknown Object (File)
Nov 7 2024, 4:42 PM
Unknown Object (File)
Nov 7 2024, 4:44 AM
Unknown Object (File)
Oct 16 2024, 3:32 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