docs/framework/schema/class-validator.mdx
Novu Framework allows you to use Class Validator to define the Control and Payload schemas for your workflows.
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>
When you define a controlSchema for a step, Novu will automatically generate a UI for the controls in the workflow editor.
string, number, boolean, and enum and array types.@Min, @Max, @IsEmail, @IsUrl and etc...