Reputation: 309
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:
* @OA\Response(
* response=200,
* description="Settings",
* @OA\JsonContent(
* @OA\Property(property="options",
* @OA\Items(
* @OA\Property(property="name", type="string"),
* @OA\Property(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?
Upvotes: 3
Views: 3566
Reputation: 309
This is my solution:
/**
*
* @OA\Schema(
* schema="ExampleResponse",
* @OA\Xml(name="ExampleResponse"),
* @OA\Property(property="message", type="string", example="My solution."),
* @OA\Property(property="errors", type="object",
* @OA\AdditionalProperties(type="array",
* @OA\Items(
* @OA\Property(property="name", type="string"),
* @OA\Property(property="type", type="string")
* )
* )
* ),
* )
*
*/
Upvotes: 6