@ts-to-json-schema/core
v1.2.4
Published
Core functions for TypeScript to JSON Schema
Downloads
7
Maintainers
Readme
@ts-to-json-schema/core
Core functions for TypeScript to JSON Schema
Installation
npm install @ts-to-json-schema/core
npm install --save-dev typescript @ts-to-json-schema/transform
Obs: Follow the instructions in the @ts-to-json-schema/transform to configure in your bundler.
Configuration
{
"compilerOptions": {
"plugins": [
{ "transform": "@ts-to-json-schema/transform", "type": "program" }
]
}
}
Obs: Follow the instructions in the @ts-to-json-schema/transform to configure in your bundler.
Usage
import { toJsonSchema } from "@ts-to-json-schema/core";
interface MyType {
foo: string;
bar?: number;
}
const schema = toJsonSchema<MyType>();
console.log(schema);
/*
* Output:
* {
* type: 'object',
* properties: {
* foo: { type: 'string' },
* bar: { type: 'number' }
* },
* required: ['foo']
* }
*/