如何在Swagger中为GET请求生成模型/示例值部分

Ban*_*dan 4 swagger swagger-php

我担心使用Swagger为我的GET请求生成Model/Example值部分. 官方示例的链接显示该部分完美.

在官方文档中,它是使用现有模型生成的:

     *     @SWG\Schema(ref="#/definitions/User")
Run Code Online (Sandbox Code Playgroud)

我没有这样的选项,因为我的属性是由REST生成的.

我尝试过以下方式:

/**
 * @SWG\Get(
...
 *     @SWG\Response(
 *         response="200",
 *         description="Ok",
 *         @SWG\Schema(
 *             type="array",
 *             @SWG\Property(property="firstname", type="string", example="Steven")
 *         ),
 *     ),
 * )
 */
Run Code Online (Sandbox Code Playgroud)

它没有工作和答案:

fetching resource list: http://localhost/dist/swagger.json; Please wait.

任何帮助都非常感谢.提前致谢.

Bob*_*ger 5

GET /pet/findByStatus是在一个例子中生成的:
github.com/zircote/swagger-php/.../Examples/petstore.swagger.io/controllers/PetController.php

您的代码段不起作用的原因是您要向某个array类型添加属性,但不支持该属性.

要描述数组的内容,您需要@SWG\Items注释:

...
 *         @SWG\Schema(
 *             type="array",
 *             @SWG\Items(
 *                 type="object",
 *                 @SWG\Property(property="firstname", type="string", example="Steven")
 *             )
 *         ),
...
Run Code Online (Sandbox Code Playgroud)