swagger-php 对递归对象属性引用时描述加不上去
运行环境:
laravel 10.42.0
php 8.3.2
darkaonline/l5-swagger 8.5.2
zircote/swagger-php 4.8.3
问题描述
我在学习使用 swagger-php 。目前碰到的问题如下:
我对分类资源做如下注解:
#[OA\Schema(
schema: "Goods_CategoryResource",
title: "Goods/CategoryResource",
description: "分类资源",
type: "object",
)]
#[OA\Property(property: "id", description: "ID", type: "integer", example: 1)]
#[OA\Property(property: "name", description: "分类名称", type: "string", example: "分类1")]
#[OA\Property(property: "parent_id", description: "上级分类ID", type: "integer", example: 0)]
#[OA\Property(property: "created_at", description: "创建时间", type: "string", example: "2021-08-31 07:00:00")]
#[OA\Property(property: "updated_at", description: "更新时间", type: "string", example: "2021-08-31 07:00:00")]
#[OA\Property(
property: "parent",
ref: "#/components/schemas/Goods_CategoryResource",
description: "父分类",
type: "object",
example: [
"id" => 1,
"name" => "分类1",
"parent_id" => 0,
"parent" => new stdClass(),
"children" => [],
"ancestors" => [],
"created_at" => "2021-08-31 07:00:00.00",
"updated_at" => "2021-08-31 07:00:00.00",
],
additionalProperties: new OA\AdditionalProperties(
ref: "#/components/schemas/Goods_CategoryResource",
type: "object",
),
)]
#[OA\Property(
property: "children",
description: "子分类",
type: "array",
items: new OA\Items(ref: "#/components/schemas/Goods_CategoryResource"),
example: [
[
"id" => 1,
"name" => "分类1",
"parent_id" => 0,
"parent" => new stdClass(),
"children" => [],
"ancestors" => [],
"created_at" => "2021-08-31 07:00:00.00",
"updated_at" => "2021-08-31 07:00:00.00",
]
],
)]
#[OA\Property(
property: "ancestors",
description: "祖先分类",
type: "array",
items: new OA\Items(ref: "#/components/schemas/Goods_CategoryResource"),
example: [
[
"id" => 1,
"name" => "分类1",
"parent_id" => 0,
"parent" => new stdClass(),
"children" => [],
"ancestors" => [],
"created_at" => "2021-08-31 07:00:00.00",
"updated_at" => "2021-08-31 07:00:00.00",
]
],
)]
期望获得其中的 parent
属性结果为:
"parent": {
"description": "上级分类",
"type": "object",
"additionalProperties": {
"$ref": "#/components/schemas/Goods_CategoryResource"
}
},
但目前通过 artisan l5-swagger:generate
生成的结果会丢失掉 description 这类属性直接生成:
"parent": {
"$ref": "#/components/schemas/Goods_CategoryResource"
},
有熟悉的小伙伴知道怎么生成我期望的结果吗?
推荐文章: