2017-10-05 43 views
1

我使用以下版本:使用外部定義中揚鞭/ Zircote/Nelmio-API文檔

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) 

這是型號/定義我想用我的控制器在我的控制器,操作:

<?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 /文檔,我看到這個錯誤:

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

我認出了接下來的事情: 我product.php似乎並沒有被swagger在所有閱讀。我可以在這裏寫任何我想要的東西。沒有錯誤,即使我拼錯了一些東西。這使我得出結論,我的product.php根本沒有找到swagger

我對每一個提示都很有幫助。

親切的問候, 最大

回答

0

,我發現這個問題的解決方案。我需要使用其完整名稱空間加載外部定義,如下所示:

/** 
    * @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)