This module enables you to perform type introspection.
To use this module, you must import it to your DataWeave code, for example,
by adding the line import * from dw::core::Types
to the header of your
DataWeave script.
Functions
arrayItem
arrayItem(t: Type): Type
Returns the type of the given array. This function fails if the input is not an Array type.
Parameters
Name | Description |
---|---|
t |
The type to check. |
Example
This example shows how arrayItem
behaves with different inputs.
Source
1
2
3
4
5
6
7
8
9
10
11
12
13
14
%dw 2.0
import * from dw::core::Types
type ArrayOfString = Array<String>
type ArrayOfNumber = Array<Number>
type ArrayOfAny = Array<Any>
type ArrayOfAnyDefault = Array
output application/json
---
{
a: arrayItem(ArrayOfString),
b: arrayItem(ArrayOfNumber),
c: arrayItem(ArrayOfAny),
d: arrayItem(ArrayOfAnyDefault)
}
Output
1
2
3
4
5
6
{
"a": "String",
"b": "Number",
"c": "Any",
"d": "Any"
}
baseTypeOf
baseTypeOf(t: Type): Type
Returns an the base type of the given type.
Parameters
Name | Description |
---|---|
t |
The type to check. |
Example
This example shows how baseTypeOf
behaves with different inputs.
Source
1
2
3
4
5
6
7
8
%dw 2.0
import * from dw::core::Types
type AType = String {format: "YYYY-MM-dd"}
output application/json
---
{
a: baseTypeOf(AType)
}
Output
1
2
3
{
"a": "String"
}
functionParamTypes
functionParamTypes(t: Type): Array<FunctionParam>
Returns the list of parameters from the given function type. This function fails if the provided type is not a Function type.
Parameters
Name | Description |
---|---|
t |
The function type. |
Example
This example shows how functionParamTypes
behaves with different inputs.
Source
1
2
3
4
5
6
7
8
9
10
%dw 2.0
output application/json
import * from dw::core::Types
type AFunction = (String, Number) -> Number
type AFunction2 = () -> Number
---
{
a: functionParamTypes(AFunction),
b: functionParamTypes(AFunction2)
}
Output
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
{
"a": [
{
"paramType": "String",
"optional": false
},
{
"paramType": "Number",
"optional": false
}
],
"b": [
]
}
functionReturnType
functionReturnType(t: Type): Type | Null
Returns the type of a function’s return type. This function fails if the input type is not a Function type.
Parameters
Name | Description |
---|---|
t |
The function type. |
Example
This example shows how functionReturnType
behaves with different inputs.
Source
1
2
3
4
5
6
7
8
9
10
%dw 2.0
output application/json
import * from dw::core::Types
type AFunction = (String, Number) -> Number
type AFunction2 = () -> Number
---
{
a: functionReturnType(AFunction),
b: functionReturnType(AFunction2)
}
Output
1
2
3
4
{
"a": "Number",
"b": "Number"
}
intersectionItems
intersectionItems(t: Type): Array<Type>
Returns an array of all the types that define a given Intersection type. This function fails if the input is not an Intersection type.
Parameters
Name | Description |
---|---|
t |
The type to check. |
Example
This example shows how intersectionItems
behaves with different inputs.
Note that the AType
variable defines an Intersection type
{name: String} & {age: Number}
by using an &
between
the two objects.
Source
1
2
3
4
5
6
7
8
%dw 2.0
import * from dw::core::Types
type AType = {name: String} & {age: Number}
output application/json
---
{
a: intersectionItems(AType)
}
Output
1
2
3
{
"a": ["Object","Object"]
}
isAnyType
isAnyType(t: Type): Boolean
Returns true
if the input is the Any type.
Parameters
Name | Description |
---|---|
t |
The type to check. |
Example
This example shows how isAnyType
behaves with different inputs.
Source
1
2
3
4
5
6
7
8
9
10
%dw 2.0
import * from dw::core::Types
type AAny = Any
output application/json
---
{
a: isAnyType(AAny),
b: isAnyType(Any),
c: isAnyType(String),
}
Output
1
2
3
4
5
{
"a": true,
"b": true,
"c": false
}
isArrayType
isArrayType(t: Type): Boolean
Returns true
if the input type is the Array type.
Parameters
Name | Description |
---|---|
t |
The type to check. |
Example
This example shows how isArrayType
behaves with different inputs.
Source
1
2
3
4
5
6
7
8
9
%dw 2.0
import * from dw::core::Types
type AType = Array<String>
output application/json
---
{
a: isArrayType(AType),
b: isArrayType(Boolean),
}
Output
1
2
3
4
{
"a": true,
"b": false
}
isBinaryType
isBinaryType(t: Type): Boolean
Returns true
if the input is the Binary type.
Parameters
Name | Description |
---|---|
t |
The type to check. |
Example
This example shows how isBinaryType
behaves with different inputs.
Source
1
2
3
4
5
6
7
8
9
10
%dw 2.0
import * from dw::core::Types
type ABinary = Binary
output application/json
---
{
a: isBinaryType(ABinary),
b: isBinaryType(Binary),
c: isBinaryType(String),
}
Output
1
2
3
4
5
{
"a": true,
"b": true,
"c": false
}
isBooleanType
isBooleanType(t: Type): Boolean
Returns true
if the input is the Boolean type.
Parameters
Name | Description |
---|---|
t |
The type to check. |
Example
This example shows how isBooleanType
behaves with different inputs.
Source
1
2
3
4
5
6
7
8
9
10
%dw 2.0
import * from dw::core::Types
type ABoolean = Boolean
output application/json
---
{
a: isBooleanType(ABoolean),
b: isBooleanType(Boolean),
c: isBooleanType(String),
}
Output
1
2
3
4
5
{
"a": true,
"b": true,
"c": false
}
isDateTimeType
isDateTimeType(t: Type): Boolean
Returns true
if the input is the DateTime type.
Parameters
Name | Description |
---|---|
t |
The type to check. |
Example
This example shows how isDateTimeType
behaves with different inputs.
Source
1
2
3
4
5
6
7
8
9
10
%dw 2.0
import * from dw::core::Types
type ADateTime = DateTime
output application/json
---
{
a: isDateTimeType(ADateTime),
b: isDateTimeType(DateTime),
c: isDateTimeType(String),
}
Output
1
2
3
4
5
{
"a": true,
"b": true,
"c": false
}
isDateType
isDateType(t: Type): Boolean
Returns true
if the input is the Date type.
Parameters
Name | Description |
---|---|
t |
The type to check. |
Example
This example shows how isDateType
behaves with different inputs.
Source
1
2
3
4
5
6
7
8
9
10
%dw 2.0
import * from dw::core::Types
type ADate = Date
output application/json
---
{
a: isDateType(ADate),
b: isDateType(Date),
c: isDateType(String),
}
Output
1
2
3
4
5
{
"a": true,
"b": true,
"c": false
}
isFunctionType
isFunctionType(t: Type): Boolean
Returns true
if the input is the Function type.
Parameters
Name | Description |
---|---|
t |
The type to check. |
Example
This example shows how isFunctionType
behaves with different inputs.
Source
1
2
3
4
5
6
7
8
9
%dw 2.0
import * from dw::core::Types
type AFunction = (String) -> String
output application/json
---
{
a: isFunctionType(AFunction),
b: isFunctionType(Boolean)
}
Output
1
2
3
4
{
"a": true,
"b": false
}
isIntersectionType
isIntersectionType(t: Type): Boolean
Returns true
if the input type is the Intersection type.
Parameters
Name | Description |
---|---|
t |
The type to check. |
Example
This example shows how isIntersectionType
behaves with different inputs.
Source
1
2
3
4
5
6
7
8
9
%dw 2.0
import * from dw::core::Types
type AType = {name: String} & {age: Number}
output application/json
---
{
a: isIntersectionType(AType),
b: isIntersectionType(Boolean),
}
Output
1
2
3
4
{
"a": true,
"b": false
}
isKeyType
isKeyType(t: Type): Boolean
Returns true
if the input is the Key type.
Parameters
Name | Description |
---|---|
t |
The type to check. |
Example
This example shows how isKeyType
behaves with different inputs.
Source
1
2
3
4
5
6
7
8
9
10
%dw 2.0
import * from dw::core::Types
type AKey = Key
output application/json
---
{
a: isKeyType(AKey),
b: isKeyType(Key),
c: isKeyType(Boolean),
}
Output
1
2
3
4
5
{
"a": true,
"b": true,
"c": false
}
isLiteralType
isLiteralType(t: Type): Boolean
Returns true
if the input is the Literal type.
Parameters
Name | Description |
---|---|
t |
The type to check. |
Example
This example shows how isLiteralType
behaves with different inputs.
Source
1
2
3
4
5
6
7
8
9
%dw 2.0
import * from dw::core::Types
type ALiteralType = "Mariano"
output application/json
---
{
a: isLiteralType(ALiteralType),
b: isLiteralType(Boolean)
}
Output
1
2
3
4
{
"a": true,
"b": false
}
isLocalDateTimeType
isLocalDateTimeType(t: Type): Boolean
Returns true
if the input is the LocalDateTime type.
Parameters
Name | Description |
---|---|
t |
The type to check. |
Example
This example shows how isLocalDateTimeType
behaves with different inputs.
Source
1
2
3
4
5
6
7
8
9
10
%dw 2.0
import * from dw::core::Types
type ALocalDateTime = LocalDateTime
output application/json
---
{
a: isLocalDateTimeType(ALocalDateTime),
b: isLocalDateTimeType(LocalDateTime),
c: isLocalDateTimeType(String),
}
Output
1
2
3
4
5
{
"a": true,
"b": true,
"c": false
}
isLocalTimeType
isLocalTimeType(t: Type): Boolean
Returns true
if the input is the LocalTime type.
Parameters
Name | Description |
---|---|
t |
The type to check. |
Example
This example shows how isLocalTimeType
behaves with different inputs.
Source
1
2
3
4
5
6
7
8
9
10
%dw 2.0
import * from dw::core::Types
type ALocalTime = LocalTime
output application/json
---
{
a: isLocalTimeType(ALocalTime),
b: isLocalTimeType(LocalTime),
c: isLocalTimeType(String),
}
Output
1
2
3
4
5
{
"a": true,
"b": true,
"c": false
}
isNamespaceType
isNamespaceType(t: Type): Boolean
Returns true
if the input is the Namespace type.
Parameters
Name | Description |
---|---|
t |
The type to check. |
Example
This example shows how isNamespaceType
behaves with different inputs.
Source
1
2
3
4
5
6
7
8
9
10
%dw 2.0
import * from dw::core::Types
type ANamespace = Namespace
output application/json
---
{
a: isNamespaceType(ANamespace),
b: isNamespaceType(Namespace),
c: isNamespaceType(String),
}
Output
1
2
3
4
5
{
"a": true,
"b": true,
"c": false
}
isNothingType
isNothingType(t: Type): Boolean
Returns true
if the input is the Nothing type.
Parameters
Name | Description |
---|---|
t |
The type to check. |
Example
This example shows how isNothingType
behaves with different inputs.
Source
1
2
3
4
5
6
7
8
9
10
%dw 2.0
import * from dw::core::Types
type ANothing = Nothing
output application/json
---
{
a: isNothingType(ANothing),
b: isNothingType(Nothing),
c: isNothingType(String),
}
Output
1
2
3
4
5
{
"a": true,
"b": true,
"c": false
}
isNullType
isNullType(t: Type): Boolean
Returns true
if the input is the Null type.
Parameters
Name | Description |
---|---|
t |
The type to check. |
Example
This example shows how isNullType
behaves with different inputs.
Source
1
2
3
4
5
6
7
8
9
10
%dw 2.0
import * from dw::core::Types
type ANull = Null
output application/json
---
{
a: isNullType(ANull),
b: isNullType(Null),
c: isNullType(String),
}
Output
1
2
3
4
5
{
"a": true,
"b": true,
"c": false
}
isNumberType
isNumberType(t: Type): Boolean
Returns true
if the input is the Number type.
Parameters
Name | Description |
---|---|
t |
The type to check. |
Example
This example shows how isNumberType
behaves with different inputs.
Source
1
2
3
4
5
6
7
8
9
10
%dw 2.0
import * from dw::core::Types
type ANumber = Number
output application/json
---
{
a: isNumberType(ANumber),
b: isNumberType(Number),
c: isNumberType(String),
}
Output
1
2
3
4
5
{
"a": true,
"b": true,
"c": false
}
isObjectType
isObjectType(t: Type): Boolean
Returns true
if the input is the Object type.
Parameters
Name | Description |
---|---|
t |
The type to check. |
Example
This example shows how isObjectType
behaves with different inputs.
Source
1
2
3
4
5
6
7
8
9
%dw 2.0
import * from dw::core::Types
type AType = {name: String}
output application/json
---
{
a: isObjectType(AType),
b: isObjectType(Boolean),
}
Output
1
2
3
4
{
"a": true,
"b": false
}
isPeriodType
isPeriodType(t: Type): Boolean
Returns true
if the input is the Period type.
Parameters
Name | Description |
---|---|
t |
The type to check. |
Example
This example shows how isPeriodType
behaves with different inputs.
Source
1
2
3
4
5
6
7
8
9
10
%dw 2.0
import * from dw::core::Types
type APeriod = Period
output application/json
---
{
a: isPeriodType(APeriod),
b: isPeriodType(Period),
c: isPeriodType(String),
}
Output
1
2
3
4
5
{
"a": true,
"b": true,
"c": false
}
isRangeType
isRangeType(t: Type): Boolean
Returns true
if the input is the Range type.
Parameters
Name | Description |
---|---|
t |
The type to check. |
Example
This example shows how isRangeType
behaves with different inputs.
Source
1
2
3
4
5
6
7
8
9
10
%dw 2.0
import * from dw::core::Types
type ARange = Range
output application/json
---
{
a: isRangeType(ARange),
b: isRangeType(Range),
c: isRangeType(String),
}
Output
1
2
3
4
5
{
"a": true,
"b": true,
"c": false
}
isReferenceType
isReferenceType(t: Type): Boolean
Returns true
if the input type is a Reference type.
Parameters
Name | Description |
---|---|
t |
The type to check. |
Example
This example shows how isReferenceType
behaves with different inputs.
Source
1
2
3
4
5
6
7
8
9
10
11
%dw 2.0
output application/json
import * from dw::core::Types
type AArray = Array<String> {n: 1}
type AArray2 = Array<AArray>
---
{
a: isReferenceType( AArray),
b: isReferenceType(arrayItem(AArray2)),
c: isReferenceType(String)
}
Output
1
2
3
4
5
{
"a": false,
"b": true,
"c": false
}
isRegexType
isRegexType(t: Type): Boolean
Returns true
if the input is the Regex type.
Parameters
Name | Description |
---|---|
t |
The type to check. |
Example
This example shows how isRegexType
behaves with different inputs.
Source
1
2
3
4
5
6
7
8
9
10
%dw 2.0
import * from dw::core::Types
type ARegex = Regex
output application/json
---
{
a: isRegexType(ARegex),
b: isRegexType(Regex),
c: isRegexType(Boolean),
}
Output
1
2
3
4
5
{
"a": true,
"b": true,
"c": false
}
isStringType
isStringType(t: Type): Boolean
Returns true
if the input is the String type.
Parameters
Name | Description |
---|---|
t |
The type to check. |
Example
This example shows how isStringType
behaves with different inputs.
Source
1
2
3
4
5
6
7
8
9
10
%dw 2.0
import * from dw::core::Types
type AString = String
output application/json
---
{
a: isStringType(AString),
b: isStringType(String),
c: isStringType(Boolean),
}
Output
1
2
3
4
5
{
"a": true,
"b": true,
"c": false
}
isTimeType
isTimeType(t: Type): Boolean
Returns true
if the input is the Time type.
Parameters
Name | Description |
---|---|
t |
The type to check. |
Example
This example shows how isTimeType
behaves with different inputs.
Source
1
2
3
4
5
6
7
8
9
10
%dw 2.0
import * from dw::core::Types
type ATime = Time
output application/json
---
{
a: isTimeType(ATime),
b: isTimeType(Time),
c: isTimeType(String),
}
Output
1
2
3
4
5
{
"a": true,
"b": true,
"c": false
}
isTimeZoneType
isTimeZoneType(t: Type): Boolean
Returns true
if the input is the TimeZone type.
Parameters
Name | Description |
---|---|
t |
The type to check. |
Example
This example shows how isTimeZoneType
behaves with different inputs.
Source
1
2
3
4
5
6
7
8
9
10
%dw 2.0
import * from dw::core::Types
type ATimeZone = TimeZone
output application/json
---
{
a: isTimeZoneType(ATimeZone),
b: isTimeZoneType(TimeZone),
c: isTimeZoneType(String),
}
Output
1
2
3
4
5
{
"a": true,
"b": true,
"c": false
}
isTypeType
isTypeType(t: Type): Boolean
Returns true
if the input is the Type type.
Parameters
Name | Description |
---|---|
t |
The type to check. |
Example
This example shows how isTypeType
behaves with different inputs.
Source
1
2
3
4
5
6
7
8
9
10
%dw 2.0
import * from dw::core::Types
type AType = Type
output application/json
---
{
a: isTypeType(AType),
b: isTypeType(Type),
c: isTypeType(String),
}
Output
1
2
3
4
5
{
"a": true,
"b": true,
"c": false
}
isUnionType
isUnionType(t: Type): Boolean
Returns true
if the input type is the Union type.
Parameters
Name | Description |
---|---|
t |
The type to check. |
Example
This example shows how isUnionType
behaves with different inputs.
Source
1
2
3
4
5
6
7
8
9
%dw 2.0
import * from dw::core::Types
type AType = String | Number
output application/json
---
{
a: isUnionType(AType),
b: isUnionType(Boolean),
}
Output
1
2
3
4
{
"a": true,
"b": false
}
isUriType
isUriType(t: Type): Boolean
Returns true
if the input is the Uri type.
Parameters
Name | Description |
---|---|
t |
The type to check. |
Example
This example shows how isUriType
behaves with different inputs.
Source
1
2
3
4
5
6
7
8
9
10
%dw 2.0
import * from dw::core::Types
type AUri = Uri
output application/json
---
{
a: isUriType(AUri),
b: isUriType(Uri),
c: isUriType(String),
}
Output
1
2
3
4
5
{
"a": true,
"b": true,
"c": false
}
literalValueOf
literalValueOf(t: Type): String | Number | Boolean
Returns the value of an input belongs to the Literal type.
Parameters
Name | Description |
---|---|
t |
The type to check. |
Example
This example shows how literalValueOf
behaves with different inputs.
Source
1
2
3
4
5
6
7
8
%dw 2.0
import * from dw::core::Types
type AType = "Mariano"
output application/json
---
{
a: literalValueOf(AType)
}
Output
1
2
3
{
"a": "Mariano"
}
metadataOf
metadataOf(t: Type): Object
Returns metadata that is attached to the given type.
Parameters
Name | Description |
---|---|
t |
The type to check. |
Example
This example shows how metadataOf
behaves with different inputs.
Source
1
2
3
4
5
6
7
8
%dw 2.0
import * from dw::core::Types
type AType = String {format: "YYYY-MM-dd"}
output application/json
---
{
a: metadataOf(AType)
}
Output
1
2
3
{
"a": {"format": "YYYY-MM-dd"}
}
nameOf
nameOf(t: Type): String
Returns the name of the input type.
Parameters
Name | Description |
---|---|
t |
The type to query |
Example
This example shows how nameOf
behaves with different inputs.
Source
1
2
3
4
5
6
7
8
9
10
11
%dw 2.0
output application/json
import * from dw::core::Types
type AArray = Array<String> {n: 1}
type AArray2 = Array<String>
---
{
a: nameOf(AArray),
b: nameOf(AArray2),
c: nameOf(String)
}
Output
1
2
3
4
5
{
"a": "AArray",
"b": "AArray2",
"c": "String"
}
objectFields
objectFields(t: Type): Array<Field>
Returns the array of fields from the given Object type. This function fails if the type is not an Object type.
Parameters
Name | Description |
---|---|
t |
The function type. |
Example
This example shows how objectFields
behaves with different inputs.
Source
1
2
3
4
5
6
7
8
9
10
11
12
import * from dw::core::Types
ns ns0 http://acme.com
type ADictionary = {_ : String}
type ASchema = {ns0#name @(ns0#foo: String): {}}
type AUser = {name @(foo?: String,l: Number)?: String, lastName*: Number}
---
{
a: objectFields(ADictionary),
b: objectFields(ASchema),
c: objectFields(Object),
d: objectFields(AUser)
}
Output
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
{
"a": [
{
"key": {
"name": {
"localName": "_",
"namespace": null
},
"attributes": [
]
},
"required": true,
"repeated": false,
"value": "String"
}
],
"b": [
{
"key": {
"name": {
"localName": "name",
"namespace": "http://acme.com"
},
"attributes": [
{
"name": {
"localName": "foo",
"namespace": "http://acme.com"
},
"value": "String",
"required": true
}
]
},
"required": true,
"repeated": false,
"value": "Object"
}
],
"c": [
],
"d": [
{
"key": {
"name": {
"localName": "name",
"namespace": null
},
"attributes": [
{
"name": {
"localName": "foo",
"namespace": null
},
"value": "String",
"required": false
},
{
"name": {
"localName": "l",
"namespace": null
},
"value": "Number",
"required": true
}
]
},
"required": false,
"repeated": false,
"value": "String"
},
{
"key": {
"name": {
"localName": "lastName",
"namespace": null
},
"attributes": [
]
},
"required": true,
"repeated": true,
"value": "Number"
}
]
}
unionItems
unionItems(t: Type): Array<Type>
Returns an array of all the types that define a given Union type. This function fails if the input is not a Union type.
Parameters
Name | Description |
---|---|
t |
The type to check. |
Example
This example shows how unionItems
behaves with different inputs.
Source
1
2
3
4
5
6
7
8
%dw 2.0
import * from dw::core::Types
type AType = String | Number
output application/json
---
{
a: unionItems(AType)
}
Output
1
2
3
{
"a": ["String","Number"]
}
Types
Attribute
Represents an Attribute definition that is part of an Object field Key.
1
{ name: QName, required: Boolean, value: Type }
Field
Represents a Field description that is part of an Object.
1
{ key: { name: QName, attributes: Array<Attribute> }, required: Boolean, repeated: Boolean, value: Type }
FunctionParam
Represents a Function parameter that is part of a Function type.
1
{ paramType: Type, optional: Boolean }
QName
Represents a Qualified Name definition with a localName
(a string) and a namespace
.
If the QName does not have a Namespace, its value is null
.
1
{ localName: String, namespace: Namespace | Null }