Skip to content

JsonSchemas

Namespace: Vercel.AI.ProviderUtils

public static class JsonSchemas

Builds JSON Schema documents from explicit shapes. This is not a Zod converter.

Inheritance: object

View source

public static JsonObject AddAdditionalProperties(JsonObject schema)

Sets additionalProperties to false on object schemas, including objects nested in combinators, items, and definitions. A schema-valued additionalProperties is kept and visited.

Parameters

Name Type Description
schema JsonObject

Returns: JsonObject

View source

public static JsonObject AnyOf(params JsonNode[] schemas)

anyOf schema.

Parameters

Name Type Description
schemas JsonNode[]

Returns: JsonObject

View source

public static JsonObject Anything()

Schema that accepts any value.

Returns: JsonObject

View source

public static JsonObject Array(JsonNode? items = null, int? minItems = null, int? maxItems = null, JsonNode? additionalItems = null)

Array schema. <code class=“paramref”>items</code> may be a schema or a tuple of schemas.

Parameters

Name Type Description
items JsonNode
minItems int?
maxItems int?
additionalItems JsonNode

Returns: JsonObject

View source

public static JsonObject Boolean()

Boolean schema.

Returns: JsonObject

View source

public static JsonObject DateTimeString()

Date-time string.

Returns: JsonObject

View source

public static JsonObject EmptyObject()

Empty object schema used when a caller does not supply one.

Returns: JsonObject

View source

public static string EndsWithPattern(string literal)

Pattern that anchors <code class=“paramref”>literal</code> at the end.

Parameters

Name Type Description
literal string

Returns: string

View source

public static JsonObject Enum(JsonNode type, JsonArray values)

Enum schema. <code class=“paramref”>type</code> may be a string or an array of type names.

Parameters

Name Type Description
type JsonNode
values JsonArray

Returns: JsonObject

View source

public static string EscapePattern(string literal)

Escapes a literal for a JSON Schema pattern.

Parameters

Name Type Description
literal string

Returns: string

View source

public static string IncludesPattern(string literal)

Pattern that contains <code class=“paramref”>literal</code>.

Parameters

Name Type Description
literal string

Returns: string

View source

public static JsonObject Integer(double? minimum = null, double? maximum = null, string? format = null)

Integer schema.

Parameters

Name Type Description
minimum double?
maximum double?
format string

Returns: JsonObject

View source

public static JsonObject Literal(string type, JsonNode constant, string? description = null)

A single literal.

Parameters

Name Type Description
type string
constant JsonNode
description string

Returns: JsonObject

View source

public static JsonObject NotEmpty()

JSON Schema not of an empty schema, used for an explicit undefined alternative.

Returns: JsonObject

View source

public static JsonObject Null()

Null schema.

Returns: JsonObject

View source

Number(double?, double?, double?, double?, double?)

Section titled “Number(double?, double?, double?, double?, double?)”
public static JsonObject Number(double? minimum = null, double? maximum = null, double? exclusiveMinimum = null, double? exclusiveMaximum = null, double? multipleOf = null)

Number schema.

Parameters

Name Type Description
minimum double?
maximum double?
exclusiveMinimum double?
exclusiveMaximum double?
multipleOf double?

Returns: JsonObject

View source

Object(IReadOnlyList<KeyValuePair<string, JsonNode>>?, IReadOnlyList<string>?, JsonNode?, bool?, JsonNode?)

Section titled “Object(IReadOnlyList<KeyValuePair<string, JsonNode>>?, IReadOnlyList<string>?, JsonNode?, bool?, JsonNode?)”
public static JsonObject Object(IReadOnlyList<KeyValuePair<string, JsonNode>>? properties = null, IReadOnlyList<string>? required = null, JsonNode? additionalProperties = null, bool? additionalPropertiesFlag = null, JsonNode? defaultValue = null)

Object schema. Pass <code class=“paramref”>additionalProperties</code> for a schema, or <code class=“paramref”>additionalPropertiesFlag</code> for true or false. Omit both to leave the keyword unset.

Parameters

Name Type Description
properties IReadOnlyList<KeyValuePair<string, JsonNode>>
required IReadOnlyList<string>
additionalProperties JsonNode
additionalPropertiesFlag bool?
defaultValue JsonNode

Returns: JsonObject

View source

public static JsonObject PrimitiveUnion(params string[] types)

Union of primitive type names.

Parameters

Name Type Description
types string[]

Returns: JsonObject

View source

public static JsonObject Record(JsonNode additionalProperties, JsonNode? propertyNames = null)

Object whose values match <code class=“paramref”>additionalProperties</code>.

Parameters

Name Type Description
additionalProperties JsonNode
propertyNames JsonNode

Returns: JsonObject

View source

public static string StartsWithPattern(string literal)

Pattern that anchors <code class=“paramref”>literal</code> at the start.

Parameters

Name Type Description
literal string

Returns: string

View source

String(int?, int?, string?, string?, string?, JsonArray?, JsonArray?)

Section titled “String(int?, int?, string?, string?, string?, JsonArray?, JsonArray?)”
public static JsonObject String(int? minLength = null, int? maxLength = null, string? format = null, string? pattern = null, string? contentEncoding = null, JsonArray? allOf = null, JsonArray? anyOf = null)

String schema.

Parameters

Name Type Description
minLength int?
maxLength int?
format string
pattern string
contentEncoding string
allOf JsonArray
anyOf JsonArray

Returns: JsonObject

View source

public static string Stringify(JsonNode? node)

Serializes a schema the way JSON.stringify does: no extra whitespace, insertion order.

Parameters

Name Type Description
node JsonNode

Returns: string

View source

public static JsonObject WithDefault(JsonObject schema, JsonNode defaultValue)

Copies <code class=“paramref”>schema</code> and sets default.

Parameters

Name Type Description
schema JsonObject
defaultValue JsonNode

Returns: JsonObject

View source

Apache-2.0 · Copyright 2023 Vercel, Inc. · unofficial community port, not an official Vercel product