Closed deluxetom closed 2 months ago
There is currently no real way to "translate" the Model
attribute to a reference string for your example. In the meantime you should be able to do this by manually defining reference like so:
#[ApiDoc\Schema(
title: 'Unlock',
type: 'object',
discriminator: new ApiDoc\Discriminator(propertyName: 'discriminator', mapping: [
self::DISCRIMINATOR_FREE_TRIAL_LOW_LATENCY => '#/components/schemas/UnlockFreeTrialLowLatency',
self::DISCRIMINATOR_FREE_TRIAL_SOURCE => '#/components/schemas/UnlockFreeTrialSource',
self::DISCRIMINATOR_PM_MEDIA => '#/components/schemas/UnlockPmMedia',
self::DISCRIMINATOR_POST => '#/components/schemas/UnlockPost',
self::DISCRIMINATOR_SOCIAL => '#/components/schemas/UnlockSocial',
self::DISCRIMINATOR_SUB_CLUB => '#/components/schemas/UnlockSubClub',
self::DISCRIMINATOR_GIFT => '#/components/schemas/UnlockGift',
self::DISCRIMINATOR_CLIP => '#/components/schemas/UnlockClip',
]),
oneOf: [
new ApiDoc\Schema(ref: new Model(type: UnlockFreeTrialLowLatency::class)),
new ApiDoc\Schema(ref: new Model(type: UnlockFreeTrialSource::class)),
new ApiDoc\Schema(ref: new Model(type: UnlockPmMedia::class)),
new ApiDoc\Schema(ref: new Model(type: UnlockPost::class)),
new ApiDoc\Schema(ref: new Model(type: UnlockSocial::class)),
new ApiDoc\Schema(ref: new Model(type: UnlockSubClub::class)),
new ApiDoc\Schema(ref: new Model(type: UnlockGift::class)),
new ApiDoc\Schema(ref: new Model(type: UnlockClip::class)),
],
)]
Thanks @DjordyKoert, that's actually what I ended up doing for now
Version
4.25.2
Question
I was trying to define the discriminator manually but I cant get it to work:
I end up with this:
and when I try this one:
the result is:
I'm trying to generate this:
any idea how I can achieve this?
Additional context
I tried using the JMS
DiscriminatorMap
but when I set the field name to the virtual property returning the discriminator, I get an error that it's a duplicate (the DB field name is different)any help would be appreciated, thank you!