$openapi = \OpenApi\Generator::scan(['/path/to/project']);
header('Content-Type: application/x-yaml');
echo $openapi->toYaml();
* @OA\Property(property="resp", type="object", anyOf = {
* @OA\Schema(ref="#/components/schemas/Variant1"),
* @OA\Schema(ref="#/components/schemas/Variant2")
* })
* @OA\Property(property="resp", type="object", anyOf = {
* @OA\Schema(ref="#/components/schemas/Variant1"),
* @OA\Schema(ref="#/components/schemas/Variant2")
* })responses:
'200':
description: wqewq* @OA\Response(
* response=200,
* description="wqewq",
* @OA\Property(
* property="resp",
* type="object",
* anyOf = {
* @OA\Schema(
* type="array",
* @OA\Items(
* @OA\Property(
* property="guid",
* type="string",
* example="548112d7-7fb7-417b-916a-76fb74de8fba",
* description="The transaction was successfully created",
* )
* )
* ),
*
* }
* )
* ),* @OA\Response(
* response=200,
* description="ok",
* @OA\JsonContent(
* allOf = {
* @OA\Schema(ref="#/components/schemas/ApiResult")
* },
* @OA\Property(
* property = "success",
* type="boolean",
* example="true"
* ),
* @OA\Property(
* property = "data",
* ref="#/components/schemas/Item"
* )
* )
* ),/**
* @OA\Schema(
* schema="Item",
* description="Блабла",
* @OA\Property(property="id", type="integer", example=123),
* @OA\Property(property="name", type="string", example="Test"),
* @OA\Property(property="var", type="object", anyOf = {
* @OA\Schema(ref="#/components/schemas/Variant1"),
* @OA\Schema(ref="#/components/schemas/Variant2")
* })
* )
*/

* @OA\Response(
* response=200,
* description="Ok",
* @OA\JsonContent(
* allOf = {
* @OA\Schema(
* type="array",
* @OA\Items(
* @OA\Property(
* property="guid",
* type="string",
* example="548112d7-7fb7-417b-916a-76fb74de8fba",
* description="The transaction was successfully created",
* )
* )
* ),
* @OA\Schema(
* @OA\Property(
* property="error",
* type="object",
* @OA\Property(
* property="code",
* type="string",
* example="101"
* ),
* @OA\Property(
* property="message",
* type="string",
* example="No input data"
* )
* )
* )
* }
* )
* ),
. allOf нужен, чтобы расширять ApiResult. В data у меня может быть и список, и объект, например, или вообще null.

* @OA\Response(
* response=200,
* description="Ok",
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* oneOf={
* @OA\Schema(
* type="array",
* @OA\Items(
* @OA\Property(
* property="guid",
* type="string",
* description="Internal identificator of transaction",
* )
* )
* ),
* @OA\Schema(
* @OA\Property(
* property="error",
* type="object",
* @OA\Property(
* property="code",
* type="intager",
* ),
* @OA\Property(
* property="message",
* type="string",
* )
* )
* )
* },
* ),
* @OA\Examples(
* description="Success response",
* summary="Success response",
* example="Success response",
* value={{"guid":"548112d7-7fb7-417b-916a-76fb74de8fba"}}
* ),
* @OA\Examples(
* description="Response with code 101",
* summary="Response with code 101",
* example="Response with code 101",
* value={"error":{"code":"101", "message":"No input data"}}
* )
* )
* ),
Sergey Ilichev, если я правильно вас понял, то в этих аннотациях можно написать вообще всё, что угодно - и нет никакой гарантии, что это будет отражать реальное положение вещей. И дело, кстати, не в PHP. В том же NestJS, например, тоже можно сделать так, что схема не будет соответствовать реальному ответу.

Но по факту вроде там вообще никакого соответствия не проверяется со схемой