I'm using zircote/swagger-php for annotations to generate swagger for my php WebApi.
I have my generic model HttpResponse, it has 2 common properties (messages and statusCode) but data is generic and has different type for every endpoint.
I'm trying to annote it via zircote/swagger-php and use different model for this data property for every endpoint. Can anyone tell me how I can do this?
Right now I'm trying something like below, but its giving me first of those anyOf to every request instead allow me specific which one i want.
/**
* @OA\Schema()
*/
class HttpResponse
{
/**
* @OA\Property(anyOf={
* @OA\Schema(ref="#/components/schemas/HolidayRequestSpecificInput"),
* @OA\Schema(ref="#/components/schemas/AvailableHolidayDatesApiModel")
* })
*/
public $data;
/**
* @OA\Property(type="array", @OA\Items(ref="#/components/schemas/Message"))
*/
public $messages;
/**
* @OA\Property(ref="#/components/schemas/HttpResponseType")
*/
public $statusCode;
public function __construct($statusCode = HttpResponseType::Ok, $data = null)
{
$this->data = $data;
$this->messages = [];
$this->statusCode = $statusCode;
}
public function addMessages($messages)
{
foreach ($messages as $msg)
array_push($this->messages, $msg);
}
}