2016-05-20 18 views
2

私はSwagger PHPを使用していますが、定義の大部分は簡単に定義できますが、別のクラスの一部ではなく連想配列の一部である特定のデータに問題があります。Swagger PHP - ネストされたプロパティを定義する方法は?

私が表示したいJSONレスポンスが(この質問のために簡略化):それを定義するために何の別々のクラスが存在しないよう

{ 
"id": 1, 
"status": "published", 
"gps": { 
    "lat": "0.00000000", 
    "lng": "0.00000000" 
} 

idstatusを定義するのは簡単です、しかしgpsは問題がありますそれはモデル内の配列です。ダミークラスを作成せずにこの配列を定義することは可能ですか?

現在のモデルファイルのコメント:

/** 
* @SWG\Definition(@SWG\Xml(name="Event")) 
*/ 
class Event extends BaseModel { 
    /** 
    * @SWG\Property(
    *  property="id", 
    *  type="integer", 
    *  example="103" 
    *) 
    * @SWG\Property(
    *  property="status", 
    *  type="string", 
    *  enum={"published", "draft", "suspended"} 
    *  example="published" 
    *) 
    */ 

} 

答えて

3

は正確に同じ問題に直面し、今日それを解決しました!これは

/** 
* @SWG\Post(
* path="/getCustomerByEmail.php", 
* summary="List the details of customer by the email.", 
* consumes={"string"}, 
* produces={"application/json"}, 
* @SWG\Parameter(
*  name="email", 
*  in="body", 
*  description="Customer email to ge the data", 
*  required=true, 
*  @SWG\Schema(
*  @SWG\Property(
*   property="id", 
*   type="object", 
*   @SWG\Property(
*   property="abc", 
*   type="object", 
*   @SWG\Property(
*    property="inner abc", 
*    type="number", 
*    default=1, 
*    example=123 
*   ) 
*  ), 
*   @SWG\Property(
*   property="xyz", 
*   type="string", 
*   default="xyz default value", 
*   example="xyz example value", 
*  ) 
*  ) 
* ) 
* ), 
* @SWG\Response(
*  response=200, 
*  description="Details of the customer" 
* ), 
* @SWG\Response(
*  response=400, 
*  description="Email required" 
* ), 
* @SWG\Response(
*  response=404, 
*  description="Customer does not exist" 
* ), 
* @SWG\Response(
*  response="default", 
*  description="an ""unexpected"" error" 
* ) 
*) 
*/ 
/** 

The output is as below

..私は、ネストされたパラメータを達成するために使用されていることを入れ子に注釈が続き闊歩2.0

です

注:私はまだ生のPHPが必要なプロジェクトに取り組んでいましたが、まだ はSwaggerを使いたいと思っていました。モデルを作成する代わりに、この 技法を使用してネストされたパラメータを作成しました。


編集1:私が問題だかわからない予想通り、UIはあるが、要求をしながら、ポストまたはペイロードにはデータがありません。

編集2:変換済み。 正常に動作しますfile_get_contents("php://input")

関連する問題