Skip to content

Response attribute must not be repeated error #31

@hansensalim

Description

@hansensalim

Hi, I have just upgraded to v1.0.2 from v0 and I'm unable to generate the API doc when there is multiple responses in a single controller method. My code looks like this:

#[OpenApi\Operation(id: 'invitationAccept', tags: ['Invitation'])]
#[OpenApi\Parameters(factory: DefaultHeaderParameters::class)]
#[OpenApi\Response(factory: SuccessResponse::class, statusCode: 200)]
#[OpenApi\Response(factory: BadRequestResponse::class, statusCode: 400)]
public function accept(Invitation $invitation)
{
   ...
}

And I get this error when running the openapi:generate command:

  Attribute "Vyuldashev\LaravelOpenApi\Attributes\Response" must not be repeated

  at vendor/vyuldashev/laravel-openapi/src/RouteInformation.php:84
     80▕             $controllerAttributes = collect($reflectionClass->getAttributes())
     81▕                 ->map(fn(ReflectionAttribute $attribute) => $attribute->newInstance());
     82▕ 
     83▕             $actionAttributes = collect($reflectionMethod->getAttributes())
  ➜  84▕                 ->map(fn(ReflectionAttribute $attribute) => $attribute->newInstance());
     85▕ 
     86▕             $instance->domain = $route->domain();
     87▕             $instance->method = $method;
     88▕             $instance->uri = Str::start($route->uri(), '/');

      +4 vendor frames 
  5   [internal]:0
      Vyuldashev\LaravelOpenApi\Builders\PathsBuilder::Vyuldashev\LaravelOpenApi\Builders\{closure}()

      +18 vendor frames 
  24  artisan:37
      Illuminate\Foundation\Console\Kernel::handle()

My current project is on PHP 8.0, Laravel 8, laravel-openapi 1.0.2. I haven't tested this issue on a fresh laravel installation yet.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions