# `Exdantic.JsonSchema.EnhancedResolver`
[🔗](https://github.com/nshkrdotcom/exdantic/blob/v0.1.0/lib/exdantic/json_schema/enhanced_resolver.ex#L1)

Enhanced JSON Schema resolution with full computed field and model validator metadata.

This module extends the basic resolver functionality to handle:
- Enhanced runtime schemas with model validators and computed fields
- Dynamic schema references with runtime resolution
- Cross-schema dependency resolution for complex validation pipelines
- LLM provider-specific optimizations with enhanced metadata

Phase 6 Enhancement: Complete Integration
- Seamlessly integrates all Exdantic features (struct patterns, model validators, computed fields)
- Provides unified JSON Schema generation for all schema types
- Optimizes for various LLM providers with enhanced metadata
- Maintains backward compatibility with existing resolvers

# `enhanced_resolution_options`

```elixir
@type enhanced_resolution_options() :: [
  include_model_validators: boolean(),
  include_computed_fields: boolean(),
  optimize_for_provider: :openai | :anthropic | :generic,
  resolve_runtime_refs: boolean(),
  max_depth: non_neg_integer(),
  flatten_for_llm: boolean()
]
```

# `comprehensive_analysis`

```elixir
@spec comprehensive_analysis(
  module()
  | Exdantic.Runtime.DynamicSchema.t()
  | Exdantic.Runtime.EnhancedSchema.t(),
  map() | nil,
  keyword()
) :: map()
```

Creates a comprehensive validation and schema generation report.

Useful for debugging, documentation, and understanding complex schema interactions.

## Parameters
  * `schema_or_spec` - Schema to analyze
  * `sample_data` - Optional sample data for validation testing
  * `opts` - Analysis options

## Returns
  * Comprehensive report with validation results, schema analysis, and metadata

## Examples

    iex> defmodule AnalysisTestSchema do
    ...>   use Exdantic
    ...>   schema do
    ...>     field :name, :string, required: true
    ...>   end
    ...> end
    iex> report = Exdantic.JsonSchema.EnhancedResolver.comprehensive_analysis(AnalysisTestSchema)
    iex> report.schema_type
    :compiled_schema
    iex> is_map(report.performance_metrics)
    true

# `optimize_for_dspy`

```elixir
@spec optimize_for_dspy(
  module()
  | Exdantic.Runtime.DynamicSchema.t()
  | Exdantic.Runtime.EnhancedSchema.t(),
  keyword()
) :: map()
```

Optimizes schemas specifically for DSPy and structured LLM output patterns.

DSPy requires specific JSON Schema patterns for reliable structured output.
This function ensures schemas work optimally with DSPy's validation patterns.

## Parameters
  * `schema_or_spec` - Schema to optimize
  * `dspy_opts` - DSPy-specific options

## DSPy Options
  * `:signature_mode` - Generate schema for DSPy signature patterns (default: false)
  * `:strict_types` - Enforce strict type constraints (default: true)
  * `:remove_computed_fields` - Remove computed fields for input validation (default: false)
  * `:field_descriptions` - Include field descriptions for better LLM understanding (default: true)

## Returns
  * DSPy-optimized JSON Schema

## Examples

    iex> defmodule DSPyTestSchema do
    ...>   use Exdantic
    ...>   schema do
    ...>     field :input, :string, required: true
    ...>   end
    ...> end
    iex> dspy_schema = Exdantic.JsonSchema.EnhancedResolver.optimize_for_dspy(DSPyTestSchema)
    iex> dspy_schema["x-dspy-optimized"]
    true

# `resolve_enhanced`

```elixir
@spec resolve_enhanced(
  module()
  | Exdantic.Runtime.DynamicSchema.t()
  | Exdantic.Runtime.EnhancedSchema.t(),
  enhanced_resolution_options()
) :: map()
```

Resolves JSON Schema with full enhanced schema support.

Handles all Exdantic schema types:
- Compile-time schemas (with struct support, model validators, computed fields)
- Runtime DynamicSchema instances
- Runtime EnhancedSchema instances with full features
- Mixed references between schema types

## Parameters
  * `schema_or_spec` - Schema module, runtime schema, or type specification
  * `opts` - Enhanced resolution options

## Options
  * `:include_model_validators` - Include model validator metadata (default: true)
  * `:include_computed_fields` - Include computed field metadata (default: true)
  * `:optimize_for_provider` - Optimize for specific LLM provider (default: :generic)
  * `:resolve_runtime_refs` - Resolve references to runtime schemas (default: true)
  * `:max_depth` - Maximum resolution depth (default: 10)
  * `:flatten_for_llm` - Flatten complex structures for LLM consumption (default: false)

## Returns
  * Enhanced JSON Schema with full metadata

## Examples

    # Basic usage with a module
    iex> defmodule TestSchema do
    ...>   use Exdantic
    ...>   schema do
    ...>     field :name, :string, required: true
    ...>   end
    ...> end
    iex> schema = Exdantic.JsonSchema.EnhancedResolver.resolve_enhanced(TestSchema)
    iex> schema["type"]
    "object"
    iex> schema["x-exdantic-enhanced"]
    true

# `validate_schema_compatibility`

```elixir
@spec validate_schema_compatibility(
  module()
  | Exdantic.Runtime.DynamicSchema.t()
  | Exdantic.Runtime.EnhancedSchema.t(),
  keyword()
) :: :ok | {:error, [String.t()]}
```

Validates that a schema is compatible with enhanced validation pipeline.

Checks for common issues that might cause problems with the full validation pipeline
including model validators and computed fields.

## Parameters
  * `schema_or_spec` - Schema to validate
  * `opts` - Validation options

## Returns
  * `:ok` if schema is valid
  * `{:error, issues}` if problems are found

## Examples

    iex> defmodule CompatibilityTestSchema do
    ...>   use Exdantic
    ...>   schema do
    ...>     field :name, :string, required: true
    ...>   end
    ...> end
    iex> Exdantic.JsonSchema.EnhancedResolver.validate_schema_compatibility(CompatibilityTestSchema)
    :ok

---

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