【问题标题】:Laravel Swagger PHP Couldn't find constant arrayLaravel Swagger PHP 找不到常量数组
【发布时间】:2020-10-02 04:13:01
【问题描述】:
  • darkaonline/l5-swagger: 8.0.2
  • PHP 版本:7.3.13
  • zircote/swagger-php: 3.1.0
  • 操作系统:Windows

我创建了一个Contract ref 对象。 现在在我的ContractController 我想列出一系列合同。 我该怎么做? 尝试在OA\Items 中添加type=array 时出现此错误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;
}

【问题讨论】:

    标签: laravel swagger-php


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-13
      • 2013-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多