Class To JSON Schema Conversion
See original GitHub issueI 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.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Free Online JSON to JSON Schema Converter
Free Online JSON to JSON Schema Converter. Uses the sample JSON document to infer a JSON schema. Download Liquid Studio Access the online...
Read more >Generate JSON schema from Java class - Stack Overflow
Use JJschema. It can generate draft 4 compliant JSON schemas. Refer this post http://wilddiary.com/generate ...
Read more >Best JSON to Jsonschema Converter - JSON Formatter
JSON to Jsonschema Online with https and easiest way to convert JSON to Jsonschema. Save online and Share.
Read more >Convert JSON to JSON Schema Online - ConvertSimple.com
Use this JSON to JSON Schema converter tool by pasting or uploading JSON in the left box below. Results will appear in the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@L2jLiga
Okay, i think i got it now it worked like this:
Thank you so much 👍🏻
Hi,
Now ids (definition ids) are dynamic but still can’t use it
In swagger it shows like params:
I want to it to be like querystring: