schemaadapt

package
v2.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 30, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package schemaadapt walks a JSON Schema so provider adapters can rewrite it into the dialect their API accepts.

Every provider that takes a JSON Schema takes a different one. The rules are not merely different in degree — they contradict:

Anthropic  REQUIRES additionalProperties: false on every object node
Gemini     REJECTS  the additionalProperties keyword outright
OpenAI     REQUIRES additionalProperties: false AND every property in required

So there is no schema a pack author can write that is portable, and the adapter — the only layer that knows which vendor it is talking to — has to do the rewriting. Each adapter supplies its own rules; this package supplies the traversal they all need, because the traversal is where the bugs are: issue #2055 was a schema that satisfied the rule at the top level and broke on an object nested inside an array's items.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsObjectNode

func IsObjectNode(node map[string]any) bool

IsObjectNode reports whether a schema node describes a JSON object, and so is subject to the object rules the providers enforce.

Both spellings count: "type": "object", and a node that declares properties without a type (common in hand-written schemas, and the providers treat it as an object).

func Rewrite

func Rewrite(raw json.RawMessage, visit func(map[string]any)) json.RawMessage

Rewrite decodes raw, applies visit to every schema node, and re-encodes.

A schema that does not decode is returned unchanged: the adapters call this on the way to the wire, and a malformed schema is the API's error to report, with its own message, not something to swallow here.

func Walk

func Walk(node any, visit func(map[string]any))

Walk visits every schema node in a decoded JSON Schema document, parents before children, and calls visit on each.

Traversal is structural: it descends only through keywords whose values are schemas. A blunt walk of every map in the document is tempting and wrong — it would treat a user property literally named "properties" or "additionalProperties" as a schema keyword and rewrite the caller's data model. $ref is a string and is not followed, which also means a recursive schema cannot send this into a loop.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL