The TypeDef schema ensures the validity of object MemberDefs.
schema
In the internet object document, the object may or may not be defined with the member called schema. But it is always recommended to define the schema for an object.
If the schema is not defined then the user can pass an object with values of any type i.e anyOf: [string, object].
# An object with schemaa:{{city,state,zip},...}# Assigning schema through memberdefb:{default:N,schema:{city,state,zip},null:T}
The above code snippet represents how the object can be defined with the typedef member schema .
type
The second member of the typedef is type. By default, the object can be of string or an object type. Here the next snippet shows how the object type can be defined.
default
The next member in the object typedef is default . Here is how the default values can be defined for an object.
null
The Object when set to null will accept null values. Here the code snippet demonstrates the way how an object can accept a null value.
optional
A member of an object type can be set to optional. Here are some of the ways through which a member of an object type can be made optional.
Designing Object Schema
Empty Object
An empty object is useful for accepting any object value irrespective of its structure. The empty object definitions can be created using empty curly braces syntax or ignoring schema. Here are some ways in which empty object definitions can be created.
Simple Object
A simple object is an ordered collection of key-value pair that avoids nesting of the object and may or may not contain a child object as shown in the code snippet.
With Memberdef
An object can be defined with the MemberDef as shown in the snippet below.
Nested Object
An Object can be nested inside another object. Accessing a nested object is similar to accessing a nested array. Here is the code snippet that shows how objects can be nested.
Dynamic Schema
Defining dynamic schema allows users to add a dynamic object as shown in the snippet below.
# Set type to object
a: object, b: {type: object}
---
# Set default value to null for a and b
a?: {object, N}, b?: {object, default: N}
---
# Set an empty object to null.
a*: {}
#Assign null value to empty object by setting null: T.
b: {{}, null: T}
# Set default value of an empty object to null.
c?*: {{}, default: N}
# Set default value of object {x, y, z} to null.
d?*: {{x, y, z}, N}
---
# Set an empty object to optional
a?: {}
b?: object
# Set optional: T for empty object
b: {{}, optional: T}
# Assign optional value to empty object
c: {{}, default: N, null: T, default: T}
# Set obect {x, y, z} to optional and null
d*?: {{x, y, z}, N}
---
# The schema directly assigned to the address
address: {street, city, state}
# The schema assinged through the memberDef. This approach
# allows designer to set additional options such as default.
address?: {{street, city, state}, default: N}