1
  • 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 OA\Items

/**
 * @OA\Info(title="Contract API", version="1")
 */

class ContractController extends Controller
{
    /**
     * @OA\Post(
     *     path="/api/v1/contract/list",
     *     tags={"contact"},
     *     summary="List Contract",
     *     operationId="list",
     *     @OA\Parameter(
     *         name="keyword",
     *         in="path",
     *         description="keyword to search contracts",
     *         required=false,
     *         @OA\Schema(
     *             type="string"
     *         )
     *     ),
     *     @OA\Parameter(
     *         name="lang_code",
     *         in="path",
     *         description="lang_code define language client used",
     *         required=false,
     *         @OA\Schema(
     *             type="string",
     *         )
     *     ),
     *     @OA\Response(
     *         response=200,
     *         description="successful",
     *         @OA\JsonContent(
     *              @OA\Items(
     *                  type=array, #This is where I got the error
     *                  ref="#/components/schemas/Contract"
     *              )
     *         )
     *     ),
     *     @OA\Response(
     *         response=400,
     *         description="Wrong"
     *     )
     * )
     */
    public function list(Request $request)
    {
        $contracts = Contract::factory()->count(10)->make();
        return response()->json([
            'message' => 'good',
            'contracts' => $contracts
        ], 200);
    }
}
/**
 * @OA\Schema(
 *     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
     * @OA\Property(format="int64", example=1)
     */
    public $id;

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

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

I know its late but Try to use

 *            @OA\MediaType(
 *                 mediaType="application/json",
 *                 @OA\Schema(
 *                 type="array",
 *                      @OA\Items(
 *                          ref="#/components/schemas/Contract"
 *                      ),
 *                 )
 *          )  

Insead of @OA\JsonContent

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.