DarkaOnLine / L5-Swagger

OpenApi or Swagger integration to Laravel
https://github.com/DarkaOnLine/L5-Swagger
MIT License
2.66k stars 397 forks source link

Ref "#/components/schemas/" not found for @OA\Items() #616

Open ridzria opened 3 months ago

ridzria commented 3 months ago

Description:

I am trying to attach the Schema from the controller but it doesn't work.

Steps To Reproduce:

Model: Actors.php

/**
 * @OA\Schema(
 *     schema="Actor",
 *     type="object",
 *     title="Actor",
 *     description="Actor Type Model",
 *     @OA\Property(
 *         property="id",
 *         type="integer",
 *         description="Unique identifier for the actor type"
 *     ),
 *     @OA\Property(
 *         property="name",
 *         type="string",
 *         description="Name of the actor type"
 *     )
 * )
 */
class Actor extends Model
{
    use HasFactory;

    protected $fillable = [
        'name',
    ];

    public function organization(): BelongsTo
    {
        return $this->belongsTo(Organization::class);
    }
}

Controller: ActorController.php

/**
     * @OA\Get(
     *     path="/business",
     *     tags={"Business"},
     *     summary="Get all Business",
     *     description="List of all the Business Types",
     *     operationId="getBusinessTypes",
     *     @OA\Response(
     *         response=200,
     *         description="A list of business types",
     *         @OA\JsonContent(
     *             type="array",
     *             @OA\Items(ref="#/components/schemas/Actor")
     *         )
     *     ),
     *     @OA\Response(
     *         response=401,
     *         description="Unauthorized"
     *     ),
     *     security={{"bearerAuth":{}}}
     * )
     */

    public function index()
    {
        $actors = Actor::all();
        return response()->json(ActorTypeResource::collection($actors));
    }

When I generate the swagger, I get the following error.

$ref "#/components/schemas/" not found for @OA\Items() in \App\Http\Controllers\ActorController->index()

  at vendor/zircote/swagger-php/src/Loggers/DefaultLogger.php:31
     27▕         } else {
     28▕             $error_level = E_USER_WARNING;
     29▕         }
     30▕ 
  ➜  31▕         trigger_error($message, $error_level);
     32▕     }
     33▕ }
     34▕ 

If I replace the @OA\Items(ref="#/components/schemas/Actor") it generates but throws error in the Swagger UI.

Resolver error at paths./actor.get.responses.200.content.application/json.schema.items.$ref
Could not resolve reference: undefined The route components/schemas/Actor could not be found.

So how to fix this?

mohammadkamil commented 3 months ago

i got same error

Aggeloudis commented 1 month ago

Same here.