繁体   English   中英

在Swagger / Zircote / Nelmio-api-doc中使用外部定义

[英]using external Definitions in Swagger / Zircote / Nelmio-api-doc

我使用以下版本:

zircote/swagger-php in version 2.0.10
nelmio/api-doc-bundle in version v3.0.0-BETA4

一键操作我的控制器

    /**
     * @Operation(
     *     tags={"DeliverySlip"},
     *     summary="Send information after deliveryItems are processed and deliverySlip was scanned",
     *     @SWG\Response(
     *         response="200",
     *         description="Returned when successful"
     *     ),
     *     @SWG\Response(
     *         response="400",
     *         description="Returned on a missing request parameter"
     *     ),
     *     @SWG\Response(
     *         response="500",
     *         description="Returned on any other error"
     *     ),
     *     @SWG\Parameter(
     *        name="slipIdentifier",
     *        description="identifier of delivery slip",
     *        type="string",
     *        format="string",
     *        in="path"
     *     ),
     *     @SWG\Parameter(
     *        name="JSON update body",
     *        in="body",
     *        description="json login request object",
     *        required=true,
     *        @SWG\Schema(ref="#/definitions/product")
     *     )
     * )
     *
     * @Put("/deliveryslip/update/{slipIdentifier}", requirements={"slipIdentifier" = "\w+"})
     *
     * @param string $slipIdentifier
     * @param Request $request
     * @return JsonResponse
     */
    public function updateDeliverySlipAction($slipIdentifier, Request $request)

这是我要在Controller-Action中使用的Model / Definition:

<?php

namespace Sendis\Presentation\RestBundle\Model;

use Swagger\Annotations as SWG;

/**
 * @SWG\Definition(
 *     definition="product",
 *     type="object",
 *     required={"name"}
 * )
 */
class Product
{
    /**
     * @SWG\Property(example="doggie")
     * @var string
     */
    public $name;
}

但是,当我转到/ api / doc的文档页面时,会看到此错误:

Errors
Resolver error at paths./api/deliveryslip/update/{slipIdentifier}.put.parameters.1.schema.$ref
Could not resolve reference: #/definitions/product

接下来的事情我承认:我product.php似乎并没有被阅读swagger的。 我可以在这里写任何我想要的东西。 没有错误,即使我拼错了一些。 这使我得出一个结论,那就是swagger根本找不到我的product.php

我对每一个提示都有帮助。

亲切的问候,马克斯

我找到了解决此问题的方法。 我需要用其完整的名称空间加载外部定义,如下所示:

/**
     * @SWG\Put(
     *     path="/deliveryslip/update/{slipIdentifier}",
     *     tags={"DeliverySlip"},
     *     summary="Send information after deliveryItems are processed and deliverySlip was scanned",
     *     @SWG\Definition(
     *        definition="product",
     *        type="object",
     *        required={"name"}
     *     ),
     *     @SWG\Response(
     *         response="200",
     *         description="Returned when successful"
     *     ),
     *     @SWG\Response(
     *         response="400",
     *         description="Returned on a missing request parameter"
     *     ),
     *     @SWG\Response(
     *         response="500",
     *         description="Returned on any other error"
     *     ),
     *     @SWG\Parameter(
     *        name="slipIdentifier",
     *        description="identifier of delivery slip",
     *        type="string",
     *        format="string",
     *        in="path"
     *     ),
     *     @SWG\Parameter(
     *        name="JSON update body",
     *        in="body",
     *        description="json login request object",
     *        required=true,
     *        @SWG\Schema(
     *         type="array",
     *         @Model(type=Sendis\Presentation\RestBundle\Model\Product::class)
     *     )
     *     )
     * )
     *
     * @param string $slipIdentifier
     * @param Request $request
     * @return JsonResponse
     */
    public function updateDeliverySlipAction($slipIdentifier, Request $request)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM