core icon indicating copy to clipboard operation
core copied to clipboard

OpenAPI: customize and replace responses

Open Cruiser13 opened this issue 3 years ago • 1 comments

API Platform version(s) affected: 2.6.6

Description
Default responses can not be overriden with new response information.

How to reproduce
Create a new Entity SipAccount with this data:

#[ApiResource(
    itemOperations: [
        'get',
        'put',
        'patch',
        'delete',
        'post_initiatecall' => [
            'method' => 'POST',
            'path' => '/sip_accounts/{uuid}/initiatecall',
            'controller' => SipAccountInitiateCallAction::class,
                'responses' => [
                    '200' => [
                        'description' => 'Call has been initiated'
                    ],
                    '400' => [
                        'description' => 'Call can not be initiated'
                    ]
                ]
            ]
        ],
    ]
    )
]
class SipAccount
{
...
}

Additional Context
It should display 200 and 400 as the only responses. But it shows them additionally to the default responses: sip-account-responses

Cruiser13 avatar Nov 02 '21 15:11 Cruiser13

+1.

Some additional thoughts: it is not possible to override content and mimetype and so on.

Here is another example:

...
            "openapi_context" => [
                "summary" => "Retrieves user file...",
                "description" => "Retrieves file...",
                "responses" => [
                    "200" => [
                        "description" => "Retrieves file...",
                        "content" => [
                            "text/*" => [
                                "schema" => [
                                    "type" => "string",
                                    "format" => "binary"
                                ]
                            ]
                        ]
                    ]
                ]
            ],

But swagger UI shows default 200 — Some Resource. Even if dummy context is specified, like "normalization_context" => ["groups" => "nothing"],

KSDaemon avatar Nov 24 '21 23:11 KSDaemon

@soyuka has this been fixed (if yes a commit or version info would be great) or do you need further information to confirm the behaviour?

Cruiser13 avatar Nov 08 '22 11:11 Cruiser13

Is it still not possible to remove an response? I am running into this issue where I override the POST to verify that a 2fa token is valid.

#[ApiResource(
    operations: [
        new Post(
            uriTemplate: '/email-verify',
            openapi: new OpenApiOperation(
                tags: ['Sign up'],
                responses: [
                    201 => null, // <-- This should be hidden, but appears as "UserEmailVerificationToken resource created"
                    204 => new Model\Response(
                        description: 'Verification was successful.',
                    ),
                    400 => new Model\Response(
                        description: 'Verification was not successful.',
                    ),
                ],
                summary: 'Verify an user email by token.',
                description: 'Verify an user email by token.',
            ),
            validationContext: ['groups' => ['2fa:email-verify']],
            output: JsonResponse::class,
            processor: UserEmailVerificationProcessor::class,
        ),
    ],
)]
class UserEmailVerificationToken {
// ...
}

thedomeffm avatar Oct 15 '23 19:10 thedomeffm