fastify/help

How to apply a transform function on `fluent-json-schema`

bacloud22 opened this issue · 0 comments

Hi,
fluent-json-schema is used for validation, but I want to add a transformer (trim in my case), that I'm thinking it can go hand in hand with validaiton.

For reference, I looked for answers, and this relates: https://stackoverflow.com/a/63305773

But I'm using fluent-json-schema specifically:

// example: How to trim string values here?

import S from 'fluent-json-schema'

export const signupSchema = S.object()
    .prop('unique_tab_id', S.string().minLength(36).maxLength(36))
    .prop('username', S.string().format(S.FORMATS.EMAIL))
    .prop('password', S.string().minLength(4).maxLength(40))
    .prop('firstName', S.string().minLength(2).maxLength(40))
    .prop('secondName', S.string().minLength(2).maxLength(40))
    .required(['username', 'password', 'firstName', 'secondName'])

If this is not possible, do you think it is useful to add some transform function for fluent-json-schema as an option ?

Kindly