Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to work with discriminator? #1637

Open
sawilde opened this issue Aug 5, 2024 · 0 comments
Open

How to work with discriminator? #1637

sawilde opened this issue Aug 5, 2024 · 0 comments

Comments

@sawilde
Copy link

sawilde commented Aug 5, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant