# `PhoenixGenApi.Helpers.Shared`
[🔗](https://github.com/ohhi-vn/phoenix_gen_api/blob/main/lib/phoenix_gen_api/helpers/shared.ex#L1)

Shared utility functions used across PhoenixGenApi modules.

This module centralizes common logic that was previously duplicated
across ConfigPuller, ConfigReceiver, PushConfig, FunConfig, and NodeSelector.

# `enforce_service_name`

```elixir
@spec enforce_service_name(PhoenixGenApi.Structs.FunConfig.t(), atom() | String.t()) ::
  PhoenixGenApi.Structs.FunConfig.t()
```

Enforces that a FunConfig's service name matches the expected service.

If the service names don't match, logs a warning and overwrites the
FunConfig's service with the expected service name.

## Parameters

  - `config` - A `%FunConfig{}` struct
  - `service_name` - The expected service name (atom or string)

## Returns

The FunConfig with the correct service name.

# `ensure_version`

```elixir
@spec ensure_version(PhoenixGenApi.Structs.FunConfig.t()) ::
  PhoenixGenApi.Structs.FunConfig.t()
```

Ensures a FunConfig has a version string, defaulting to "0.0.0".

If the FunConfig's version is nil or empty, sets it to "0.0.0".

## Parameters

  - `config` - A `%FunConfig{}` struct

## Returns

The FunConfig with a guaranteed version string.

# `is_valid_node?`

```elixir
@spec is_valid_node?(any()) :: boolean()
```

Validates that a value is a valid node identifier.

A valid node is either an atom (e.g., `:node1@host`) or a binary string
(e.g., `"node1@host"`).

## Examples

    iex> is_valid_node?(:node1@host)
    true

    iex> is_valid_node?("node1@host")
    true

    iex> is_valid_node?(123)
    false

# `same_service?`

```elixir
@spec same_service?(atom() | String.t(), atom() | String.t()) :: boolean()
```

Compares two service names for equality, handling atom↔string comparisons.

Service names can be atoms or strings throughout the system. This function
normalizes the comparison so that `:my_service` and `"my_service"` are
considered the same service.

## Examples

    iex> same_service?(:my_service, "my_service")
    true

    iex> same_service?("my_service", :my_service)
    true

    iex> same_service?(:my_service, :other_service)
    false

# `validate_nodes`

```elixir
@spec validate_nodes(list()) :: list()
```

Validates a list of nodes, filtering out invalid entries.

## Parameters

  - `nodes` - A list of potential node identifiers

## Returns

A list containing only valid node identifiers.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
