Skip to content

Set security on an Operation will be wrong converted in yaml / json #5625

@kswzr

Description

@kswzr

API Platform version(s) affected: 3.1.12

Description
Setting the security property on an Path Operation, will be wrong converted in a json / yaml. The output is an invalid openapi specification.

How to reproduce

#[ApiResource(
    operations: [
        new Get(
            uriTemplate: '/currencies/{id}',
            openapi: new Operation(
                operationId: 'getCurrency',
                summary: 'Get a currency',
                security: [
                    'JWT' => ['CURRENCY_READ']
                ]
            ),
            security: 'is_granted("CURRENCY_READ", object)',
            name: 'getCurrency',
        )
    ],
    normalizationContext: ['groups' => [self::READ]],
)]

Given output in yaml:
Bildschirmfoto 2023-06-10 um 14 16 10

Possible Solution
I've already tried some solutions, but got in stuck with the OpenApiNormalizer and their cleanup method.
Here is a solution, how it is solved in Zircote's Openapi implementation: https://github.com/zircote/swagger-php/blob/9e009264d4ec92193934ac0abf6015cb3f908b04/src/Annotations/Operation.php#L203

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions