Lather.Types.Generator (lather v1.0.42)
View SourceRuntime struct generation for SOAP types.
This module provides utilities to dynamically generate Elixir structs from WSDL type definitions at runtime, enabling type-safe interactions with SOAP services.
Summary
Functions
Creates a struct instance from XML data using generated types.
Generates Elixir structs at runtime for WSDL types.
Gets the module name for a generated struct type.
Validates if a module was generated for a type.
Converts a struct instance to XML data.
Functions
Creates a struct instance from XML data using generated types.
Parameters
xml_data- Parsed XML datatype_name- The struct type to creategenerated_modules- Map of generated modules
Examples
{:ok, user_struct} = Lather.Types.Generator.create_struct_instance(
%{"name" => "John", "age" => "30"},
"User",
generated_modules
)
# %DynamicTypes.User{name: "John", age: 30}
Generates Elixir structs at runtime for WSDL types.
Parameters
service_info- Service information from WSDL analysisoptions- Generation options
Options
:module_prefix- Module prefix for generated structs (default: DynamicTypes):exclude_types- List of type names to exclude from generation:include_only- List of type names to include (excludes all others):field_naming- How to handle field names (:snake_case, :camel_case, :preserve)
Examples
{:ok, generated_modules} = Lather.Types.Generator.generate_structs(service_info)
{:ok, modules} = Lather.Types.Generator.generate_structs(
service_info,
module_prefix: MyApp.SoapTypes,
field_naming: :snake_case
)
Gets the module name for a generated struct type.
Examples
module_name = Lather.Types.Generator.get_struct_module("User", DynamicTypes)
# DynamicTypes.User
Validates if a module was generated for a type.
Examples
true = Lather.Types.Generator.struct_exists?("User", generated_modules)
false = Lather.Types.Generator.struct_exists?("NonExistent", generated_modules)
Converts a struct instance to XML data.
Parameters
struct_instance- The struct to converttype_context- Type mapping context
Examples
xml_data = Lather.Types.Generator.struct_to_xml(user_struct, type_context)
# %{"name" => "John", "age" => "30"}