-
Notifications
You must be signed in to change notification settings - Fork 825
Open
Labels
area-aiMicrosoft.Extensions.AI librariesMicrosoft.Extensions.AI librariesbugThis issue describes a behavior which is not expected - a bug.This issue describes a behavior which is not expected - a bug.
Description
Description
[MaxLength(n)]
is turned into maxLength
propertly if the property is also required, but if it's nullable, it's turned into maxItems
Reproduction Steps
Given the following record and function:
record Payload([property: MaxLength(24), Required] string Value);
static void SetPayload(Payload payload) { }
The schema becomes:
{
"type": "object",
"properties": {
"payload": {
"type": "object",
"properties": {
"value": {
"type": "string",
"maxLength": 24
}
},
"required": [
"value"
]
}
},
"required": [
"payload"
]
}
But if the payload value is made nullable: record Payload([property: MaxLength(24)] string? Value);
, the schema now becomes:
{
"type": "object",
"properties": {
"payload": {
"type": "object",
"properties": {
"value": {
"type": [
"string",
"null"
],
"default": null,
"maxItems": 24
}
}
}
},
"required": [
"payload"
]
}
Expected behavior
maxLength
is consistently emitted in both cases. AFAIK, using maxItems on a non-array type is invalid (and string isn't, although from .NET's point of view it is a char[].... so perhaps that's the source of the bug?)
Actual behavior
Emits (invalid?) json schema with maxItems for a [string, null] type.
Regression?
No response
Known Workarounds
No response
Configuration
net10 preview 6, MEAI 9.7.0
Other information
No response
Copilot
Metadata
Metadata
Assignees
Labels
area-aiMicrosoft.Extensions.AI librariesMicrosoft.Extensions.AI librariesbugThis issue describes a behavior which is not expected - a bug.This issue describes a behavior which is not expected - a bug.