27
27
final class SchemaFactory implements SchemaFactoryInterface, SchemaFactoryAwareInterface
28
28
{
29
29
private const BASE_PROP = [
30
- 'readOnly ' => true ,
31
30
'type ' => 'string ' ,
32
31
];
33
32
private const BASE_PROPS = [
@@ -36,7 +35,6 @@ final class SchemaFactory implements SchemaFactoryInterface, SchemaFactoryAwareI
36
35
];
37
36
private const BASE_ROOT_PROPS = [
38
37
'@context ' => [
39
- 'readOnly ' => true ,
40
38
'oneOf ' => [
41
39
['type ' => 'string ' ],
42
40
[
@@ -74,18 +72,43 @@ public function buildSchema(string $className, string $format = 'jsonld', string
74
72
return $ schema ;
75
73
}
76
74
77
- if ('input ' === $ type ) {
78
- return $ schema ;
75
+ if (($ key = $ schema ->getRootDefinitionKey () ?? $ schema ->getItemsDefinitionKey ()) !== null ) {
76
+ $ postfix = '. ' .$ type ;
77
+ $ definitions = $ schema ->getDefinitions ();
78
+ $ definitions [$ key .$ postfix ] = $ definitions [$ key ];
79
+ unset($ definitions [$ key ]);
80
+
81
+ if (($ schema ['type ' ] ?? '' ) === 'array ' ) {
82
+ $ schema ['items ' ]['$ref ' ] .= $ postfix ;
83
+ } else {
84
+ $ schema ['$ref ' ] .= $ postfix ;
85
+ }
79
86
}
80
87
81
88
$ definitions = $ schema ->getDefinitions ();
82
89
if ($ key = $ schema ->getRootDefinitionKey ()) {
83
90
$ definitions [$ key ]['properties ' ] = self ::BASE_ROOT_PROPS + ($ definitions [$ key ]['properties ' ] ?? []);
91
+ if (Schema::TYPE_OUTPUT === $ type ) {
92
+ foreach (array_keys (self ::BASE_ROOT_PROPS ) as $ property ) {
93
+ $ definitions [$ key ]['required ' ] ??= [];
94
+ if (!\in_array ($ property , $ definitions [$ key ]['required ' ], true )) {
95
+ $ definitions [$ key ]['required ' ][] = $ property ;
96
+ }
97
+ }
98
+ }
84
99
85
100
return $ schema ;
86
101
}
87
102
if ($ key = $ schema ->getItemsDefinitionKey ()) {
88
103
$ definitions [$ key ]['properties ' ] = self ::BASE_PROPS + ($ definitions [$ key ]['properties ' ] ?? []);
104
+ if (Schema::TYPE_OUTPUT === $ type ) {
105
+ foreach (array_keys (self ::BASE_PROPS ) as $ property ) {
106
+ $ definitions [$ key ]['required ' ] ??= [];
107
+ if (!\in_array ($ property , $ definitions [$ key ]['required ' ], true )) {
108
+ $ definitions [$ key ]['required ' ][] = $ property ;
109
+ }
110
+ }
111
+ }
89
112
}
90
113
91
114
if (($ schema ['type ' ] ?? '' ) === 'array ' ) {
0 commit comments