Lather.Types.Mapper (lather v1.0.42)
View SourceDynamic type mapping system for SOAP services.
This module provides utilities to convert between WSDL XML Schema types and Elixir data structures dynamically, allowing the library to work with any SOAP service's data types without hardcoded implementations.
Summary
Functions
Creates a type mapping context from WSDL analysis.
Converts Elixir data structures to XML data based on type context.
Gets the definition of a specific type.
Infers the type of XML data based on the type context.
Validates data against a type definition.
Converts XML data to Elixir data structures based on type context.
Functions
Creates a type mapping context from WSDL analysis.
Parameters
service_info- Service information from WSDL analysisoptions- Mapping configuration options
Options
:generate_structs- Whether to generate Elixir structs (default: false):struct_module- Module namespace for generated structs:type_prefix- Prefix for generated type names:namespace_mapping- Custom namespace to module mapping
Examples
type_context = Lather.Types.Mapper.create_context(service_info)
type_context = Lather.Types.Mapper.create_context(
service_info,
generate_structs: true,
struct_module: MyApp.SoapTypes
)
Converts Elixir data structures to XML data based on type context.
Parameters
elixir_data- Elixir data structuretype_name- The target type name for XML conversiontype_context- Type mapping context from create_context/2
Examples
elixir_data = %{name: "John", age: 30, active: true}
{:ok, xml_data} = Lather.Types.Mapper.elixir_to_xml(
elixir_data,
"User",
type_context
)
# %{"name" => "John", "age" => "30", "active" => "true"}
Gets the definition of a specific type.
Examples
{:ok, type_def} = Lather.Types.Mapper.get_type_definition("User", type_context)
Infers the type of XML data based on the type context.
Parameters
xml_data- Parsed XML datatype_context- Type mapping context
Examples
{:ok, type_name} = Lather.Types.Mapper.infer_type(xml_data, type_context)
# "User"
Validates data against a type definition.
Parameters
data- Data to validatetype_name- Type name to validate againsttype_context- Type mapping context
Examples
:ok = Lather.Types.Mapper.validate_type(data, "User", type_context)
{:error, {:missing_required_field, "name"}} =
Lather.Types.Mapper.validate_type(%{}, "User", type_context)
Converts XML data to Elixir data structures based on type context.
Parameters
xml_data- Parsed XML data (maps with string keys)type_name- The expected type name for the datatype_context- Type mapping context from create_context/2
Examples
xml_data = %{"name" => "John", "age" => "30", "active" => "true"}
{:ok, elixir_data} = Lather.Types.Mapper.xml_to_elixir(
xml_data,
"User",
type_context
)
# %{name: "John", age: 30, active: true}