API Platform: How to add OpenAPI documentation at the field level
23 February 2024 (Updated 23 February 2024)
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiProperty;
use Symfony\Component\Serializer\Annotation\Groups;
#[ApiResource(
normalizationContext: ['groups' => ['read']],
denormalizationContext: ['groups' => ['write']]
)]
class Product
{
#[ApiProperty(
description: "The unique identifier of the product.",
example: "123",
openapiContext: [
'type' => 'integer',
'description' => 'Unique identifier of the product.',
]
)]
#[Groups(['read'])]
private $id;
#[ApiProperty(
description: "The name of the product.",
example: "A fancy Product",
openapiContext: [
'type' => 'string',
'description' => 'Name of the product.',
]
)]
#[Groups(['read', 'write'])]
private $name;
}
Tagged:
API Platform
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment