swagger-php注釋寫法教程,實用例子


網上關於swagger-php的注釋寫法,資料較少。最全面的應該是 Laravel-China上如何編寫基於 Swagger-PHP 的 API 文檔

 

本篇文章記錄一下遇到的坑。

文章中第1章2.5節,

required的值應該是true,不帶引號。

如果是post請求,請求消息體中包含多個參數,並且修改了header內容。

header內容應該放到form內容之前。例子:

 1     /**
 2      * @SWG\Post(
 3      *     path="/mall/save",
 4      *     summary="保存采集的id",
 5      *     description="用戶使用瀏覽器插件,將某個日期的流量id保存到服務器",
 6      *     tags={"Mall"},
 7      *     @SWG\Parameter(
 8      *          name="token",
 9      *          type="string",
10      *          required=true,
11      *          in="header",
12      *          description="令牌"
13      *     ),
14      *     @SWG\Parameter(
15      *          name="date",
16      *          type="string",
17      *          format="date",
18      *          required=true,
19      *          in="formData",
20      *          default="2018-12-05",
21      *          description="日期。格式為2018-12-05"
22      *     ),
23      *     @SWG\Parameter(
24      *          name="mallId",
25      *          type="string",
26      *          required=true,
27      *          in="formData",
28      *          description="店鋪id"
29      *     ),44      *     @SWG\Response(
45      *         response="200",
46      *         description="狀態碼、提示消息",
47      *         @SWG\Schema(
48      *              required={"code","message"},
49      *              @SWG\Property(
50      *                  property="code",
51      *                  type="integer",
52      *                  format="int32",
53      *                  description="狀態碼"
54      *              ),
55      *              @SWG\Property(
56      *                  property="message",
57      *                  type="string",
58      *                  description="提示消息"
59      *              ),
60      *              @SWG\Property(
61      *                  property="data",
62      *                  type="string",
63      *                  description="數據"
64      *              )
65      *          )
66      *     )
67      * )
68      */

 

 

 返回復雜結果的例子:

    /**
     * @SWG\Post(
     *     path="/mall/get",
     *     summary="獲取所有采集的id",
     *     description="獲取所有采集的id",
     *     tags={"Mall"},
     *     @SWG\Parameter(
     *          name="token",
     *          type="string",
     *          required=true,
     *          in="header",
     *          description="令牌"
     *     ),
     *     @SWG\Parameter(
     *          name="mallId",
     *          type="string",
     *          required=true,
     *          in="formData",
     *          default="123123",
     *          description="店鋪id"
     *     ),
     *     @SWG\Response(
     *         response="200",
     *         description="狀態碼、提示消息",
     *         @SWG\Schema(
     *              required={"code","message"},
     *              @SWG\Property(
     *                  property="code",
     *                  type="integer",
     *                  format="int32",
     *                  description="狀態碼"
     *              ),
     *              @SWG\Property(
     *                  property="message",
     *                  type="string",
     *                  description="提示消息"
     *              ),
     *              @SWG\Property(
     *                  property="data",
     *                  type="array",
     *                  @SWG\Items(
     *                      @SWG\Property(
     *                          property="id",
     *                          type="integer",
     *                          description="流量記錄id"
     *                      ),
     *                      @SWG\Property(
     *                          property="date",
     *                          type="string",
     *                          description="流量id所在的日期。例:2019-01-01"
     *                      ),
     *                      @SWG\Property(
     *                          property="nallIdNum",
     *                          type="integer",
     *                          description="id的數量"
     *                      )
     *                  )
     *              ),
     *          )
     *     )
     * )
     */

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM