【问题标题】:Swagger-php adding a "schema" property on every Model propertySwagger-php 在每个模型属性上添加一个“模式”属性
【发布时间】:2019-08-08 00:25:33
【问题描述】:

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

我正在使用:
-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 不应该有其他属性。附加属性:架构。

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

提前致谢!

【问题讨论】:

    标签: swagger openapi swagger-editor swagger-php


    【解决方案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"
      *    )
      * )
      */
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-01
      • 2016-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多