2

我正在使用 Symfony 4 和NelmioApiDocBundle作为 API。

我有捆绑包设置和工作,但我试图apiKey在默认情况下在所有端点中要求一个标头。

我已经按照文档进行操作,但我看不到TEST-KEY我运行时try it out的标题/api/docs- 我做错了什么?

nelmio_api_doc.yml

nelmio_api_doc:
    documentation:
        info:
            title: Test API
            description: Test API
            version: 1.0.0
        securityDefinitions:
            apiKey:
                type: apiKey
                description: 'My test authentication key'
                name: TEST-KEY
                in: header
        security:
            - apiKey: []
    areas:
        path_patterns:
            - ^/api(?!/doc$)

应用\控制器\TestController.php

    /**
     * @Operation(
     *     tags={"Test API"},
     *     produces={"application/json"},
     *     summary="Get a list of all...",
     *     @SWG\Parameter(
     *         name="start",
     *         in="query",
     *         description="Offset...",
     *         required=false,
     *         type="integer",
     *         default="0"
     *     ),
     *     @SWG\Parameter(
     *         name="limit",
     *         in="query",
     *         description="Limit...",
     *         required=false,
     *         type="integer"
     *     ),
     *     @SWG\Response(
     *         response="200",
     *         description="Returned when successful"
     *     )
     * )
     *
     * @Security(name="apiKey")
     *
     * @param Request $request
     * @return JsonResponse
     */
    public function getTestAction(Request $request)
    {
        $start = $request->get('start');
        $limit = $request->get('limit');

        $data = [];

        return new JsonResponse($data, 200);
    }

我也尝试过这种方法,但也没有运气:

    /**
     * @Operation(
     *     tags={"Test API"},
     *     produces={"application/json"},
     *     summary="Get a list of all...",
     *     security={
     *         {"apiKey"}
     *     },
     *     @SWG\Parameter(
     *         name="start",
     *         in="query",
     *         description="Offset...",
     *         required=false,
     *         type="integer",
     *         default="0"
     *     ),
4

0 回答 0