1

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.

2

2 Answers 2

2

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'

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

Comments

0

Modify your project detail property by adding example ex.

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

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.