HomePhabricator
Diffusion Comm 92fcaebcb29c

[lib] Handle other tcomb types in extendResponderValidatorBase

Description

[lib] Handle other tcomb types in extendResponderValidatorBase

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

Reviewers: tomek, ashoat, kamil

Reviewed By: ashoat

Differential Revision: https://phab.comm.dev/D12205

Details

Provenance
inkaAuthored on May 23 2024, 6:33 AM
Reviewer
ashoat
Differential Revision
D12205: [lib] Handle other tcomb types in extendResponderValidatorBase
Parents
rCOMMbb773af95385: [lib] Fix invite links validation
Branches
Unknown
Tags
Unknown