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
@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 operationschemas- Map of schema names to Schema structs
Returns
The resolved schema or nil if no schema is found.
@spec resolve_schema(ExOpenAI.Codegen.DocsParser.Schema.t(), %{ required(String.t()) => ExOpenAI.Codegen.DocsParser.Schema.t() }) :: ExOpenAI.Codegen.DocsParser.Schema.t()
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"]