%dw 2.0
type Weather = "cloudy" | "sunny" | "rainy" | "stormy"
type DetailedWeather = {temperature: Number, weather: Weather}
Reusing Types from DataWeave Modules
To reuse types declared in other DataWeave modules, use the import
directive:
DataWeave Module (
dw/Weather.dwl
):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:
DataWeave Script:
%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
}