Class Schema
- Namespace
- GenerativeAI.Types
- Assembly
- GenerativeAI.dll
The Schema object allows the definition of input and output data types. These types can be objects, but also primitives and arrays. Represents a select subset of an OpenAPI 3.0 schema object.
public class Schema
- Inheritance
-
Schema
- Inherited Members
- Extension Methods
Constructors
Schema()
Initializes a new instance of the Schema class for JSON deserialization.
public Schema()
Schema(string)
Initializes a new instance of the Schema class with the specified type.
public Schema(string type)
Parameters
typestringThe data type for the schema.
Properties
AdditionalProperties
Optional. Schema for additional properties not explicitly defined. Note: This property is not supported by the Gemini API and is excluded from serialization.
[JsonIgnore]
public JsonNode? AdditionalProperties { get; set; }
Property Value
AnyOf
Optional. The value should be valid against any of the provided schemas.
[JsonPropertyName("anyOf")]
public List<Schema>? AnyOf { get; set; }
Property Value
Default
Optional. Default value for this schema.
[JsonPropertyName("default")]
public JsonNode? Default { get; set; }
Property Value
Defs
Optional. Definitions of reusable schemas.
[JsonPropertyName("defs")]
public Dictionary<string, Schema>? Defs { get; set; }
Property Value
Description
Optional. A brief description of the parameter. This could contain examples of use. Parameter description may be formatted as Markdown.
[JsonPropertyName("description")]
public string? Description { get; set; }
Property Value
Enum
Optional. Possible values of the element of Type.STRING with enum format. For example we can define an Enum Direction as: {type:STRING, format:enum, enum:["EAST", NORTH", "SOUTH", "WEST"]}
[JsonPropertyName("enum")]
public List<string>? Enum { get; set; }
Property Value
Example
Optional. Example value for this schema.
[JsonPropertyName("example")]
public JsonNode? Example { get; set; }
Property Value
Format
Optional. The format of the data. This is used only for primitive datatypes. Supported formats: for NUMBER type: float, double for INTEGER type: int32, int64 for STRING type: enum
[JsonPropertyName("format")]
public string? Format { get; set; }
Property Value
Items
Optional. Schema of the elements of Type.ARRAY.
[JsonPropertyName("items")]
public Schema? Items { get; set; }
Property Value
MaxItems
Optional. Maximum number of the elements for Type.ARRAY.
[JsonPropertyName("maxItems")]
public long? MaxItems { get; set; }
Property Value
- long?
MaxLength
Optional. Maximum length for string types.
[JsonPropertyName("maxLength")]
public int? MaxLength { get; set; }
Property Value
- int?
MaxProperties
Optional. Maximum number of properties for object types.
[JsonPropertyName("maxProperties")]
public int? MaxProperties { get; set; }
Property Value
- int?
Maximum
Optional. Maximum value for numeric types.
[JsonPropertyName("maximum")]
public double? Maximum { get; set; }
Property Value
MinItems
Optional. Minimum number of the elements for Type.ARRAY.
[JsonPropertyName("minItems")]
public long? MinItems { get; set; }
Property Value
- long?
MinLength
Optional. Minimum length for string types.
[JsonPropertyName("minLength")]
public int? MinLength { get; set; }
Property Value
- int?
MinProperties
Optional. Minimum number of properties for object types.
[JsonPropertyName("minProperties")]
public int? MinProperties { get; set; }
Property Value
- int?
Minimum
Optional. Minimum value for numeric types.
[JsonPropertyName("minimum")]
public double? Minimum { get; set; }
Property Value
Nullable
Optional. Indicates if the value may be null.
[JsonPropertyName("nullable")]
public bool? Nullable { get; set; }
Property Value
- bool?
Pattern
Optional. Regular expression pattern for string validation.
[JsonPropertyName("pattern")]
public string? Pattern { get; set; }
Property Value
Properties
Optional. Properties of Type.OBJECT.
An object containing a list of "key": value pairs.
Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.
[JsonPropertyName("properties")]
public Dictionary<string, Schema>? Properties { get; set; }
Property Value
PropertyOrdering
Optional. The order of the properties. Not a standard field in open api spec. Used to determine the order of the properties in the response.
[JsonPropertyName("propertyOrdering")]
public List<string>? PropertyOrdering { get; set; }
Property Value
Ref
Optional. Reference to another schema definition.
[JsonPropertyName("ref")]
public string? Ref { get; set; }
Property Value
Required
Optional. Required properties of Type.OBJECT.
[JsonPropertyName("required")]
public List<string>? Required { get; set; }
Property Value
Title
Optional. Title of the schema.
[JsonPropertyName("title")]
public string? Title { get; set; }
Property Value
Type
Required. Data type.
[JsonPropertyName("type")]
public string Type { get; set; }
Property Value
Methods
FromEnum<T>(JsonSerializerOptions?)
Creates a schema from an enum type.
public static Schema? FromEnum<T>(JsonSerializerOptions? options = null) where T : Enum
Parameters
optionsJsonSerializerOptionsOptional JSON serializer options.
Returns
- Schema
A schema representing the enum type, or null if conversion fails.
Type Parameters
TThe enum type to create a schema from.
FromObject(object, JsonSerializerOptions?)
Creates a Schema object representing the structure of the specified object type. This method evaluates the properties and structure of the provided object and generates a corresponding schema representation.
public static Schema FromObject(object value, JsonSerializerOptions? options = null)
Parameters
valueobjectThe object from which to generate the schema.
optionsJsonSerializerOptionsOptional JSON serializer options used for customization during schema generation.