首页 > 解决方案 > 无法从 Swagger API 文档中获取数据

问题描述

我昨晚刚开始使用 swagger/openapi,我正在尝试为演示书店应用程序记录 API,但我无法从 swagger-ui 上的 api 获取数据。

这是 api doc bookstore api doc的链接

我已经像这样向 BookController 添加了注释

/**
 *  @OA\Schema(
 *      schema="Book",
 *      @OA\Property(property="title", type="string"),
 *      @OA\Property(property="author", type="string"),
 *      @OA\Property(property="description", type="string")
 *  )
 */
/**
 *  @OA\Schema(
 *      schema="NewBook",
 *      required={"title", "author", "description"}
 *  )
 */

class BookController extends Controller
{
    /**
     * @OA\Get(
     *     path="/books",
     *     description="Returns a books list from the app",
     *     operationId="getBooksList",
     *     summary="Gets a complete list of all books available on the app with their ratings",
     *     @OA\Response(
     *         response=200,
     *         description="book response",
     *         @OA\JsonContent(
     *             type="array",
     *             @OA\Items(ref="#/components/schemas/Book")
     *         )
     *     ),
     *     @OA\Response(
     *         response="default",
     *         description="unexpected error",
     *     )
     * )
     */
    /**
     * Display a listing of the books.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return BookResource::collection(Book::with('ratings')->get());
    }
}

我哪里出错了,我该如何解决?

标签: phplaravelswaggerswagger-uiopenapi

解决方案


推荐阅读