Lather.Types.Generator (lather v1.0.42)

View Source

Runtime 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

create_struct_instance(xml_data, type_name, generated_modules)

@spec create_struct_instance(map(), String.t(), map()) ::
  {:ok, struct()} | {:error, term()}

Creates a struct instance from XML data using generated types.

Parameters

  • xml_data - Parsed XML data
  • type_name - The struct type to create
  • generated_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}

generate_structs(service_info, options \\ [])

@spec generate_structs(
  map(),
  keyword()
) :: {:ok, [module()]} | {:error, term()}

Generates Elixir structs at runtime for WSDL types.

Parameters

  • service_info - Service information from WSDL analysis
  • options - 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
)

get_struct_module(type_name, module_prefix)

@spec get_struct_module(String.t(), module()) :: module()

Gets the module name for a generated struct type.

Examples

module_name = Lather.Types.Generator.get_struct_module("User", DynamicTypes)
# DynamicTypes.User

struct_exists?(type_name, generated_modules)

@spec struct_exists?(String.t(), map()) :: boolean()

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)

struct_to_xml(struct_instance, type_context)

@spec struct_to_xml(
  struct(),
  map()
) :: map()

Converts a struct instance to XML data.

Parameters

  • struct_instance - The struct to convert
  • type_context - Type mapping context

Examples

xml_data = Lather.Types.Generator.struct_to_xml(user_struct, type_context)
# %{"name" => "John", "age" => "30"}