Skip to content

[Bug]: RouteDescriber for new response #2529

@prugala

Description

@prugala

Version

v5.5.0

Description

I want to add response in documentation for all routes with my custom attribute. When I have single action with my attribute code works fine.
Problem occurs when I have more than one actions (separated classes).

Auth Warning: Multiple @OA\Response() with the same response="200":

<?php

final readonly class SuccessResponseRouteDescriber implements RouteDescriberInterface
{
    use RouteDescriberTrait;

    public function describe(OpenApi $api, Route $route, \ReflectionMethod $reflectionMethod): void
    {
        $attributes = $reflectionMethod->getDeclaringClass()->getAttributes(SuccessResponse::class);

        if (!$attributes) {
            return;
        }

        /** @var SuccessResponse $attribute */
        $attribute = $attributes[0]->newInstance();

        $model = new Model(type: $attribute->modelClass, groups: $attribute->groups);
        $response = new OA\Response(...);

        foreach ($this->getOperations($api, $route) as $operation) {
            $operation->merge([$response]);
        }
    }
}

I found related issue #1900 but solution as I see was for old version and used class for reset context does not exist.

JSON OpenApi

JSON OpenApi
Replace this text with your JSON (`bin/console nelmio:apidoc:dump`)

Additional context

No response

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