Skip to content

Instantly share code, notes, and snippets.

@yawaramin
Created June 18, 2019 03:11
Show Gist options
  • Save yawaramin/cb2a1f203114f825c610bd6025261154 to your computer and use it in GitHub Desktop.
Save yawaramin/cb2a1f203114f825c610bd6025261154 to your computer and use it in GitHub Desktop.
Flow type description of JSON Schema (WIP)
/* @flow */
type NonNegativeInt = number
type PositiveNumber = number
type Regex = string
type SchemaType = {
description?: string,
}
type SchemaObject = {
...SchemaType,
type: "object",
maxProperties?: NonNegativeInt,
minProperties?: NonNegativeInt,
required?: string[],
properties: {[string]: Schema},
patternProperties?: {[Regex]: Schema},
additionalProperties?: Schema,
}
type SchemaArray = {
...SchemaType,
type: "array",
items?: Schema | Schema[],
additionalItems?: Schema,
maxItems?: NonNegativeInt,
minItems?: NonNegativeInt,
uniqueItems?: boolean,
contains?: Schema,
}
type SchemaString = {
...SchemaType,
type: "string",
maxLength?: NonNegativeInt,
minLength?: NonNegativeInt,
pattern?: Regex,
}
type SchemaNumber = {
...SchemaType,
type: "number",
multipleOf?: PositiveNumber,
maximum?: number,
exclusiveMaximum?: number,
minimum?: number,
exclusiveMinimum?: number,
}
type SchemaBoolean = {
...SchemaType,
type: "boolean"
}
type SchemaNull = {
...SchemaType,
type: "null"
}
type Schema =
| SchemaObject
| SchemaArray
| SchemaString
| SchemaNumber
| SchemaBoolean
| SchemaNull
type SchemaRoot = {
...Schema,
"$schema": string,
"$id": string,
title: string,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment