How to specify additionalProperties with l5-swagger

  laravel, openapi, swagger

I am trying to write OpenAPI documentation for a project (written with Laravel) and struggling with several API points.

One returns

{
    "active_options": {
        "1": {
            "name": "name1",
            "type": "type1"
        },
        "2": {
            "name": "name2",
            "type": "type2"
        },
        "3": {
            "name": "name3",
            "type": "type3"
        }
    },
    "server": {
        "url": "URL...",
        "settings1": "value"
    },
    "message": "Server settings retrieved."
}

I am struggling with how to write this annotation with l5-swagger plugin.
The "1", "2", "3" are optional and any combination of them is valid.

I wanted to use optionalProperties, but I don’t know how to combine them together.

This is the closest I got:

     *   @OAResponse(
     *     response=200,
     *     description="Settings",
     *     @OAJsonContent(
     *       @OAProperty(property="options",
     *         @OAItems(
     *            @OAProperty(property="name", type="string"),
     *            @OAProperty(property="type", type="string")
     *         )
     *       ),
     *     )
     *   ),


But the sample generates this:

{
  "options": [
    {
      "name": "string",
      "type": "string"
    }
  ]
}

Which obviously is missing the "1": … part.
Maybe a better question would be how to do unnamed properties?

Source: Laravel

Leave a Reply