メモ:swaggerアノテーションでResponseの型の書き方
 2018年2月4日
データ削除のAPIは削除できなかった場合でもResponseは200OKなので、bodyで削除数を戻すようにしている。
swagger-uiで数値の戻り値の書き方。
コントローラーのアノテーションのResponseに@SWG\Schema( type=”integer”)を追加。
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51  | 
						    /**      * Remove the specified resource from storage.      *      * @param  string  $date      * @param  string  $time      * @return \Illuminate\Http\Response      *      * @SWG\Delete(      *     path="/blood/{date}/{time}",      *     summary="データを削除する",      *     produces={"application/json"},      *     tags={"blood"},      *     security={{      *       "MyHeaderAuthentication":{}      *     }},      *     @SWG\Parameter(      *         name="date",      *         description="日付",      *         in="path",      *         required=true,      *         type="string"      *     ),      *     @SWG\Parameter(      *         name="time",      *         description="時刻",      *         in="path",      *         required=true,      *         type="string"      *     ),      *     @SWG\Response(      *         response=200,      *         description="OK",      *         @SWG\Schema(      *             type="integer")      *     ),      *     @SWG\Response(      *         response=400,      *         description="BAD-REQUEST"      *     ),      *     @SWG\Response(      *         response=403,      *         description="Auth error",      *     ),      * )      */     public function destroy($date, $time)     {         $res = Blood::where('date', $date)->where('time', $time)->forceDelete();         return response()->json($res, 200);     }  | 
					
swagger-uiのswagger.jsonファイルを再出力。
| 
					 1  | 
						#vendor/bin/swagger /var/www/blood/app/ -o public/swagger-ui/  | 
					
| 
					 1 2 3 4 5 6 7 8 9 10 11 12  | 
						[root@app-server blood]# vendor/bin/swagger /var/www/blood/app/ -o public/swagger-ui/ Swagger-PHP 2.0.9 -----------------     get /blood     put /blood     get /blood/{from}/{to}  delete /blood/{date}/{time} ----------------------- 4 operations documented ----------------------- Written to /var/www/blood/public/swagger-ui/swagger.json  | 
					
戻り値のExample Valueで数値が返ることがわかるようになった。
ちなみに@SWG\Schema( type=”boolean”)にすると、Example Valueはtrueとか表示される。
試しに実行。
できた。(o^-‘)b


