swagger-php
swagger-php copied to clipboard
How to work with discriminator?
We are using a discriminator to model two types of inputs into our API using something like the following in an annotation
use Nelmio\ApiDocBundle\Annotation\Model;
use OpenApi\Attributes as OA;
...
#[ ...
new OA\Property(
property: 'data',
discriminator: new OA\Discriminator(
propertyName: 'type',
mapping: [
'thingA' => '#/components/schemas/ThingADto',
'thingB' => '#/components/schemas/ThingBDto',
]
),
oneOf: [
new OA\Schema(new Model(type: ThingADto::class)),
new OA\Schema(new Model(type: ThingBDto::class)),
]
),
...
]
public function thingy(...){ ... }
Is there a way to programmatically generate the ref strings used in mapping ie '#/components/schemas/ThingADtoDto'
, rather than having to hand roll them?