You can declare multiple #[OpenApi\Response] attributes on a single controller method to represent different outcomes (e.g., 201 Created, 401 Unauthorized, 422 Unprocessable Entity).
Important: Even if your response factory's build() method defines a status code, you must explicitly provide the statusCode parameter in the #[OpenApi\Response] attribute in your controller. If you omit the statusCode in the attribute, only one response will be included in the final OpenAPI result.
use Vyuldashev\\LaravelOpenApi\\Attributes as OpenApi;
class UserController extends Controller
{
/**
* Create user.
*/
#[OpenApi\Response(factory: CreatedUserResponse::class, statusCode: 201)]
#[OpenApi\Response(factory: ErrorUnauthenticatedResponse::class, statusCode: 401)]
#[OpenApi\Response(factory: ErrorForbiddenResponse::class, statusCode: 403)]
#[OpenApi\Response(factory: ErrorNotFoundResponse::class, statusCode: 404)]
#[OpenApi\Response(factory: ErrorValidationResponse::class, statusCode: 422)]
public function store(Request $request)
{
//
}
}