9

私は 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"
     * )
     */

 }
4

1 に答える 1

20

まったく同じ問題に直面し、今日解決しました!

これはSwagger 2.0用です

以下は、ネストされたパラメーターを実現するために使用した注釈のネストです。

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

出力は以下のとおりです

注:私は未加工の PHP を必要とするプロジェクトに取り組んでいましたが、それでも Swagger を使用したいと考えていました。そのため、モデルを作成する代わりに、この手法を使用してネストされたパラメーターを作成しました。


編集 1: 何が問題なのかわかりません。UI は期待どおりですが、リクエストの作成中に、投稿またはペイロードにデータがありません。

編集 2: Get を Post に変換しました。正常に動作しますfile_get_contents("php://input")

于 2016-08-17T06:13:41.133 に答える