Swagger-php: Simple array of strings as body

Created on 11 Jul 2016  路  3Comments  路  Source: zircote/swagger-php

I am trying to define the request body as a simple array of strings like this:

@SWG\Parameter(
     *     in="body",
     *     description="List of ids",
     *     required=true,
     *     type="array",
     *     @SWG\Items(type="string")
     *   ),

The resulting data type/model is just

Array[string]

Can this be any better?

At the same time the response should be a single array of strings which also seems to be an issue as no matter what I've tried so far it mostly looks like this:

{
  "ids": []
}

Is there perhaps a list of simple examples on how to create some of these basic structures?

Most helpful comment

No list that I know of, let me know if you find one, so i can link it in the docs.
The json-schema.org has some examples to get a feel for defining the data-structures.

 * @SWG\Response(
 *   response=200,
 *   description="List of ids",
 *   @SWG\Schema(
 *     type="array",
 *     @SWG\Items(type="string")
 *   )
 * )

All 3 comments

No list that I know of, let me know if you find one, so i can link it in the docs.
The json-schema.org has some examples to get a feel for defining the data-structures.

 * @SWG\Response(
 *   response=200,
 *   description="List of ids",
 *   @SWG\Schema(
 *     type="array",
 *     @SWG\Items(type="string")
 *   )
 * )

Thinking too complicated !

Thanks.

/**
 * @OA\Schema(
 *   schema="PostRequest",
 *   type="object",
 *   @OA\Property(
 *     property="images",
 *     description="The images URL",
 *     type="array",
 *     @OA\Items(type="string")
 *   )
 * )
 */

Now you can use the Schema in the service's description:

    /**
     * @OA\Post(
     *   path="/posts",
     *   @OA\RequestBody(
     *     @OA\MediaType(
     *       mediaType="application/json",
     *       @OA\Schema(ref="#/components/schemas/PostRequest")
     *     )
     *   ),
     * )
     */
Was this page helpful?
0 / 5 - 0 ratings

Related issues

Dalabad picture Dalabad  路  4Comments

beeradmoore picture beeradmoore  路  5Comments

xiehan picture xiehan  路  5Comments

hpatoio picture hpatoio  路  3Comments

huksley picture huksley  路  4Comments