4

I use Laravel + Swagger PHP. In one of my services, I handle parameters like this :

$params = [
    'addressChild' => [
        'address' => ' ... ',
        'city' => ' ... ',
    ],
    'addressParent' => [
        'address' => ' ... ',
        'city' => ' ... ',
    ],
];

I am trying to describe this schema in Swagger Annotations, using OpenApi 3 :

/**
 * @OA\Post(
 *      path="/entity/{entity}/addresses",
 *      @OA\Response(
 *          response=200,
 *          @OA\JsonContent()
 *      ),
 *      @OA\RequestBody(
 *          description="Addresses to store",
 *          required=true,
 *          @OA\JsonContent(
 *              type="object",
 *              @OA\Property()
 *          ),
 *      ),
 * )
 *
 */
public function update(Request $request)
{
    // ...
}

I tried many things like :

 @OA\JsonContent(
     type="object",
     @OA\Property(name="addressKid", ref="#/components/schemas/ParkingAddressRequest") // error
 ),

My address data is described in ref="#/components/schemas/ParkingAddressRequest" schema, how can I set it as an array in RequestBody ?

1 Answer 1

4

If I understood your problem, you could do it like this

/**
 * @OA\Post(
 *      path="/entity/{entity}/addresses",
 *      @OA\Response(
 *          response=200,
 *          @OA\JsonContent()
 *      ),
 *      @OA\RequestBody(
 *          description="Addresses to store",
 *          required=true,
 *          @OA\JsonContent(
 *              type="array",
 *              @OA\Items(ref="#/components/schemas/ParkingAddressRequest")
 *          ),
 *      ),
 * )
 *
 */
Sign up to request clarification or add additional context in comments.

Comments

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.