Class Schema
Schema is used to define the format of input/output data. Represents a select subset of an OpenAPI 3.0 schema object (https://spec.openapis.org/oas/v3.0.3#schema-object). More fields may be added in the future as needed.
public record Schema : IEquatable<Schema>
- Inheritance
-
Schema
- Implements
- Inherited Members
Properties
AdditionalProperties
Optional. Can either be a boolean or an object; controls the presence of additional properties.
[JsonPropertyName("additionalProperties")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public object? AdditionalProperties { get; set; }
Property Value
AnyOf
Optional. The instance must be valid against any (one or more) of the subschemas listed in
any_of.
[JsonPropertyName("anyOf")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public List<Schema>? AnyOf { get; set; }
Property Value
Default
Optional. Default value to use if the field is not specified.
[JsonPropertyName("default")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public object? Default { get; set; }
Property Value
Defs
Optional. A map of definitions for use by ref Only allowed at the root of the schema.
[JsonPropertyName("defs")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public Dictionary<string, Schema>? Defs { get; set; }
Property Value
Description
Optional. Describes the data. The model uses this field to understand the purpose of the schema and how to use it. It is a best practice to provide a clear and descriptive explanation for the schema and its properties here, rather than in the prompt.
[JsonPropertyName("description")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? Description { get; set; }
Property Value
Enum
Optional. Possible values of the field. This field can be used to restrict a value to a
fixed set of values. To mark a field as an enum, set format to enum and provide the list
of possible values in enum. For example: 1. To define directions: {type:STRING, format:enum, enum:["EAST", "NORTH", "SOUTH", "WEST"]} 2. To define apartment numbers:
{type:INTEGER, format:enum, enum:["101", "201", "301"]}
[JsonPropertyName("enum")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public List<string>? Enum { get; set; }
Property Value
Example
Optional. Example of an instance of this schema.
[JsonPropertyName("example")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public object? Example { get; set; }
Property Value
Format
Optional. The format of the data. For NUMBER type, format can be float or double. For
INTEGER type, format can be int32 or int64. For STRING type, format can be email,
byte, date, date-time, password, and other formats to further refine the data type.
[JsonPropertyName("format")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? Format { get; set; }
Property Value
Items
Optional. If type is ARRAY, items specifies the schema of elements in the array.
[JsonPropertyName("items")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public Schema? Items { get; set; }
Property Value
MaxItems
Optional. If type is ARRAY, max_items specifies the maximum number of items in an array.
[JsonPropertyName("maxItems")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonConverter(typeof(StringToNullableLongConverter))]
public long? MaxItems { get; set; }
Property Value
- long?
MaxLength
Optional. If type is STRING, max_length specifies the maximum length of the string.
[JsonPropertyName("maxLength")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonConverter(typeof(StringToNullableLongConverter))]
public long? MaxLength { get; set; }
Property Value
- long?
MaxProperties
Optional. If type is OBJECT, max_properties specifies the maximum number of properties
that can be provided.
[JsonPropertyName("maxProperties")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonConverter(typeof(StringToNullableLongConverter))]
public long? MaxProperties { get; set; }
Property Value
- long?
Maximum
Optional. If type is INTEGER or NUMBER, maximum specifies the maximum allowed value.
[JsonPropertyName("maximum")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public double? Maximum { get; set; }
Property Value
MinItems
Optional. If type is ARRAY, min_items specifies the minimum number of items in an array.
[JsonPropertyName("minItems")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonConverter(typeof(StringToNullableLongConverter))]
public long? MinItems { get; set; }
Property Value
- long?
MinLength
Optional. If type is STRING, min_length specifies the minimum length of the string.
[JsonPropertyName("minLength")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonConverter(typeof(StringToNullableLongConverter))]
public long? MinLength { get; set; }
Property Value
- long?
MinProperties
Optional. If type is OBJECT, min_properties specifies the minimum number of properties
that can be provided.
[JsonPropertyName("minProperties")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonConverter(typeof(StringToNullableLongConverter))]
public long? MinProperties { get; set; }
Property Value
- long?
Minimum
Optional. If type is INTEGER or NUMBER, minimum specifies the minimum allowed value.
[JsonPropertyName("minimum")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public double? Minimum { get; set; }
Property Value
Nullable
Optional. Indicates if the value of this field can be null.
[JsonPropertyName("nullable")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public bool? Nullable { get; set; }
Property Value
- bool?
Pattern
Optional. If type is STRING, pattern specifies a regular expression that the string must
match.
[JsonPropertyName("pattern")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? Pattern { get; set; }
Property Value
Properties
Optional. If type is OBJECT, properties is a map of property names to schema definitions
for each property of the object.
[JsonPropertyName("properties")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public Dictionary<string, Schema>? Properties { get; set; }
Property Value
PropertyOrdering
Optional. Order of properties displayed or used where order matters. This is not a standard field in OpenAPI specification, but can be used to control the order of properties.
[JsonPropertyName("propertyOrdering")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public List<string>? PropertyOrdering { get; set; }
Property Value
Ref
Optional. Allows indirect references between schema nodes. The value should be a valid
reference to a child of the root defs. For example, the following schema defines a
reference to a schema node named "Pet": type: object properties: pet: ref: #/defs/Pet defs:
Pet: type: object properties: name: type: string The value of the "pet" property is a
reference to the schema node named "Pet". See details in
https://json-schema.org/understanding-json-schema/structuring
[JsonPropertyName("ref")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? Ref { get; set; }
Property Value
Required
Optional. If type is OBJECT, required lists the names of properties that must be
present.
[JsonPropertyName("required")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public List<string>? Required { get; set; }
Property Value
Title
Optional. Title for the schema.
[JsonPropertyName("title")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? Title { get; set; }
Property Value
Type
Optional. Data type of the schema field.
[JsonPropertyName("type")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public Type? Type { get; set; }
Property Value
- Type?
Methods
FromJson(string, JsonSerializerOptions?)
Deserializes a JSON string to a Schema object.
public static Schema? FromJson(string jsonString, JsonSerializerOptions? options = null)
Parameters
jsonStringstringThe JSON string to deserialize.
optionsJsonSerializerOptionsOptional JsonSerializerOptions.
Returns
- Schema
The deserialized Schema object, or null if deserialization fails.