Skip to content

Commit 4e04fb5

Browse files
committed
refactor: improves schema accuracy
1 parent c213c49 commit 4e04fb5

File tree

1 file changed

+37
-16
lines changed

1 file changed

+37
-16
lines changed

src/Operations/DTO/GenerativeAiOperation.php

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -89,26 +89,47 @@ public function getResult(): ?GenerativeAiResult
8989
public static function getJsonSchema(): array
9090
{
9191
return [
92-
'type' => 'object',
93-
'properties' => [
94-
'id' => [
95-
'type' => 'string',
96-
'description' => 'Unique identifier for this operation.',
97-
],
98-
'state' => [
99-
'type' => 'string',
100-
'enum' => ['starting', 'processing', 'succeeded', 'failed', 'canceled'],
101-
'description' => 'The current state of the operation.',
92+
'oneOf' => [
93+
// Succeeded state - has result
94+
[
95+
'type' => 'object',
96+
'properties' => [
97+
'id' => [
98+
'type' => 'string',
99+
'description' => 'Unique identifier for this operation.',
100+
],
101+
'state' => [
102+
'type' => 'string',
103+
'const' => OperationStateEnum::succeeded()->value,
104+
],
105+
'result' => GenerativeAiResult::getJsonSchema(),
106+
],
107+
'required' => ['id', 'state', 'result'],
108+
'additionalProperties' => false,
102109
],
103-
'result' => [
104-
'oneOf' => [
105-
['type' => 'null'],
106-
GenerativeAiResult::getJsonSchema(),
110+
// All other states - no result
111+
[
112+
'type' => 'object',
113+
'properties' => [
114+
'id' => [
115+
'type' => 'string',
116+
'description' => 'Unique identifier for this operation.',
117+
],
118+
'state' => [
119+
'type' => 'string',
120+
'enum' => [
121+
OperationStateEnum::starting()->value,
122+
OperationStateEnum::processing()->value,
123+
OperationStateEnum::failed()->value,
124+
OperationStateEnum::canceled()->value,
125+
],
126+
'description' => 'The current state of the operation.',
127+
],
107128
],
108-
'description' => 'The result once the operation completes.',
129+
'required' => ['id', 'state'],
130+
'additionalProperties' => false,
109131
],
110132
],
111-
'required' => ['id', 'state'],
112133
];
113134
}
114135
}

0 commit comments

Comments
 (0)