# Resource Polymorphism Since API Platform 5.1, a resource can expose several subtypes. The subtypes are declared in a [Symfony Serializer `#[DiscriminatorMap]`](https://symfony.com/doc/current/serializer.html#serializing-interfaces-and-abstract-classes) on the resource class. API Platform then reads, writes and documents the properties of each subtype on the endpoints of the resource. ## Enabling Polymorphism Polymorphism is off by default. Enable it with the `discriminator_map` option. ```yaml # api/config/packages/api_platform.yaml api_platform: serializer: discriminator_map: true ``` ```php [ 'discriminator_map' => true, ], ]; ``` ## Declaring the Subtypes Declare the `#[DiscriminatorMap]` on the resource. API Platform only reads the map you declare: it does not derive subtypes from the Doctrine inheritance mapping. ```php Car::class, 'truck' => Truck::class, ])] abstract class Vehicle { public ?int $id = null; public string $name = ''; } ``` ```php [!WARNING] > Operations, and therefore their `security` expressions, are taken from the root resource only. A > subtype does not get its own security. The operation that handles a request is the one matching the URL. On the endpoints of the root resource (`/vehicles`), `security`, `securityPostDenormalize` and the other operation options of the root apply to every subtype. A subtype that you also declare as a resource has its own operations, but they only apply on its own endpoints: a `PATCH /vehicles/6` on a bus still uses the operations of `Vehicle`, not the ones of `Bus`. Restrict the root operations accordingly, and do not rely on a subtype `security` option to protect data on the root endpoints. [Property-level `security`](security.md) declared with `#[ApiProperty(security: ...)]` on a subtype property is applied for each user: ```php