Scenario:
- a schema is declared above a
child_class
child_class extends parent_class
- 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
Scenario:
child_classchild_classextendsparent_classparent_classUnexpected result: the property of the
parent_classschema is merged into the schema of thechild_classExample code:
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