php - how to create swagger json routes using laravel

857

I want to create this type of JSON using swagger in laravel, how is it possible?

"parameters": [
          {
            "in": "body",
            "name": "body",
            "required": false,
            "schema": {
              "$ref": "#/definitions/CustomerAuthenticateResponse"
            }
          }
        ],

How this create this route: #/definitions/CustomerAuthenticateResponse ?

71

Answer

Solution:

I got the solution to pass body request(json) using swagger.

Controller:

class abcController extends Controller
{
    /*
     * @SWG\Post(
     *      path="/api/user",
     *       tags={"User"},
     *      operationId="ApiV1saveUser",
     *      summary="Add User",
     *      consumes={"application/json"},
     *      produces={"application/json"},
     *      @SWG\Parameter(
     *          name="body",
     *          in="body",
     *          @SWG\Schema(ref="#/definitions/User"), //User Model
     *      ),
     *      @SWG\Response(
     *         response=200,
     *         description="Success"
     *      ),
     * )
     */
     public function store(Request $request)
     {
     }
}

User Model:

/**
    * @SWG\Definition(
    *      required={"name","email"},
    *      type="object",
    *      @SWG\Xml(name="User")
    * ),
    * @SWG\Property(format="byte", type="string", property="name", description="User Name"),
    * @SWG\Property(format="byte", type="string",property="email", description="Email")
    */
    class User extends Model
    {
    }

Thanks,

846

Answer

Solution:

Take a look at this package After installing you can put the definitions in the phpdoc of your controller.

class PetController
{
    /**
     * @OAS\Post(
     *     path="/pet",
     *     tags={"pet"},
     *     summary="Add a new pet to the store",
     *     operationId="addPet",
     *     @OAS\Response(
     *         response=405,
     *         description="Invalid input"
     *     ),
     *     security={
     *         {"petstore_auth": {"write:pets", "read:pets"}}
     *     },
     *     requestBody={"$ref": "#/components/requestBodies/Pet"}
     * )
     */
    public function addPet()
    {
    }
}

source

People are also looking for solutions to the problem: javascript - Show Modal after user hasnt interact with the page in x minutes

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.