[英]Where to put @SWG\Definition to be reused with Swagger-PHP and Nelmio API-DOC Bundle
[英]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.