Doubter × JSON Schema ![build](https://github.com/smikhalevski/doubter-json-schema/actions/workflows/master.yml/badge.svg?branch=master&event=push)
Converts Doubter shapes from and to JSON schemas.
Warning This project is at the early development stage.
npm install --save-prod @doubter/json-schema
Define a shape:
import * as d from 'doubter';
const shape = d.object({
foo: d.string().optional(),
bar: d.number().gt(10)
});
const schema = toJSONSchema(shape);
The schema
is a JSON schema object:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"foo": {
"oneOf": [
{ "type": "null" },
{ "type": "string" }
]
},
"bar": {
"type": "number",
"exclusiveMinimum": 10
}
},
"required": ["bar"]
}