1

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 ?

2 Answers 2

1

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,

Sign up to request clarification or add additional context in comments.

Comments

0

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

1 Comment

Thanks, but I got the actual solution to it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.