Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/justeat/ts-jsonschema-builder
Fluent TypeScript JSON Schema builder.
https://github.com/justeat/ts-jsonschema-builder
Last synced: about 2 months ago
JSON representation
Fluent TypeScript JSON Schema builder.
- Host: GitHub
- URL: https://github.com/justeat/ts-jsonschema-builder
- Owner: justeat
- License: apache-2.0
- Created: 2019-04-30T07:25:30.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-05-01T00:33:10.000Z (over 1 year ago)
- Last Synced: 2024-04-23T18:48:16.893Z (9 months ago)
- Language: TypeScript
- Size: 1.26 MB
- Stars: 6
- Watchers: 18
- Forks: 4
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Fluent TypeScript JSON Schema Builder [![Build Status](https://travis-ci.com/justeat/ts-jsonschema-builder.svg?branch=master)](https://travis-ci.com/justeat/ts-jsonschema-builder)
This builder takes advantage of TypeScript [Generics](https://www.typescriptlang.org/docs/handbook/generics.html) 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](https://github.com/justeat/ts-jsonschema-builder/wiki) for all supported features![Builder demo](https://github.com/justeat/ts-jsonschema-builder/raw/master/assets/ts-schema-demo.gif)
```typescript
const schema = new Schema()
.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();
```Produces following schema (click to expand)
```json
{
"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](https://github.com/justeat/ts-jsonschema-builder/wiki)