/
githubmirror
/
novu
Обзор
Документация
Войти
/
githubmirror
/
novu
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
next
docs/framework/schema/class-validator.mdx
78 строк
3 KB
mintlify[bot]
docs(docs): Apply SEO and metadata best practices (#11903)
13 июл 2026, 11:22
Не верифицирован
13 июл 2026, 11:22
01f36ae
Код
Авторство
О чём код?
--- title: "Class Validator" description: "Integrate class-validator with Novu Framework to validate workflow payload and step control schemas using TypeScript class decorators." --- Novu Framework allows you to use [Class Validator](https://www.npmjs.com/package/class-validator) to define the [Control](/framework/controls) and [Payload](/framework/payload) schemas for your workflows. ## Add class validator to your project <Steps> <Step title="Install Class Validator Packages"> ```bash npm install class-validator class-validator-jsonschema reflect-metadata ``` Novu requires the `class-validator-jsonschema` package to generate JSON schemas from your DTOs. You may also need the `reflect-metadata` package. </Step> <Step title="Use Class Validator in your workflow"> After installation, the Class Validator DTOs can be used interchangeably with the `controlSchema` and `payloadSchema` options in your workflow definitions. ```tsx class TestComponent { @IsString() subject: string; @IsString() content: string; } class TestControlSchema { @IsBoolean() hideBanner: boolean; @IsString() @IsNotEmpty() @IsOptional() subject?: string; // Allowing no code control over the component in the Dashboard UI @Type(() => NewSignUpComponent) @NestedValidation({ each: true }) @IsOptional() components?: NewSignUpComponent[]; } class TestPayloadSchema { @IsString() username: string; } export const testWorkflow = workflow('test-workflow', async ({ step, payload }) => { await step.email('send-email', async (controls) => { return { subject: controls.subject, body: 'Hello, World!', }; }, { controlSchema: TestControlSchema, }); }, { payloadSchema: TestPayloadSchema, }); ``` </Step> </Steps> ## Controls and Payload UI When you define a `controlSchema` for a step, Novu will automatically generate a UI for the controls in the workflow editor. - **Form Input Title** - Will be derived from the key of the Class Validator schema. Unfortunately Class Validator does not support custom titles at this point. - **Form Input Type** - Will be derived from the Class Validator schema type, with support for `string`, `number`, `boolean`, and `enum` and `array` types. - **Default Value** - Unfortunately Class Validator does not support default values at this point. - **Validation** - Will be derived from the Class Validator schema validation decorators, including `@Min`, `@Max`, `@IsEmail`, `@IsUrl` and etc...