@@ -72,7 +72,7 @@ public function buildSchema(string $className, string $format = 'json', string $
72
72
if (null === $ metadata = $ this ->getMetadata ($ className , $ type , $ operationType , $ operationName , $ serializerContext )) {
73
73
return $ schema ;
74
74
}
75
- [$ resourceMetadata , $ serializerContext , $ inputOrOutputClass ] = $ metadata ;
75
+ [$ resourceMetadata , $ serializerContext , $ validationGroups , $ inputOrOutputClass ] = $ metadata ;
76
76
77
77
if (null === $ resourceMetadata && (null !== $ operationType || null !== $ operationName )) {
78
78
throw new \LogicException ('The $operationType and $operationName arguments must be null for non-resource class. ' );
@@ -131,7 +131,7 @@ public function buildSchema(string $className, string $format = 'json', string $
131
131
$ definition ['externalDocs ' ] = ['url ' => $ iri ];
132
132
}
133
133
134
- $ options = $ this ->getFactoryOptions ($ serializerContext , $ operationType , $ operationName );
134
+ $ options = $ this ->getFactoryOptions ($ serializerContext , $ validationGroups , $ operationType , $ operationName );
135
135
foreach ($ this ->propertyNameCollectionFactory ->create ($ inputOrOutputClass , $ options ) as $ propertyName ) {
136
136
$ propertyMetadata = $ this ->propertyMetadataFactory ->create ($ inputOrOutputClass , $ propertyName , $ options );
137
137
if (!$ propertyMetadata ->isReadable () && !$ propertyMetadata ->isWritable ()) {
@@ -200,18 +200,13 @@ private function buildPropertySchema(Schema $schema, string $definitionName, str
200
200
}
201
201
202
202
$ propertySchema = new \ArrayObject ($ propertySchema + $ valueSchema );
203
- if (DocumentationNormalizer::OPENAPI_VERSION === $ version ) {
204
- $ schema ->getDefinitions ()[$ definitionName ]['properties ' ][$ normalizedPropertyName ] = $ propertySchema ;
205
-
206
- return ;
207
- }
208
203
209
204
$ schema ->getDefinitions ()[$ definitionName ]['properties ' ][$ normalizedPropertyName ] = $ propertySchema ;
210
205
}
211
206
212
207
private function buildDefinitionName (string $ className , string $ format = 'json ' , string $ type = Schema::TYPE_OUTPUT , ?string $ operationType = null , ?string $ operationName = null , ?array $ serializerContext = null ): string
213
208
{
214
- [$ resourceMetadata , $ serializerContext , $ inputOrOutputClass ] = $ this ->getMetadata ($ className , $ type , $ operationType , $ operationName , $ serializerContext );
209
+ [$ resourceMetadata , $ serializerContext ,, $ inputOrOutputClass ] = $ this ->getMetadata ($ className , $ type , $ operationType , $ operationName , $ serializerContext );
215
210
216
211
$ prefix = $ resourceMetadata ? $ resourceMetadata ->getShortName () : (new \ReflectionClass ($ className ))->getShortName ();
217
212
if (null !== $ inputOrOutputClass && $ className !== $ inputOrOutputClass ) {
@@ -239,6 +234,7 @@ private function getMetadata(string $className, string $type = Schema::TYPE_OUTP
239
234
return [
240
235
null ,
241
236
$ serializerContext ?? [],
237
+ [],
242
238
$ className ,
243
239
];
244
240
}
@@ -259,6 +255,7 @@ private function getMetadata(string $className, string $type = Schema::TYPE_OUTP
259
255
return [
260
256
$ resourceMetadata ,
261
257
$ serializerContext ?? $ this ->getSerializerContext ($ resourceMetadata , $ type , $ operationType , $ operationName ),
258
+ $ this ->getValidationGroups ($ resourceMetadata , $ operationType , $ operationName ),
262
259
$ inputOrOutput ['class ' ],
263
260
];
264
261
}
@@ -274,10 +271,21 @@ private function getSerializerContext(ResourceMetadata $resourceMetadata, string
274
271
return $ resourceMetadata ->getTypedOperationAttribute ($ operationType , $ operationName , $ attribute , [], true );
275
272
}
276
273
274
+ private function getValidationGroups (ResourceMetadata $ resourceMetadata , ?string $ operationType , ?string $ operationName ): array
275
+ {
276
+ $ attribute = 'validation_groups ' ;
277
+
278
+ if (null === $ operationType || null === $ operationName ) {
279
+ return \is_array ($ validationGroups = $ resourceMetadata ->getAttribute ($ attribute , [])) ? $ validationGroups : [];
280
+ }
281
+
282
+ return \is_array ($ validationGroups = $ resourceMetadata ->getTypedOperationAttribute ($ operationType , $ operationName , $ attribute , [], true )) ? $ validationGroups : [];
283
+ }
284
+
277
285
/**
278
286
* Gets the options for the property name collection / property metadata factories.
279
287
*/
280
- private function getFactoryOptions (array $ serializerContext , ?string $ operationType , ?string $ operationName ): array
288
+ private function getFactoryOptions (array $ serializerContext , array $ validationGroups , ?string $ operationType , ?string $ operationName ): array
281
289
{
282
290
$ options = [];
283
291
@@ -299,6 +307,10 @@ private function getFactoryOptions(array $serializerContext, ?string $operationT
299
307
}
300
308
}
301
309
310
+ if (!empty ($ validationGroups )) {
311
+ $ options ['validation_groups ' ] = $ validationGroups ;
312
+ }
313
+
302
314
return $ options ;
303
315
}
304
316
}
0 commit comments