在Nelmio API文档包中,我在属性内使用了@Model(type=MyClass::class)
注释。该模型具有“示例”标签,以提供模型属性的示例值。这是必需的,因为我们要在API Doc页面中显示示例。
现在,该模型在父模型中已多次使用,但是每次使用该模型时,模型属性的示例都应该有所不同。
问题:如何在使用这些模型的位置覆盖这些模型中的示例?
在示例代码中,级别模型具有属性$name
的“示例”文本。使用此模型时,$name
的示例文本应由House.php中指定的示例文本覆盖。
在House.php中:
...
@SWG\Response(
response=200,
description="Description of the house levels",
@SWG\Schema(
@SWG\Property(
property="level0",
example="The base level, kitchen", <-- here actually the example for 'name' should be overwritten.
ref=@Model(type=Level::class)
),
@SWG\Property(
property="level1",
example="the first level, sleeping rooms", <-- here actually the example for 'name' should be overwritten.
ref=@Model(type=Level::class)
)
)
)
...
在Level.php中:
class Level
{
...
/**
* @var int
* @SWG\Property(property="name", type="string", example="The level description")
*/
private $name;
public function __construct(string $name)
{
$this->name = $name;
}
public getName(): string
{
return $this->name;
}
}
据我所知,模型中给出的示例不能被模型实际使用时给出的示例覆盖。