swagger-php icon indicating copy to clipboard operation
swagger-php copied to clipboard

How to work with discriminator?

Open sawilde opened this issue 6 months ago • 0 comments

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?

sawilde avatar Aug 05 '24 06:08 sawilde