@@ -37,37 +37,43 @@ final class SchemaFactory implements SchemaFactoryInterface, SchemaFactoryAwareI
37
37
use SchemaUriPrefixTrait;
38
38
39
39
private const ITEM_BASE_SCHEMA_NAME = 'HydraItemBaseSchema ' ;
40
+ private const ITEM_BASE_SCHEMA_OUTPUT_NAME = 'HydraOutputBaseSchema ' ;
40
41
private const COLLECTION_BASE_SCHEMA_NAME = 'HydraCollectionBaseSchema ' ;
41
42
private const BASE_PROP = [
42
- 'readOnly ' => true ,
43
43
'type ' => 'string ' ,
44
44
];
45
45
private const BASE_PROPS = [
46
46
'@id ' => self ::BASE_PROP ,
47
47
'@type ' => self ::BASE_PROP ,
48
48
];
49
- private const BASE_ROOT_PROPS = [
50
- '@context ' => [
51
- 'readOnly ' => true ,
52
- 'oneOf ' => [
53
- ['type ' => 'string ' ],
54
- [
55
- 'type ' => 'object ' ,
56
- 'properties ' => [
57
- '@vocab ' => [
58
- 'type ' => 'string ' ,
59
- ],
60
- 'hydra ' => [
61
- 'type ' => 'string ' ,
62
- 'enum ' => [ContextBuilder::HYDRA_NS ],
49
+ private const ITEM_BASE_SCHEMA = [
50
+ 'type ' => 'object ' ,
51
+ 'properties ' => [
52
+ '@context ' => [
53
+ 'oneOf ' => [
54
+ ['type ' => 'string ' ],
55
+ [
56
+ 'type ' => 'object ' ,
57
+ 'properties ' => [
58
+ '@vocab ' => [
59
+ 'type ' => 'string ' ,
60
+ ],
61
+ 'hydra ' => [
62
+ 'type ' => 'string ' ,
63
+ 'enum ' => [ContextBuilder::HYDRA_NS ],
64
+ ],
63
65
],
66
+ 'required ' => ['@vocab ' , 'hydra ' ],
67
+ 'additionalProperties ' => true ,
64
68
],
65
- 'required ' => ['@vocab ' , 'hydra ' ],
66
- 'additionalProperties ' => true ,
67
69
],
68
- ],
70
+ ] + self :: BASE_PROPS ,
69
71
],
70
- ] + self ::BASE_PROPS ;
72
+ ];
73
+
74
+ private const ITEM_BASE_SCHEMA_OUTPUT = [
75
+ 'required ' => ['@id ' , '@type ' ],
76
+ ] + self ::ITEM_BASE_SCHEMA ;
71
77
72
78
/**
73
79
* @param array<string, mixed> $defaultContext
@@ -126,13 +132,14 @@ public function buildSchema(string $className, string $format = 'jsonld', string
126
132
127
133
$ key = $ schema ->getRootDefinitionKey () ?? $ collectionKey ;
128
134
129
- if (!isset ($ definitions [self ::ITEM_BASE_SCHEMA_NAME ])) {
130
- $ definitions [self ::ITEM_BASE_SCHEMA_NAME ] = ['type ' => 'object ' , 'properties ' => self ::BASE_ROOT_PROPS ];
135
+ $ name = Schema::TYPE_OUTPUT === $ type ? self ::ITEM_BASE_SCHEMA_NAME : self ::ITEM_BASE_SCHEMA_OUTPUT_NAME ;
136
+ if (!isset ($ definitions [$ name ])) {
137
+ $ definitions [$ name ] = Schema::TYPE_OUTPUT === $ type ? self ::ITEM_BASE_SCHEMA_OUTPUT : self ::ITEM_BASE_SCHEMA ;
131
138
}
132
139
133
140
$ definitions [$ definitionName ] = [
134
141
'allOf ' => [
135
- ['$ref ' => $ prefix .self :: ITEM_BASE_SCHEMA_NAME ],
142
+ ['$ref ' => $ prefix .$ name ],
136
143
['$ref ' => $ prefix .$ key ],
137
144
],
138
145
];
0 commit comments