-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Formal rules for constructing a schema:
Top-level Schema Structure
-
Schema Definition:
- A schema is defined using the
defineSchemamacro followed by a schema name. - The schema name should be a valid Nim identifier.
- A schema is defined using the
-
Definitions:
- The
definitionskeyword is used to define reusable subschemas. definitionsare allowed only at the top level of a schema.- Each definition is identified by a unique name.
- Definitions can be referenced elsewhere in the schema using the ref attribute.
- The
Properties
- Properties:
- The
propertieskeyword is used to define the properties of an object. - Properties are required by default.
- The
allowExtra = trueattribute can be used withpropertiesto allow additional properties. - Each property is defined using a key-value pair, where the key is the property name and the value is the property definition.
- The
Property Definition
-
Property Definition:
- A property definition can be a simple type definition, a reference or a nested schema.
- Simple type definitions include
int,float,number,string, andbool. - A definition may include attributes such as
minimum,maxItems,format, and others specific to the property type. - A property can be marked as nullable using the
nullable = trueattribute. - A property can be marked as optional using the
optional = trueattribute.
-
Enum:
- The
enumkeyword is used to specify a list of allowed values. - Currently,
enumis specified to work only with strings.
- The
-
References:
- The
refkeyword is used to reference a subschema defined indefinitions. - References can only point to subschemas declared within the same schema's
definitions.
- The
Nested Structures, Arrays and Tuples
-
Nested Properties:
- Properties can be nested, allowing the definition of complex objects.
-
Arrays:
- Arrays are defined using the keyword
items. - The
itemskeyword is followed by the type, reference, or schema definition for the array elements.
- Arrays are defined using the keyword
-
Tuples:
prefixItemsis an array where each item is a schema that corresponds to each index of the document's array.
Schema Composition
- Schema Composition:
- The DSL includes a few keywords for combining schemas together.
- The keywords used to combine schemas are:
allOf: (AND) Must be valid against all of the subschemasanyOf: (OR) Must be valid against any of the subschemasoneOf: (XOR) Must be valid against exactly one of the subschemasnot: (NOT) Must not be valid against the given schema
Special Validation Features
-
Number Validation:
- Numbers support the following attributes for validation:
minimum: Specifies the minimum value allowed for the number.maximum: Specifies the maximum value allowed for the number.exclusiveMinimum: If set totrue, the number must be strictly greater than the specifiedminimum.exclusiveMaximum: If set totrue, the number must be strictly less than the specifiedmaximum.
- Numbers support the following attributes for validation:
-
String Validation:
- Strings support the following attributes for validation:
format: Specifies a format for the string value. Supported formats include "email", "date", "time", "date-time", "uri", "hostname", "ipv4", "ipv6", etc.minLength: Specifies the minimum length allowed for the string.maxLength: Specifies the maximum length allowed for the string.pattern: Specifies a regular expression pattern that the string must match.
- Strings support the following attributes for validation:
-
**Array Validation:
- Arrays support the following attributes for validation:
minItems: Specifies the minimum number of items required in the array.maxItems: Specifies the maximum number of items allowed in the array.uniqueItems: If set totrue, the array must contain only unique items.
- Arrays support the following attributes for validation:
Example Schema Definition
defineSchema ExampleSchema:
properties:
prop1(`type` = string)
prop2(`enum` = ["value1", "value2"])
prop3(`ref` = subschema)
prop4:
items(`type` = number)
prop5(`type` = float, nullable = true, optional = true)
definitions:
subschema:
oneOf:
properties:
prop6(`type` = string, format = "email")
prop7(`type` = bool)
prefixItems(`type` = int, `type` = bool)Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels