Skip to content

Instantly share code, notes, and snippets.

@robertdempsey
Last active February 28, 2020 10:51
Show Gist options
  • Save robertdempsey/5bc13fe74feb674e6ebd6b1145b2c145 to your computer and use it in GitHub Desktop.
Save robertdempsey/5bc13fe74feb674e6ebd6b1145b2c145 to your computer and use it in GitHub Desktop.
An example JSON Schema output
{
"$ref": "#/definitions/MyObject",
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"MyBaseObject": {
"additionalProperties": false,
"properties": {
"number": {
"description": "This is a number. We can set the max and min like so",
"maximum": 9,
"minimum": 3,
"type": "number"
},
"string": {
"description": "This is a string. We can set the maxLength like so",
"maxLength": 20,
"type": "string"
}
},
"required": [
"number",
"string"
],
"type": "object"
},
"MyObject": {
"additionalProperties": false,
"properties": {
"array": {
"description": "This is an array. We can set the maxItems using",
"items": {
"$ref": "#/definitions/MyBaseObject"
},
"maxItems": 99,
"type": "array"
},
"notRequired": {
"description": "We can set optional properties like so",
"type": "boolean"
},
"number": {
"description": "This is a number. We can set the max and min like so",
"maximum": 9,
"minimum": 3,
"type": "number"
},
"object": {
"$ref": "#/definitions/MyBaseObject",
"description": "This is an object"
},
"setOfKnownStrings": {
"description": "This will generate a property of type string with an enum with the below possible values",
"enum": [
"one",
"two",
"three"
],
"type": "string"
},
"string": {
"description": "This is a string. We can set the maxLength like so",
"maxLength": 20,
"type": "string"
}
},
"required": [
"array",
"number",
"object",
"setOfKnownStrings",
"string"
],
"type": "object"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment