标签: swagger-php

如何修复ErrorException:当@OA \ Property()类型为“数组”时,需要@OA \ Items()?

我试图添加任意类型的嵌套数组。这些是我的注释:

* @OA\Property(
*      @OA\Schema(
*          type="array",
*          @OA\Items(
*              type="array",
*              @OA\Items(type={})
*          )
*      ),
*      description="bla bla bla"
* )
Run Code Online (Sandbox Code Playgroud)

php swagger-php openapi

3
推荐指数
1
解决办法
1150
查看次数

Swagger OpenAPI 使用带有模式的对象而不是数组

我正在使用L5 SwaggerfromDarkOnLine使用 OpenApi 原理图生成 Swagger 文档。

使用模式我可以做

@OA\Property(property="certification", type="array", @OA\Items(ref="#/components/schemas/Certification"))
Run Code Online (Sandbox Code Playgroud)

它工作得很好,显示为

"certification": [
    {
      "certification_id": 0,
      "name": "string"
    }
  ],
Run Code Online (Sandbox Code Playgroud)

. 但是它创建了一个带有方括号的数组块,里面有多个对象。

如何使用相同的工作但丢失数组。就像是

@OA\Property(property="certification", type="object", @OA\Items(ref="#/components/schemas/Certification")),
Run Code Online (Sandbox Code Playgroud)

以便删除方括号并仅显示对象。

"certification": {
      "certification_id": 0,
      "name": "string"
 }
Run Code Online (Sandbox Code Playgroud)

swagger swagger-php openapi

3
推荐指数
1
解决办法
3257
查看次数

配置 Swagger UI 路由

我想使用 swagger 来记录 Laravel API 并让用户使用与petstore.swagger.io

swagger-php这是我使用&l5-swagger包所采取的步骤

  1. 作曲家需要 zircote/swagger-php
  2. 作曲家需要 darkaonline/l5-swagger
  3. 添加L5Swagger\L5SwaggerServiceProvider::class,到 config/app.php 文件
  4. 为 BookController 添加注释
  5. 运行命令php artisan l5-swagger:generate

然后我像这样向 BookController 添加注释

/**
 * @OA\Info(
 *      version="1.0.0",
 *      title="Laravel Test OpenApi",
 *      description="L5 Swagger OpenApi description",
 *      @OA\Contact(
 *          email="menadio1@gmail.com"
 *      ),
 *     @OA\License(
 *         name="Apache 2.0",
 *         url="http://www.apache.org/licenses/LICENSE-2.0.html"
 *     )
 * )
 */
/**
 *  @OA\Server(
 *      url=L5_SWAGGER_CONST_HOST,
 *      description="L5 Swagger OpenApi dynamic host server"
 *  )
 *
 *  @OA\Server(
* …
Run Code Online (Sandbox Code Playgroud)

php swagger swagger-php swagger-ui laravel-5.7

3
推荐指数
1
解决办法
1万
查看次数

在 Swagger 属性 (OAS3) 中设置带有 ids 的数组示例

我试图在 swagger (OAS3) 中指定以下 requestBody:

{
  "first_name": "John",
  "last_name": "Doe",
  "email": "user@example.com",
  "interest_ids": [
     1,2
  ]
}
Run Code Online (Sandbox Code Playgroud)

我目前已指定 requestBody 如下:

 *     @OA\RequestBody(
 *          required=true,
 *          @OA\JsonContent(
 *              required={"email"},
 *              @OA\Property(property="first_name", type="string", format="string", example="John"),
 *              @OA\Property(property="last_name", type="string", format="string", example="Doe"),
 *              @OA\Property(property="email", type="string", format="email", example="user@example.com"),
 *              @OA\Property(property="interest_ids", type="array", @OA\Items(
 *                      type="integer",
 *                      example=3
 *                  ),
 *              ),
 *          ),
 *     ),
Run Code Online (Sandbox Code Playgroud)

这给了我一个正确的 requestBody,但是这显然只给了我一个键,其值3作为interest_ids数组的示例值。如何在不将类型设置为字符串的情况下指定多个 id?我尝试了多种解决方案,例如将示例设置为example={1,2},不幸的是,这给了我数组中的另一个数组interest_ids

{
  "first_name": "John",
  "last_name": "Doe",
  "email": "user@example.com",
  "interest_ids": [
    [ …
Run Code Online (Sandbox Code Playgroud)

php swagger swagger-php openapi

3
推荐指数
1
解决办法
2681
查看次数

Swagger - “未找到所需的 @OA\Info()”

我刚刚进入 api 文档并尝试使用 Swagger

这是我的 php 文件,其中包含我想要记录的路由:

<?php

use OpenApi\Annotations as OA;

/**
 * @OA\Info(title="My First API", version="0.1")
 */
return [
    /**
     * @OA\Get(
     *     path="/api/v1/test",
     *     @OA\Response(response="200", description="An example resource")
     * )
     */
    'GET api/v1/test' => 'test/index',
];
Run Code Online (Sandbox Code Playgroud)

但是当我运行./vendor/bin/openapi api/config/routes.phpcli 时只输出错误:

Warning: Required @OA\Info() not found
Warning: Required @OA\PathItem() not found
openapi: 3.0.0
Run Code Online (Sandbox Code Playgroud)

然后我尝试了 Swagger2,效果很好

我使用dockerphp8.1镜像php:8.1-fpm-alpine、最新的zircote/swagger-php软件包和 Yii2 框架

php swagger-php openapi

3
推荐指数
1
解决办法
1万
查看次数

请求标头的 Swagger-php 注释

我正在使用 Slim 框架在 php 中创建一个 Restful api。使用 Swagger-php Annotations 来记录 api。如何注释 api 的请求标头?

swagger-php

2
推荐指数
1
解决办法
4132
查看次数

如何在 swagger-php 数组中上传文件

我想在 json requestBody 中的 swagger-php 中上传一个文件如何在 swagger anonations 的帮助下上传

从很多小时开始尝试但不走运如何在应用程序/ json数组中发送和文件,如果有关于此的任何信息,您能否提供帮助,那么我将解决我的问题我对此没有概念

当此代码在终端中生成时也没有任何错误并且未显示在 swagger ui 的请求正文中

/**
* @OA\Post(
*      path="/products/save",
*      tags={"Product"},
*      summary="Post bulk products",
*      description="Return bulk products",
*      @OA\RequestBody(
*       required=true,
*       description="Bulk products Body",
*       @OA\JsonContent(
*           @OA\Property(
*               property="products",
*               @OA\Items(
*                  @OA\Property(property="first_name", type="string"),
*                  @OA\Property(property="last_name", type="string"),
*                  @OA\Property(property="email", type="string"),
*                  @OA\Property(property="phone", type="string"),
*                  @OA\Property(property="resume", type="string", format="base64"),
*               ),
*           )
*       )
*     ),
* )
*/
Run Code Online (Sandbox Code Playgroud)

我想要这种类型的 swagger-ui 正文,以便用户可以填写属性并以 base64 格式添加简历

{
  "products": …
Run Code Online (Sandbox Code Playgroud)

laravel swagger-php

2
推荐指数
1
解决办法
2272
查看次数

如何在Swagger注释中使用PHP变量

首先,这个Swagger PHP非常令人兴奋,非常有表​​现力!

有什么办法可以在swagger批注中提供PHP变量。

下面是我的代码:

define('API_PATH', '/api/demo');

/**
 * @SWG\Swagger(
 * basePath="{API_PATH}",
 * host="11.7.11.16:xxxx",
 * schemes={"http"},
Run Code Online (Sandbox Code Playgroud)

尝试在注解中也给出类似$ api_path的内容,但将其作为字符串和API调用失败了...。

basePath="$api_path",
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激

swagger swagger-php swagger-2.0

1
推荐指数
1
解决办法
1107
查看次数

php swagger注释json属性中方括号的转义字符

我在 Php Laravel 中编写 API 并使用 swagger (2.0) 注释(lib:darkaonline/l5-swagger使用swagger-php)来生成 swagger.json,但是我有以下问题 - 当我输入时:

/**
 *
 * Space Schema
 *
 * @SWG\Get(
 *     path="/api/v1/client/space/schema",
 *     @SWG\Response( 
 *        response=200, 
 *        description="OK",
 *        @SWG\Property(property="result", type="json", example={ "aa": [ "bb", "cc" ] }  )
 *      )
 * )
Run Code Online (Sandbox Code Playgroud)

并尝试生成 swagger.json 我得到:

[Syntax Error] Expected PlainValue, got '[' in ...
Run Code Online (Sandbox Code Playgroud)

但是当我不使用方括号时,例如:

@SWG\Property(property="result", type="json", example={ "ee": "ff" })
Run Code Online (Sandbox Code Playgroud)

然后一切都很好。但是我需要使用方括号所以问题是:

[swagger注释中json字符串中(方括号)的转义字符是什么?

我还想补充一点,我的示例 json 非常大且复杂

php json annotations swagger-php swagger-2.0

1
推荐指数
1
解决办法
1448
查看次数

NelmioApiDocBundle v4.0.0-BETA1,未找到 $ref

我有一个这样的 DTO:

# AppBundle\DTO

/**
 * @OA\Schema(
 *      schema="ProductDto",
 *      type="object",
 *      required={
 *          "foo",
 *          "bar",
 *          "baz",
 *      },
 * )
 */
class ProductDto
{
    /**
     * @OA\Property(description="foo bar baz")
     * @var string|null
     */
    private $foo;

    ...
 }
Run Code Online (Sandbox Code Playgroud)

我试图在我的控制器中引用这个 DTO,但似乎这个文件没有被解析。

# AppBundle\Controller\Api\v1
class ProductController {

  ...

  /**
    * @OA\Post(
    *      @OA\RequestBody(
    *          required=true,
    *          content={
    *              @OA\MediaType(
    *                  mediaType="application/json",
    *                  @OA\Schema(
    *                      type="object",
    *                      ref="#/components/schemas/ProductDto",
    *                  ),
    *              ),
    *          }
    *      ),
    * )
    */
  public function …
Run Code Online (Sandbox Code Playgroud)

swagger-php nelmioapidocbundle openapi

1
推荐指数
1
解决办法
1694
查看次数

如何在 Swagger-PHP 中指定默认的 JSON 正文?

我想在 Swagger-PHP 中为 POST 请求指定默认的 JSON 正文。我的注释如下所示:

/**
 * Setup order
 *
 * @SWG\Post(
 *      path="/order/setup",
 *      operationId="setupOrder",
 *      tags={"Orders"},
 *      summary="Setup an order with status draft.",
 *      description="Setup an order with status draft",
 *      consumes={"application/json"},
 *      @SWG\Parameter(
 *          name="body",
 *          in="body",
 *          default="{}",
 *          description="Json order info body (customer and products info)",
 *          required=true,
 *          @SWG\Schema(type="string")
 *      ),
 *      @SWG\Response(
 *          response=200,
 *          description="successful operation"
 *       ),
 *       @SWG\Response(response=400, description="Bad request"),
 *       security={
 *           {"api_key_security_example": {}}
 *       }
 * …
Run Code Online (Sandbox Code Playgroud)

swagger swagger-php swagger-2.0

0
推荐指数
1
解决办法
5541
查看次数