Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ridzria opened this issue Aug 6, 2024 · 2 comments
Open

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

ridzria opened this issue Aug 6, 2024 · 2 comments

Comments

@ridzria
Copy link

ridzria commented Aug 6, 2024

  • L5-Swagger Version: 8.6.0 (composer show | grep l5-swagger)
  • PHP Version (php -v): 8.3.0
  • OS: MacOS

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
Copy link

i got same error

@Aggeloudis
Copy link

Same here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants