1.0.2 • Published 5 years ago

@justeat/ts-jsonschema-builder v1.0.2

Weekly downloads
74
License
Apache-2.0
Repository
-
Last release
5 years ago

Fluent TypeScript JSON Schema Builder Build Status

This builder takes advantage of TypeScript Generics to provide a Fluent JSON Schema builder, with full IntelliSense support. You don't need to worry about knowing the JSON Schema specification upfront, instead explore it while typing code.

Builder is packaged as ECMAScript 5. This means it can be used in vanilla JS projects, but you will not get a rich IntelliSense support.

⚠ Builder aims to implement Draft-V4 See wiki for all supported features

Builder demo

const schema = new Schema<Model>()
    .with(m => m.StringProp, /^[A-z]+\.[A-z]+$/)
    .with(m => m.NumberProp, x => x > 15)
    .with(m => m.ObjProp.Lvl2ObjProp.Lvl3StrProp, "specificValue")
    .with(m => m.ArrayProp, new ArraySchema({
        length: x => x < 10,
    }))
    .build();
{
    "type": "object",
    "properties": {
        "StringProp": {
            "type": "string",
            "pattern": "^[A-z]+\\.[A-z]+$"
        },
        "NumberProp": {
            "type": "number",
            "minimum": 16
        },
        "ObjProp": {
            "title": "ObjProp",
            "type": "object",
            "properties": {
                "Lvl2ObjProp": {
                    "title": "Lvl2ObjProp",
                    "type": "object",
                    "properties": {
                        "Lvl3StrProp": {
                            "type": "string",
                            "pattern": "specificValue"
                        }
                    },
                    "required": [
                        "Lvl3StrProp"
                    ]
                }
            },
            "required": [
                "Lvl2ObjProp"
            ]
        },
        "ArrayProp": {
            "type": "array",
            "maxItems": 9
        }
    },
    "required": [
        "StringProp",
        "NumberProp",
        "ObjProp",
        "ArrayProp"
    ]
}

For many more examples, check our Wiki

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago