1. 程式人生 > 實用技巧 >[FAQ] swagger-php @OA\JsonContent 與 @MediaType @OA\Schema 的用法

[FAQ] swagger-php @OA\JsonContent 與 @MediaType @OA\Schema 的用法

@OA\JsonContent 是對@MediaType @OA\Schema 兩者的封裝,類似於 laravel 中 JsonResponse 對 Response 的封裝。

@OA\JsonContent 例子:

     *      @OA\Response(
     *          response=200,
     *          description="failure data",
     *          @OA\JsonContent(
     *              type="object",
     *              @OA\Property(property="data", default
=""), * @OA\Property(property="message", type="string", default="xx not correct"), * @OA\Property(property="code", type="integer", default=-1) * ) * ),

@MediaType 和 @OA\Schema 例子:

     *      @OA\Response(
     *          response=200,
     *          description="success data",
     *          @OA\MediaType(
     
* mediaType="application/json", * @OA\Schema( * @OA\Property(property="data", type="object", * @OA\Property(property="token", type="string") * ), * @OA\Property(property="message", default
="success"), * @OA\Property(property="code", type="integer") * ) * ) * ),

Doc:https://zircote.github.io/swagger-php/Getting-started.html#shortcuts

Link:https://www.cnblogs.com/farwish/p/14015753.html