Skip to content

Schema wrongly absorbs property from another schema #666

Description

@coriolanweihrauch

Scenario:

  1. a schema is declared above a child_class
  2. child_class extends parent_class
  3. another schema is declared above parent_class

Unexpected result: the property of the parent_class schema is merged into the schema of the child_class

Example code:

<?php

namespace App\Http\Controllers;

use OpenApi\Attributes as OA;

#[OA\Schema(
    schema: "UsefulSchema",
    properties: [
        new OA\Property(property: "good", type: "string", example: "expected to display"),
    ],
    type: "object",
)]
class TestController extends Parent_class
{
    #[OA\Get(
        path: "/url",
        summary: "controller",
        requestBody: new OA\RequestBody(
            content: new OA\JsonContent(
                ref: "#/components/schemas/UsefulSchema"
            )
        ),
        responses: [
            new OA\Response(
                response: 200,
                description: "Successful response",
            ),
        ]
    )]
    public function action()
    {
    }
}

#[OA\Schema(
    schema: "BuggySchema",
    properties: [
        new OA\Property(property: "bug", type: "string", example: "should not appear"),
    ],
    type: "object",
)]
class Parent_class
{
}

Expected result

Get /url
Request body: application/json
Example Value

{
  "good": "expected to display"
}

Actual result

Get /url
Request body: application/json
Example Value

{
  "bug": "should not appear",
  "good": "expected to display"
}

Workaround

Do not declare schemas above classes and move them into the body

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions