0.0.6 • Published 3 years ago

jsonschema-types v0.0.6

Weekly downloads
1
License
MIT
Repository
github
Last release
3 years ago

npm version

jsonschema-types

This package enables building Jsonschemas as Typescript classes. It uses decorators to build the jsonschema

You can access the schema with

new TestSchema().jsonschema

Test the schema with validate It uses the validate function of jsonschema

Example

@schemaOptions({ id: '/TestSchemaCreate' })
export class TestSchema extends Schema {
  @prop({ required: true, minimum: 1, maximum: 4 })
  testProp!: string

  @prop({ enum: ETEST})
  what!: ETEST

  @prop({})
  other!: TestSchema2

  @prop({ type: Number, maxItems: 3 })
  numberList!: number[]

  @prop({ type: TestSchema2, minItems: 1, uniqueItems: true })
  otherList!: TestSchema2[]

  @prop({ multipleOf: 3 })
  multiple!: number

  @prop({ minLength: 3, maxLength: 5, required: true })
  minLen!: string

  @prop({ pattern: '/abc/' })
  regex!: string

  @prop({ exclusiveMinimum: true, exclusiveMaximum: true })
  exclusive!: number
}