Skip to content

Commit 91de3c1

Browse files
committed
Fixed URI identifier parameter mismatch in SwaggerUI Links section
1 parent 17b5daf commit 91de3c1

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Swagger/Serializer/DocumentationNormalizer.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,8 +799,11 @@ private function getLinkObject(string $resourceClass, string $operationId, strin
799799
if (!$linkObject) {
800800
return [];
801801
}
802+
preg_match_all('/{(.*)}/', $path, $uriParams);
803+
$identifierUriParam = !empty($uriParams[1]) ? end($uriParams[1]) : 'id';
804+
802805
$linkObject['operationId'] = $operationId;
803-
$linkObject['description'] = 1 === \count($identifiers) ? sprintf('The `%1$s` value returned in the response can be used as the `id` parameter in `GET %2$s`.', $identifiers[0], $path) : sprintf('The values returned in the response can be used in `GET %s`.', $path);
806+
$linkObject['description'] = 1 === \count($identifiers) ? sprintf('The `%1$s` value returned in the response can be used as the `%2$s` parameter in `GET %3$s`.', $identifiers[0], $identifierUriParam, $path) : sprintf('The values returned in the response can be used in `GET %s`.', $path);
804807

805808
return $linkObject;
806809
}

tests/Metadata/Property/Factory/SerializerPropertyMetadataFactoryTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ public function testCreate($readGroups, $writeGroups)
8383
$dummySerializerClassMetadata->addAttributeMetadata($relatedDummySerializerAttributeMetadata);
8484
$nameConvertedSerializerAttributeMetadata = new SerializerAttributeMetadata('nameConverted');
8585
$dummySerializerClassMetadata->addAttributeMetadata($nameConvertedSerializerAttributeMetadata);
86+
$nameSerializedSerializerAttributeMetadata = new SerializerAttributeMetadata('nameSerialized');
87+
$nameSerializedSerializerAttributeMetadata->setSerializedName('name_serialized');
88+
$dummySerializerClassMetadata->addAttributeMetadata($nameSerializedSerializerAttributeMetadata);
8689
$serializerClassMetadataFactoryProphecy->getMetadataFor(Dummy::class)->willReturn($dummySerializerClassMetadata);
8790
$relatedDummySerializerClassMetadata = new SerializerClassMetadata(RelatedDummy::class);
8891
$idSerializerAttributeMetadata = new SerializerAttributeMetadata('id');
@@ -105,6 +108,9 @@ public function testCreate($readGroups, $writeGroups)
105108
$nameConvertedPropertyMetadata = (new PropertyMetadata())
106109
->withType(new Type(Type::BUILTIN_TYPE_STRING, true));
107110
$decoratedProphecy->create(Dummy::class, 'nameConverted', [])->willReturn($nameConvertedPropertyMetadata);
111+
$nameSerializedPropertyMetadata = (new PropertyMetadata())
112+
->withType(new Type(Type::BUILTIN_TYPE_STRING, true));
113+
$decoratedProphecy->create(Dummy::class, 'nameSerialized', [])->willReturn($nameSerializedPropertyMetadata);
108114

109115
$resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
110116
$resourceClassResolverProphecy->isResourceClass(RelatedDummy::class)->willReturn(true);
@@ -116,6 +122,7 @@ public function testCreate($readGroups, $writeGroups)
116122
$actual[] = $serializerPropertyMetadataFactory->create(Dummy::class, 'foo');
117123
$actual[] = $serializerPropertyMetadataFactory->create(Dummy::class, 'relatedDummy');
118124
$actual[] = $serializerPropertyMetadataFactory->create(Dummy::class, 'nameConverted');
125+
$actual[] = $serializerPropertyMetadataFactory->create(Dummy::class, 'nameSerialized');
119126

120127
$this->assertInstanceOf(PropertyMetadata::class, $actual[0]);
121128
$this->assertFalse($actual[0]->isReadable());
@@ -130,6 +137,9 @@ public function testCreate($readGroups, $writeGroups)
130137
$this->assertInstanceOf(PropertyMetadata::class, $actual[2]);
131138
$this->assertFalse($actual[2]->isReadable());
132139
$this->assertFalse($actual[2]->isWritable());
140+
141+
$this->assertInstanceOf(PropertyMetadata::class, $actual[3]);
142+
$this->assertEquals($actual[3]->getSerializedName(), 'name_serialized');
133143
}
134144

135145
public function groupsProvider(): array

0 commit comments

Comments
 (0)