V
V
v_i_rus2022-03-21 10:19:17
API
v_i_rus, 2022-03-21 10:19:17

What's wrong with generating the Swagger Documentation API?

I'm not familiar with swagger, I'm just learning. The task is to generate documentation for api controllers. Put the @OA\Info annotation on the main controller class

namespace App\Http\Controllers;

/**
 * @OA\Info(
 *      version="1.0.0",
 *      title="Documentation",
 *      description="Документация",
 * )
 */

class Controller extends BaseController


Added path annotations to other controllers
namespace App\Http\Controllers;

/**
 * @OA\Schema(
 *     title="UserController",
 *     description="UserController",
 *     @OA\Xml(
 *         name="UserController"
 *     )
 * )
 */

class UserController extends Controller
{
    /**
     * @OA\Post(
     * path="/api/users/add",
     *   tags={"add"},
     *   summary="add",
     *   operationId="add",
     *
     *  @OA\Parameter(
     *      name="name",
     *      in="query",
     *      required=true,
     *      @OA\Schema(
     *           type="string"
     *      )
     *   ),
     *   @OA\Parameter(
     *      name="email",
     *      in="query",
     *      required=true,
     *      @OA\Schema(
     *           type="string"
     *      )
     *   ),
     *   @OA\Parameter(
     *      name="password",
     *      in="query",
     *      required=true,
     *      @OA\Schema(
     *          type="string"
     *      )
     *   ),
     *   @OA\Response(
     *      response=200,
     *       description="Success",
     *      @OA\MediaType(
     *           mediaType="application/json",
     *      )
     *   )
     *)
     **/
    /**
     * @param Request $request
     * @return bool
     */
    public function create(Request $request){
        return $this->serviceUser->create($request);
    }
    ....
}


When executing the php artisan l5-swagger:generate command,
I get the error Required @OA\PathItem() not found

I did not change the configs. Routes are spelled correctly.
Installed package "darkaonline/l5-swagger": "^8.3"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
v_i_rus, 2022-03-21
@v_i_rus

because of the two annotations in a row, the last one will be selected. solved by merging them into one

/**
     * @OA\Post(
     * path="/api/users/add",
     *   tags={"add"},
     *   summary="add",
     *   operationId="add",
     *
     *  @OA\Parameter(
     *      name="name",
     *      in="query",
     *      required=true,
     *      @OA\Schema(
     *           type="string"
     *      )
     *   ),
     *   @OA\Parameter(
     *      name="email",
     *      in="query",
     *      required=true,
     *      @OA\Schema(
     *           type="string"
     *      )
     *   ),
     *   @OA\Parameter(
     *      name="password",
     *      in="query",
     *      required=true,
     *      @OA\Schema(
     *          type="string"
     *      )
     *   ),
     *   @OA\Response(
     *      response=200,
     *       description="Success",
     *      @OA\MediaType(
     *           mediaType="application/json",
     *      )
     *   )
     *)
     * @param Request $request
     * @return bool
     */

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question