Skip to content

Commit 4016c69

Browse files
author
Amrouche Hamza
committed
fix an issue in swagger generator when using two groups
1 parent d644132 commit 4016c69

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/Swagger/Serializer/DocumentationNormalizer.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ private function getPathOperation(string $operationName, array $operation, strin
189189
private function updateGetOperation(\ArrayObject $pathOperation, array $mimeTypes, bool $collection, ResourceMetadata $resourceMetadata, string $resourceClass, string $resourceShortName, string $operationName, \ArrayObject $definitions)
190190
{
191191
$responseDefinitionKey = $this->getDefinition($definitions, $collection, false, $resourceMetadata, $resourceClass, $operationName);
192+
192193
$pathOperation['produces'] ?? $pathOperation['produces'] = $mimeTypes;
193194

194195
if ($collection) {
@@ -203,7 +204,7 @@ private function updateGetOperation(\ArrayObject $pathOperation, array $mimeType
203204
],
204205
];
205206

206-
if (!isset($pathOperation['parameters']) && count($parameters = $this->getFiltersParameters($resourceClass, $operationName, $resourceMetadata)) > 0) {
207+
if (!isset($pathOperation['parameters']) && count($parameters = $this->getFiltersParameters($resourceClass, $operationName, $resourceMetadata, $responseDefinitionKey)) > 0) {
207208
$pathOperation['parameters'] = $parameters;
208209
}
209210

@@ -350,8 +351,7 @@ private function getDefinition(\ArrayObject $definitions, bool $collection, bool
350351
} else {
351352
$definitionKey = $resourceMetadata->getShortName();
352353
}
353-
354-
$definitions[$definitionKey] = $this->getDefinitionSchema($resourceClass, $resourceMetadata, $serializerContext);
354+
$definitions[$definitionKey] = $this->getDefinitionSchema($resourceClass, $resourceMetadata, $serializerContext, $definitionKey);
355355

356356
return $definitionKey;
357357
}
@@ -369,7 +369,7 @@ private function getDefinition(\ArrayObject $definitions, bool $collection, bool
369369
*
370370
* @return \ArrayObject
371371
*/
372-
private function getDefinitionSchema(string $resourceClass, ResourceMetadata $resourceMetadata, array $serializerContext = null): \ArrayObject
372+
private function getDefinitionSchema(string $resourceClass, ResourceMetadata $resourceMetadata, array $serializerContext = null, $definitionKey = null): \ArrayObject
373373
{
374374
$definitionSchema = new \ArrayObject(['type' => 'object']);
375375

@@ -390,7 +390,7 @@ private function getDefinitionSchema(string $resourceClass, ResourceMetadata $re
390390
$definitionSchema['required'][] = $normalizedPropertyName;
391391
}
392392

393-
$definitionSchema['properties'][$normalizedPropertyName] = $this->getPropertySchema($propertyMetadata);
393+
$definitionSchema['properties'][$normalizedPropertyName] = $this->getPropertySchema($propertyMetadata, $definitionKey);
394394
}
395395

396396
return $definitionSchema;
@@ -405,7 +405,7 @@ private function getDefinitionSchema(string $resourceClass, ResourceMetadata $re
405405
*
406406
* @return \ArrayObject
407407
*/
408-
private function getPropertySchema(PropertyMetadata $propertyMetadata): \ArrayObject
408+
private function getPropertySchema(PropertyMetadata $propertyMetadata, $definitionKey = null): \ArrayObject
409409
{
410410
$propertySchema = new \ArrayObject();
411411

@@ -430,7 +430,7 @@ private function getPropertySchema(PropertyMetadata $propertyMetadata): \ArrayOb
430430
$className = $valueType->getClassName();
431431
}
432432

433-
$valueSchema = $this->getType($builtinType, $isCollection, $className, $propertyMetadata->isReadableLink());
433+
$valueSchema = $this->getType($builtinType, $isCollection, $className, $propertyMetadata->isReadableLink(), $definitionKey);
434434

435435
return new \ArrayObject((array) $propertySchema + $valueSchema);
436436
}
@@ -445,10 +445,10 @@ private function getPropertySchema(PropertyMetadata $propertyMetadata): \ArrayOb
445445
*
446446
* @return array
447447
*/
448-
private function getType(string $type, bool $isCollection, string $className = null, bool $readableLink = null): array
448+
private function getType(string $type, bool $isCollection, string $className = null, bool $readableLink = null, $definitionKey = null): array
449449
{
450450
if ($isCollection) {
451-
return ['type' => 'array', 'items' => $this->getType($type, false, $className, $readableLink)];
451+
return ['type' => 'array', 'items' => $this->getType($type, false, $className, $readableLink, $definitionKey)];
452452
}
453453

454454
if (Type::BUILTIN_TYPE_STRING === $type) {
@@ -481,7 +481,7 @@ private function getType(string $type, bool $isCollection, string $className = n
481481
}
482482

483483
if (true === $readableLink) {
484-
return ['$ref' => sprintf('#/definitions/%s', $this->resourceMetadataFactory->create($className)->getShortName())];
484+
return ['$ref' => sprintf('#/definitions/%s', $definitionKey ?: $this->resourceMetadataFactory->create($className)->getShortName())];
485485
}
486486
}
487487

@@ -529,7 +529,7 @@ private function computeDoc(Documentation $documentation, \ArrayObject $definiti
529529
*
530530
* @return array
531531
*/
532-
private function getFiltersParameters(string $resourceClass, string $operationName, ResourceMetadata $resourceMetadata): array
532+
private function getFiltersParameters(string $resourceClass, string $operationName, ResourceMetadata $resourceMetadata, $definitionKey): array
533533
{
534534
if (null === $this->filterCollection) {
535535
return [];
@@ -548,7 +548,7 @@ private function getFiltersParameters(string $resourceClass, string $operationNa
548548
'in' => 'query',
549549
'required' => $data['required'],
550550
];
551-
$parameter += $this->getType($data['type'], false);
551+
$parameter += $this->getType($data['type'], false, null, null, $definitionKey);
552552

553553
if (isset($data['swagger'])) {
554554
$parameter = $data['swagger'] + $parameter;

0 commit comments

Comments
 (0)