首页 > 解决方案 > 缺少 Swagger/api 文档的参数

问题描述

在我的 symfony 项目 4.1 上将 nelmio api doc 从 3.0 更新到 3.1/3.3 时出现问题。我无法访问可以在请求中发送到 API 服务的参数,我不明白。不管是用$request->attributes->all()、$request->query->all()还是$request->request->all(),我从来没有我的参数,但是在3.0版本中,它可以工作

我尝试清除缓存,更改参数类型,它不起作用:(

我的 symfony 项目中的 nelmio api doc 包有这个配置

nelmio_api_doc:
documentation:
    info:
        title: Project
        description: description
        version: 1.0.0
    securityDefinitions:
       api_key:
           type: apiKey
           description: Json Web Token
           name: Authorization
           in: header
    security:
        - api_key: []
models: { use_jms: true }

我的控制器中的示例注释:

@SWG\Parameter(
 *         name="email",
 *         in="formData",
 *         description="The user email",
 *         required=true,
 *         type="string"
 *     ),
 *     @SWG\Parameter(
 *         name="password",
 *         in="formData",
 *         description="The user password",
 *         required=true,
 *         type="string"
 *     ),

请问有人有解决办法吗?谢谢 !

标签: symfonyparametersswaggerapi-doc

解决方案


你可以试试这个注释:

/**
 * @SWG\Post(
 *     path="/api/path",
 *     summary="Post to URL",
 *     @SWG\Parameter(
 *          name="body",
 *          in="body",
 *          required=true,
 *          @SWG\Schema(
 *              @SWG\Property(
 *                  property="email",
 *                  type="string"
 *              ),
 *              @SWG\Property(
 *                  property="password",
 *                  type="string"
 *              )
 *          )
 *     )
 *   )
 */

推荐阅读