Effect CommunityEC
Effect Community2y ago
2 replies
staubfuss

Modeling Exclusive API Parameters in Schema

Hi all, I am dealing with an external api, which allows for either files[] or files_url[] but not both. Is there an easy way to model this in schema? My initial thought was a discriminating union, but the fields names are different, so I am a bit clueless currently. I guess I could extend from "Base Class" and use .transformOrFail.. or something like that but I wanted to quickly verify if someone has a better Idea. Another thing that I would like to implement is a maxItems/maxKeys for records but I am struggling to find a good starting point. Any hints are welcome. Thanks a lot in advance!
export class SendSignature extends S.Class<SendSignature>('SendSignature')({
    title: String255,
    subject: String255,
    message: S.NonEmpty.pipe(S.maxLength(5000)),
    signers: S.nonEmptyArray(Signer),
    cc_email_addresses: S.optional(S.nonEmptyArray(EmailSchema)),
    // file_urls: S.nonEmptyArray(S.NonEmpty),
    // files: S.nonEmptyArray(S.NonEmpty),
    metadata: S.optional(S.record(S.NonEmpty, S.unknown)), //max 10 key value pairs
    signing_options: SigningOptions,
    field_options: S.struct({
        date_format: S.NonEmpty,
    }),
    test_mode: S.boolean,
}) {}
Was this page helpful?