skip to Main Content
  • darkaonline/l5-swagger: 8.0.2
  • PHP Version: 7.3.13
  • zircote/swagger-php: 3.1.0
  • OS: Windows

I created a Contract ref object.
Now in my ContractController I want to list an array of contracts.
How can I do it?
I got this error Couldn't find constant array when trying to add type=array in OAItems

/**
 * @OAInfo(title="Contract API", version="1")
 */

class ContractController extends Controller
{
    /**
     * @OAPost(
     *     path="/api/v1/contract/list",
     *     tags={"contact"},
     *     summary="List Contract",
     *     operationId="list",
     *     @OAParameter(
     *         name="keyword",
     *         in="path",
     *         description="keyword to search contracts",
     *         required=false,
     *         @OASchema(
     *             type="string"
     *         )
     *     ),
     *     @OAParameter(
     *         name="lang_code",
     *         in="path",
     *         description="lang_code define language client used",
     *         required=false,
     *         @OASchema(
     *             type="string",
     *         )
     *     ),
     *     @OAResponse(
     *         response=200,
     *         description="successful",
     *         @OAJsonContent(
     *              @OAItems(
     *                  type=array, #This is where I got the error
     *                  ref="#/components/schemas/Contract"
     *              )
     *         )
     *     ),
     *     @OAResponse(
     *         response=400,
     *         description="Wrong"
     *     )
     * )
     */
    public function list(Request $request)
    {
        $contracts = Contract::factory()->count(10)->make();
        return response()->json([
            'message' => 'good',
            'contracts' => $contracts
        ], 200);
    }
}
/**
 * @OASchema(
 *     description="Contract model",
 *     type="object",
 *     title="Contract model"
 * )
 */
class Contract extends Model
{
    use HasFactory;

    /**
     * The unique identifier of a product in our catalog.
     *
     * @var integer
     * @OAProperty(format="int64", example=1)
     */
    public $id;

    /**
     * @var string
     * @OAProperty(format="string", example="contract 001")
     */
    public $contract_title;
}

2

Answers


  1. Use type="array", (with "s) instead of type=array,

    Login or Signup to reply.
  2. I know its late but
    Try to use

     *            @OAMediaType(
     *                 mediaType="application/json",
     *                 @OASchema(
     *                 type="array",
     *                      @OAItems(
     *                          ref="#/components/schemas/Contract"
     *                      ),
     *                 )
     *          )  
    

    Insead of @OAJsonContent

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search