Getting started Community Training Tutorials Documentation APIs, AI & Tools
%dw 2.0
type Weather = "cloudy" | "sunny" | "rainy" | "stormy"
type DetailedWeather = {temperature: Number, weather: Weather}
Reusing Types from DataWeave Modules
Reusing Types from DataWeave Modules
You're viewing an older version of the documentation. You can switch to the latest version or use the version selector in the left navigation.
To reuse types declared in other DataWeave modules, use the import directive:
dw/Weather.dwl):%dw 2.0
type Weather = "cloudy" | "sunny" | "rainy" | "stormy"
type DetailedWeather = {temperature: Number, weather: Weather}
You can use those imported types as any other type in DataWeave, as constraints for variables and functions or for pattern matching and checking types at runtime:
%dw 2.0
output json
import * from dw::Weather
fun weatherMessage(todayWeather: Weather) =
"The weather for today is: " ++ todayWeather
var worstPossibleWeather: DetailedWeather = {temperature: -10, weather: "stormy"}
---
{
a: weatherMessage("sunny"),
b: worstPossibleWeather.weather is Weather
}