Rahul G.
Rahul G.

Reputation: 21

Swagger PHP annotation for object of array

I want to include Array of objects in api/doc view. But I am unable to get that.

From the code below:

@SWG\Schema(        
  @SWG\Property(property="project-name", type="string"),    
  @SWG\Property(property="project-detail", type="array",
    @SWG\Items(type="object",
        @SWG\Property(property="name", type="string", ),
        @SWG\Property(property="category", type="string",),
    ),
    @SWG\Items(type="object",
        @SWG\Property(property="new_name", type="string", ),
        @SWG\Property(property="new_category", type="string",),
    ),
  ),
),

I get the output:

{
  "project-name": "string",
  "project-detail": [
     {
       "name": "string",
       "category": "string"
     }
   ]
}

But I want below one:

{
  "project-name": "string",
  "project-detail": [
     {
       "name": "string",
       "category": "string"
     },
     {
       "new_name": "string",
       "new_category": "string"
     },
   ]
}

Please help me out for this.

Upvotes: 1

Views: 5278

Answers (2)

RNEL
RNEL

Reputation: 91

Modify your project detail property by adding example ex.

example="{
         {
          "name": "String",
          "category": "String"
         }, 
         {
          "name": "String",
          "category": "String"
         }
        }"

Upvotes: 0

Lorddistrict
Lorddistrict

Reputation: 51

You can only display one object on the array of objects. Because Swagger has been created to explain what you have to give to the API and what is returned (not required).

When you're looking an array and an object inside, of course you're understanding this isn't an array with 1 object.

Hope it helps !

Lord'

Upvotes: 2

Related Questions