-
-
Notifications
You must be signed in to change notification settings - Fork 539
Add support for JSON Schema $defs, definitions, $ref, oneOf, anyOf and others in PropertyDefinition #726
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…opertyDefinition This PR extends PropertyDefinition to support additional JSON Schema draft-07 elements: $defs (for schema definitions) definitions $ref (schema references) anyOf (combining subschemas) These additions improve compatibility with more complex JSON Schema structures.
@dotnet-policy-service agree |
…f, exclusiveMinimum, exclusiveMaximum, format, pattern, minItems, maxItems
…ultipleOf - can be float" This reverts commit 477569b.
…rray-like type of property to support optional props https://platform.openai.com/docs/guides/structured-outputs#all-fields-must-be-required
…rray-like type of property to support optional props https://platform.openai.com/docs/guides/structured-outputs#all-fields-must-be-required
This pull request introduces significant enhancements to JSON serialization and schema validation functionality in the JSON Serialization Enhancements:
Schema Validation Enhancements:
Model Improvements:
Minor Adjustments:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances JSON Schema support in PropertyDefinition
by adding draft-07 elements, combining schema constructs, and improving type handling.
- Introduces
TypeList
with a custom converter for single-or-array"type"
values. - Adds JSON Schema keywords:
const
, numeric bounds (minimum
,maximum
, etc.),format
,pattern
,minItems
/maxItems
,$defs
,definitions
,$ref
,anyOf
,oneOf
, and related documentation. - Updates converter logic in
Converters.cs
to parse/serialize string or array types.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
File | Description |
---|---|
OpenAI.SDK/ObjectModels/SharedModels/FunctionParameters.cs | Added new schema-related properties and replaced default type handling with TypeList /Type . |
OpenAI.SDK/ObjectModels/Converters.cs | Implemented SingleOrArrayToListConverter for JSON (de)serialization of "type" values. |
Comments suppressed due to low confidence (3)
OpenAI.SDK/ObjectModels/SharedModels/FunctionParameters.cs:42
- The previous default of
type = "object"
was removed when replacing the oldType
property, which may be a breaking change for clients expecting object by default. Consider initializingTypeList
to["object"]
when no type is set or documenting this behavior clearly.
public IList<string?>? TypeList { get; set; }
OpenAI.SDK/ObjectModels/Converters.cs:94
- This converter contains nontrivial logic for both reading and writing single values or arrays. Please add unit tests covering string, array, and null cases to ensure correct (de)serialization behavior.
public class SingleOrArrayToListConverter : JsonConverter<IList<string?>>
OpenAI.SDK/ObjectModels/SharedModels/FunctionParameters.cs:204
- New properties like
anyOf
andoneOf
add conditional schema logic. Consider adding tests that serialize and deserialize scenarios with multiple subschemas to validate these fields.
[JsonPropertyName("anyOf")]
This PR extends PropertyDefinition to support additional JSON Schema draft-07 elements:
Also support array-like type of property to support optional props https://platform.openai.com/docs/guides/structured-outputs#all-fields-must-be-required like
These additions improve compatibility with more complex JSON Schema structures.