Any
Any data type is used to assign any type of value to the variables. It is useful in the case where either the actual type is not known or types are needed to be dynamically assigned. Thus for undefined type, the default type will be always set to any
.
Any type can be defined with the members such as type
, default
, choices
, anyOf
, optional
, and null
. Schema of any
TypeDef should be written as,
TypeDef Schema
The TypeDef schema ensures the validity of any
MemberDefs.
type
As with most of the types in Internet Object, the first member of typedef is type
. The next snippet shows different ways to define the members a
, b
, and c
as any
.
default
The second member in the any
typedef is default
. Here is how the default values can be defined.
Here, the default value for a
is Monday
and default value for b
is null
.
choices
The choices
restricts the member to be strictly bound with the unique constant values. If set, the choices must be an array of any type of value. The code snippet shows how choices
can be defined for the any
type.
anyOf
In some cases, a member must accept different kinds of values. Such as, a number could be a multiple of 3 or a multiple of 5; they could be a string or number but not that of other types; two different formats of the schema. TheanyOf
allows schema designers to define members that can accept different kinds of constrained values. It accepts an array of MemberDef and/or schema and types.
This snippet explains how a
, b
and c
can accept various kinds of values.
null
When set null
to true, a member can accept null values. Here are some of the ways through which a member of any type can accept null values.
optional
When set optioanl
to true, a member can be marked as optional. Here are some of the ways through which a member of any type can be made optional.
Examples
Some of the valid examples of members with any
are...
Last updated