Skip to content

Commit 57d9b91

Browse files
HaKIMuschr-hertel
authored andcommitted
Feature/treat nullable fields as required
1 parent beadd5c commit 57d9b91

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

src/agent/tests/StructuredOutput/ResponseFormatFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function testCreate()
3838
'isActive' => ['type' => 'boolean'],
3939
'age' => ['type' => ['integer', 'null']],
4040
],
41-
'required' => ['id', 'name', 'createdAt', 'isActive'],
41+
'required' => ['id', 'name', 'createdAt', 'isActive', 'age'],
4242
'additionalProperties' => false,
4343
],
4444
'strict' => true,

src/platform/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
0.1
55
---
66

7+
* Add nullables as required in structured outputs
78
* Add support for Albert API for French/EU data sovereignty
89
* Add unified abstraction layer for interacting with various AI models and providers
910
* Add support for 16+ AI providers:

src/platform/src/Contract/JsonSchema/Factory.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ private function convertTypes(array $elements): ?array
117117
if (!isset($schema['anyOf'])) {
118118
$schema['type'] = [$schema['type'], 'null'];
119119
}
120-
} elseif (!($element instanceof \ReflectionParameter && $element->isOptional())) {
120+
}
121+
122+
if (!($element instanceof \ReflectionParameter && $element->isOptional())) {
121123
$result['required'][] = $name;
122124
}
123125

src/platform/tests/Contract/JsonSchema/FactoryTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public function testBuildPropertiesForUserClass()
183183
'isActive' => ['type' => 'boolean'],
184184
'age' => ['type' => ['integer', 'null']],
185185
],
186-
'required' => ['id', 'name', 'createdAt', 'isActive'],
186+
'required' => ['id', 'name', 'createdAt', 'isActive', 'age'],
187187
'additionalProperties' => false,
188188
];
189189

@@ -304,7 +304,7 @@ public function testBuildPropertiesForUnionTypeDto()
304304
],
305305
],
306306
],
307-
'required' => [],
307+
'required' => ['time'],
308308
'additionalProperties' => false,
309309
];
310310

@@ -347,7 +347,7 @@ public function testBuildPropertiesForExampleDto()
347347
'enum' => ['Foo', 'Bar', null],
348348
],
349349
],
350-
'required' => ['name', 'taxRate'],
350+
'required' => ['name', 'taxRate', 'category'],
351351
'additionalProperties' => false,
352352
];
353353

0 commit comments

Comments
 (0)