Laravel Swagger PHP找不到常量数组

r1zhe5dt  于 2023-01-10  发布在  PHP
关注(0)|答案(2)|浏览(165)
  • 深色/l5-摆动:8.0.2
  • PHP版本:7.3.13
  • 氧化锆/摇摆-PHP:3.1.0
  • 操作系统:Windows

我创建了一个Contract ref对象。现在我想在我的ContractController中列出一个契约数组。我该怎么做呢?我在尝试将type=array添加到OA\Items中时收到了Couldn't find constant array错误

/**
 * @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;
}
4xrmg8kj

4xrmg8kj1#

使用type="array",(带有" s)代替type=array,

wfveoks0

wfveoks02#

我知道现在很晚了但是试着用

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

@OA\JsonContent学院

相关问题