Skip to content

Commit 18935e9

Browse files
committed
Use serializedName in Swagger UI Links section
1 parent 000a56a commit 18935e9

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

src/Metadata/Property/Factory/SerializerPropertyMetadataFactory.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ public function create(string $resourceClass, string $property, array $options =
6161
return $propertyMetadata;
6262
}
6363

64+
$serializerMetadataAttributes = $this->serializerClassMetadataFactory->getMetadataFor($resourceClass)->getAttributesMetadata();
65+
if (null !== ($serializedName = $serializerMetadataAttributes[$property]->getSerializedName())) {
66+
$propertyMetadata = $propertyMetadata->withSerializedName($serializedName);
67+
}
68+
6469
$propertyMetadata = $this->transformReadWrite($propertyMetadata, $resourceClass, $property, $normalizationGroups, $denormalizationGroups);
6570

6671
return $this->transformLinkStatus($propertyMetadata, $normalizationGroups, $denormalizationGroups);

src/Metadata/Property/PropertyMetadata.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ final class PropertyMetadata
3535
private $attributes;
3636
private $subresource;
3737
private $initializable;
38+
private $serializedName;
3839

39-
public function __construct(Type $type = null, string $description = null, bool $readable = null, bool $writable = null, bool $readableLink = null, bool $writableLink = null, bool $required = null, bool $identifier = null, string $iri = null, $childInherited = null, array $attributes = null, SubresourceMetadata $subresource = null, bool $initializable = null)
40+
public function __construct(Type $type = null, string $description = null, bool $readable = null, bool $writable = null, bool $readableLink = null, bool $writableLink = null, bool $required = null, bool $identifier = null, string $iri = null, $childInherited = null, array $attributes = null, SubresourceMetadata $subresource = null, bool $initializable = null, string $serializedName = null)
4041
{
4142
$this->type = $type;
4243
$this->description = $description;
@@ -51,6 +52,7 @@ public function __construct(Type $type = null, string $description = null, bool
5152
$this->attributes = $attributes;
5253
$this->subresource = $subresource;
5354
$this->initializable = $initializable;
55+
$this->serializedName = $serializedName;
5456
}
5557

5658
/**
@@ -343,4 +345,23 @@ public function withInitializable(bool $initializable): self
343345

344346
return $metadata;
345347
}
348+
349+
/**
350+
* Gets custom serialized name of this property.
351+
*/
352+
public function getSerializedName(): ?string
353+
{
354+
return $this->serializedName;
355+
}
356+
357+
/**
358+
* Returns a new instance with the given serialized name.
359+
*/
360+
public function withSerializedName(string $serializedName = null): self
361+
{
362+
$metadata = clone $this;
363+
$metadata->serializedName = $serializedName;
364+
365+
return $metadata;
366+
}
346367
}

src/Swagger/Serializer/DocumentationNormalizer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,7 @@ private function getLinkObject(string $resourceClass, string $operationId, strin
791791
continue;
792792
}
793793

794+
$propertyName = $propertyMetadata->getSerializedName() ?? $propertyName;
794795
$linkObject['parameters'][$propertyName] = sprintf('$response.body#/%s', $propertyName);
795796
$identifiers[] = $propertyName;
796797
}

0 commit comments

Comments
 (0)