# `Exdantic.Runtime.DynamicSchema`
[🔗](https://github.com/nshkrdotcom/exdantic/blob/v0.1.0/lib/exdantic/runtime/dynamic_schema.ex#L1)

Represents a schema created at runtime with field definitions and configuration.

This struct holds all the information needed to validate data against a
dynamically created schema, including field metadata, configuration options,
and runtime metadata.

# `t`

```elixir
@type t() :: %Exdantic.Runtime.DynamicSchema{
  config: %{
    optional(:title) =&gt; String.t(),
    optional(:description) =&gt; String.t(),
    optional(:strict) =&gt; boolean()
  },
  fields: %{required(atom()) =&gt; Exdantic.FieldMeta.t()},
  metadata: map(),
  name: String.t()
}
```

# `add_field`

```elixir
@spec add_field(t(), atom(), Exdantic.FieldMeta.t()) :: t()
```

Adds a new field to the schema.

## Parameters
  * `schema` - The DynamicSchema instance
  * `field_name` - The field name (atom)
  * `field_meta` - The FieldMeta definition

## Returns
  * Updated DynamicSchema instance

## Examples

    iex> field_meta = %Exdantic.FieldMeta{name: :bio, type: {:type, :string, []}, required: false}
    iex> updated = Exdantic.Runtime.DynamicSchema.add_field(schema, :bio, field_meta)
    %Exdantic.Runtime.DynamicSchema{...}

# `field_names`

```elixir
@spec field_names(t()) :: [atom()]
```

Lists all field names in the schema.

## Parameters
  * `schema` - The DynamicSchema instance

## Returns
  * List of field names (atoms)

## Examples

    iex> Exdantic.Runtime.DynamicSchema.field_names(schema)
    [:name, :age, :email]

# `get_field`

```elixir
@spec get_field(t(), atom()) :: {:ok, Exdantic.FieldMeta.t()} | :error
```

Gets the field definition for a specific field name.

## Parameters
  * `schema` - The DynamicSchema instance
  * `field_name` - The field name (atom)

## Returns
  * `{:ok, field_meta}` if field exists
  * `:error` if field not found

## Examples

    iex> Exdantic.Runtime.DynamicSchema.get_field(schema, :name)
    {:ok, %Exdantic.FieldMeta{...}}

    iex> Exdantic.Runtime.DynamicSchema.get_field(schema, :nonexistent)
    :error

# `new`

```elixir
@spec new(String.t(), map(), map(), map()) :: t()
```

Creates a new DynamicSchema instance.

## Parameters
  * `name` - Unique identifier for the schema
  * `fields` - Map of field name to FieldMeta
  * `config` - Schema configuration options
  * `metadata` - Optional runtime metadata

## Examples

    iex> fields = %{name: %Exdantic.FieldMeta{...}}
    iex> config = %{title: "User Schema", strict: true}
    iex> Exdantic.Runtime.DynamicSchema.new("UserSchema", fields, config)
    %Exdantic.Runtime.DynamicSchema{...}

# `optional_fields`

```elixir
@spec optional_fields(t()) :: [atom()]
```

Gets the optional field names from the schema.

## Parameters
  * `schema` - The DynamicSchema instance

## Returns
  * List of optional field names (atoms)

## Examples

    iex> Exdantic.Runtime.DynamicSchema.optional_fields(schema)
    [:age, :bio]

# `remove_field`

```elixir
@spec remove_field(t(), atom()) :: t()
```

Removes a field from the schema.

## Parameters
  * `schema` - The DynamicSchema instance
  * `field_name` - The field name to remove (atom)

## Returns
  * Updated DynamicSchema instance

## Examples

    iex> updated = Exdantic.Runtime.DynamicSchema.remove_field(schema, :bio)
    %Exdantic.Runtime.DynamicSchema{...}

# `required_fields`

```elixir
@spec required_fields(t()) :: [atom()]
```

Gets the required field names from the schema.

## Parameters
  * `schema` - The DynamicSchema instance

## Returns
  * List of required field names (atoms)

## Examples

    iex> Exdantic.Runtime.DynamicSchema.required_fields(schema)
    [:name, :email]

# `strict?`

```elixir
@spec strict?(t()) :: boolean()
```

Checks if the schema is configured for strict validation.

## Parameters
  * `schema` - The DynamicSchema instance

## Returns
  * `true` if strict mode is enabled, `false` otherwise

## Examples

    iex> Exdantic.Runtime.DynamicSchema.strict?(schema)
    true

# `summary`

```elixir
@spec summary(t()) :: map()
```

Returns a summary of the schema structure.

## Parameters
  * `schema` - The DynamicSchema instance

## Returns
  * Map with schema summary information

## Examples

    iex> Exdantic.Runtime.DynamicSchema.summary(schema)
    %{
      name: "UserSchema",
      field_count: 3,
      required_count: 2,
      optional_count: 1,
      strict: true
    }

# `update_config`

```elixir
@spec update_config(t(), map()) :: t()
```

Updates the schema configuration.

## Parameters
  * `schema` - The DynamicSchema instance
  * `new_config` - Configuration options to merge

## Returns
  * Updated DynamicSchema instance

## Examples

    iex> updated = Exdantic.Runtime.DynamicSchema.update_config(schema, %{strict: true})
    %Exdantic.Runtime.DynamicSchema{config: %{strict: true, ...}}

---

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