core icon indicating copy to clipboard operation
core copied to clipboard

[OpenAPI] Allow using (more) objects instead of arrays in openapiContext

Open JarJak opened this issue 1 year ago • 9 comments

Description

Hello! I'm in the middle of transforming my old API to the API Platform one.

One thing I noticed is that when changing OpenAPI attributes to Api Platform attributes I can no longer use item references as class names or generally OpenAPI/Nelmio Model objects deeper under openapiContext property.

Am I missing something to make it work properly or is this feature not implemented yet?

Example
My old attribute:

use OpenApi\Attributes as OA;
use Nelmio\ApiDocBundle\Annotation\Model;

    #[OA\Property(
        description: 'the list of order items',
        type: 'array',
        items: new OA\Items(
            ref: new Model(type: OrderItem::class),
        )
    )]
    public array $items;

The new one:

    #[ApiProperty(
        description: 'the list of order items',
        openapiContext: [
            'type' => 'array',
            'items' => [
                '$ref' => '#/components/schemas/OrderItem'
            ],
        ],
    )]
    public array $items;

JarJak avatar Feb 21 '24 11:02 JarJak

I wish it'd be something like:

#[ApiProperty(openapi: new Schema)]

from where do use OpenApi\Attributes as OA; come from?

soyuka avatar Mar 05 '24 10:03 soyuka

@soyuka they come from https://github.com/zircote/swagger-php through https://github.com/nelmio/NelmioApiDocBundle

JarJak avatar Mar 05 '24 14:03 JarJak

Sorry we're not compatible with swagger-php for now it's not supported, marking this as an enhancement.

soyuka avatar Mar 15 '24 10:03 soyuka