I am trying to convert my DTO class (Typescript) to JSON schema:
import { IsNumber, IsString } from 'class-validator';
import { classToPlain } from 'class-transformer';
export class TodoDTO {
@IsNumber()
id?: number;
@IsString()
name?: string;
@IsString()
description?: string;
}
let todo = classToPlain(TodoDTO);
console.log('todo=>', todo);
I tried to use two packages class-transformer and class-validator to transform and validate TodoDTO class.
In console it gives output as todo=> [Function: TodoDTO]
Expected output:
"TodoDTO": {
"type": "object",
"properties": {
"id": { "type": "number" },
"name": { "type": "string" },
"description": { "type": "string" }
},
"required": [ "id", "name", "description" ]
}
I am trying to use TodoDTO class as a json-schema in fastify-typescript.
Any suggestions are welcome.