View Source ExOpenAI.Codegen.SchemaResolver (ex_openai.ex v2.0.0-beta2)

Shared utilities for resolving OpenAPI schemas.

Handles schema resolution including allOf merging and reference resolution.

Summary

Functions

Gets and resolves the schema for a request body.

Resolves a schema, handling allOf merging.

Functions

Link to this function

get_request_body_schema(request_body, schemas)

View Source
@spec get_request_body_schema(map() | nil, %{
  required(String.t()) => ExOpenAI.Codegen.DocsParser.Schema.t()
}) :: ExOpenAI.Codegen.DocsParser.Schema.t() | nil

Gets and resolves the schema for a request body.

Extracts the schema reference from the request body content and resolves it using the provided schemas map.

Parameters

  • request_body - The request body from an operation
  • schemas - Map of schema names to Schema structs

Returns

The resolved schema or nil if no schema is found.

Link to this function

resolve_schema(schema, schemas)

View Source

Resolves a schema, handling allOf merging.

When a schema contains allOf, this function merges all referenced schemas and inline schemas into a single resolved schema with combined properties and required fields.

Examples

iex> schema = %Schema{
...>   all_of: [
...>     %Schema{ref: "#/components/schemas/Base"},
...>     %Schema{properties: %{"extra" => %Schema{type: "string"}}}
...>   ]
...> }
iex> schemas = %{"Base" => %Schema{properties: %{"id" => %Schema{type: "integer"}}}}
iex> resolved = resolve_schema(schema, schemas)
iex> Map.keys(resolved.properties)
["extra", "id"]