1

(这是我的第一个堆栈溢出帖子,所以请放轻松,哈哈)

我正在使用:
-OpenApi (v3)
-L5-Swagger(swagger-php 和 swagger-ui 的包装器)

我正在使用注释来生成 OpenAPI 规范。正在从控制台生成规范,没有错误。但是,在每个模型的每个属性中,一旦生成,就会添加一个附加属性。

我尝试过:
1. 重写模型,
2. 以不同方式重写属性

我的模型之一和“id”属性:

/**   
 * Class ActionPlan   
 *   
 * @OA\Schema(   
 *   description="Action Plans",   
 *   title="Action Plan Schema",   
 *   required={   
 *     "id",   
 *     "name",   
 *     "organization_id",   
 *     "assessment_period_id",   
 *     "completed",   
 *     "created_by",   
 *     "updated_by"   
 *   },   
 * )   
 *   
 * @OA\Property(   
 *   property="id",   
 *   type="integer",   
 *   format="int32",   
 *   description="Action Plan ID"   
 * )   

这是正在生成的内容:

        "ActionPlan": {
            "title": "Action Plan Schema",
            "description": "Action Plans",
            "required": [
                "id",
                "name",
                "organization_id",
                "assessment_period_id",
                "completed",
                "created_by",
                "updated_by"
            ],
            "properties": {
                "id": {
                    "schema": "ActionPlan",
                    "description": "Action Plan ID",
                    "type": "integer",
                    "format": "int32"
                },

我在做什么,正在生成一个“模式”属性?

当我将规范文件放入 Swagger 编辑器时,它说 ActionPlan.properties.id 不应该有其他属性。附加属性:模式。

我只是想知道创建“模式”属性发生了什么。

提前致谢!

4

1 回答 1

1

我了解到,这个“错误”实际上根本不是错误。这实际上是一个非常有用的功能,我只是不知道!当在其对应的 OA\Schema 对象之外创建 OA\Property 时,我想在每个属性中添加一个“模式”属性,以创建一个引用,这样我们作为开发人员就不会迷茫哪个 OA\Schema财产属于。要删除此“模式”属性,只需将所有 OA\Properties 移动其对应的 OA\Schema 对象中。像这样。。

/**
  * Class ActionPlan
  *
  * @OA\Schema(
  *   description="Action Plans",
  *   title="Action Plan Schema",
  *   required={
  *     "id",
  *     "name",
  *     "organization_id",
  *     "assessment_period_id",
  *     "completed",
  *     "created_by",
  *     "updated_by"
  *   },
  *    @OA\Property(
  *      property="id",
  *      type="integer",
  *      format="int32",
  *      description="Action Plan ID"
  *    )
  * )
  */
于 2019-08-08T16:58:08.053 回答