php - Swagger 的 laravel 护照不起作用

标签 php laravel swagger swagger-php

我想将 swagger 与 laravel passport 连接起来。我的 swagger 配置文件设置

'passport' => [ // Unique name of security
            'type' => 'oauth2', // The type of the security scheme. Valid values are "basic", "apiKey" or "oauth2".
            'description' => 'Laravel passport oauth2 security.',
            'in' => 'header',
            'scheme' => 'https',
            'flows' => [
                "password" => [
                    "authorizationUrl" => config('app.url') . '/oauth/authorize',
                    "tokenUrl" => config('app.url') . '/oauth/token',
                    "refreshUrl" => config('app.url') . '/token/refresh',
                    "scopes" => []
                ],
            ],
        ],

在我使用注释的 laravel Controller 中

/**
     * @OA\Post(
     *     path="/beauty/list-customer-service-bookings",
     *     tags={"beauty_customer_bookings"},
     *     summary="List Customer Bookings.",
     *     operationId="Beauty_Customer_Bookings",
     *     security={{"passport": {}}},
     * @OA\SecurityScheme(
     *    securityScheme="https",
     *    type="oauth2",
     *    in="header",
     *    name="api_key"
     * ),
     *
     *     @OA\Parameter(
     *         name="customer_id",
     *         in="query",
     *         description="customer id",
     *         required=true,
     *         @OA\Schema(
     *             type="integer",
     *             default="482"
     *         )
     *     ),
     *     @OA\Response(
     *         response=422,
     *         description="validation errors."
     *     ),
     *     @OA\Response(
     *          response="200",
     *          description="Customer Bookings."
     *     ),
     *     @OA\Response(
     *          response="401",
     *          description="auth failed."
     *     ),
     *     @OA\Response(
     *          response="404",
     *          description="Page not found."
     *     ),
     * )
     */

它没有发送它应该发送的 header 。我做错了什么或缺少什么吗?我需要 this 的解决方案但在 Laravel 中带有 swagger OA 3

最佳答案

  • 你好 friend ,你只需要添加魔法参数
    示例:
    security={ 
       {"passport": {}}, 
     },
  • 在您的 swagger 评论中,这样当您输入有效的身份验证凭据和护照 key 时,curl 会生成护照 token 。

谢谢。

关于php - Swagger 的 laravel 护照不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60182833/

相关文章:

dictionary - Swagger HashMap 属性类型

php - 加盐密码?

php - 如何使用 .htaccess 将非 www 重定向到 www? (还有两个问题……)

Laravel 如何下载目录中的所有文件

php - 通过浏览器访问 IP 地址时,在 nginx 上创建新的 Lumen 应用程序会抛出 404

java - 使用 PUT 请求 Java 将文本文件上传到 Swagger

php - SQL查询在php函数中失败

php - SQLSTATE[HY000] [1698]-Laravel-6.5.1

php - 数组到字符串的转换,即使 Laravel Lighthouse 中存在类型提示

javascript - 在 Node js Express 中解析 req.body 中的数组