Search code examples
swaggeropenapiswagger-editorswagger-php

Swagger-php adding a "schema" property on every Model property


(This is my first stack overflow post so go easy on me, haha)

I'm using:
-OpenApi (v3)
-L5-Swagger (wrapper of swagger-php & swagger-ui)

I'm using annotations to generate an OpenAPI spec. The spec is being generated without errors from the console. However, in each property for every model there's an additional property being added once it generates.

I've tried:
1. re-writing the model,
2. rewriting the properties in different ways

One of my models & the "id" property:

/**   
 * 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"   
 * )   

Here's what is being generated:

        "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"
                },

What am I doing that there's a "schema" property being generated?

When I put the spec file into Swagger editor, it says that ActionPlan.properties.id should NOT have additional properties. Additional property: schema.

I'm just wondering what's happening to make create "schema" property.

Thanks in advance!


Solution

  • This "error", I learned, is actually not an error at all. It's actually a very helpful feature that I was just unaware of! When an OA\Property is created outside of it's corresponding OA\Schema object, a "schema" property is added in each property to, I imagine, create a reference so we as developers don't lose become confused as to which OA\Schema a property belongs to. To remove this "schema" property, one just needs to move all the OA\Properties inside their corresponding OA\Schema object. Like so..

    /**
      * 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"
      *    )
      * )
      */