Use allOf wrapping for nested model $ref in spec output

Direct $ref with sibling properties is not valid OpenAPI 3 / Swagger 2.
Wrap in allOf so SDK generators correctly resolve the referenced schema.
This commit is contained in:
Chirag Aggarwal
2026-04-02 23:31:06 +05:30
parent 60f1426c36
commit 902642d9fe
2 changed files with 8 additions and 6 deletions
@@ -932,10 +932,11 @@ class OpenAPI3 extends Format
}
if ($items) {
if (!empty($rule['nestedModel']) && !$rule['array']) {
unset($output['components']['schemas'][$model->getType()]['properties'][$name]['type']);
$existing = $output['components']['schemas'][$model->getType()]['properties'][$name];
unset($existing['type']);
$output['components']['schemas'][$model->getType()]['properties'][$name] = \array_merge(
$output['components']['schemas'][$model->getType()]['properties'][$name],
$items
$existing,
['allOf' => [$items]]
);
} else {
$output['components']['schemas'][$model->getType()]['properties'][$name]['items'] = $items;
@@ -925,10 +925,11 @@ class Swagger2 extends Format
}
if ($items) {
if (!empty($rule['nestedModel']) && !$rule['array']) {
unset($output['definitions'][$model->getType()]['properties'][$name]['type']);
$existing = $output['definitions'][$model->getType()]['properties'][$name];
unset($existing['type']);
$output['definitions'][$model->getType()]['properties'][$name] = \array_merge(
$output['definitions'][$model->getType()]['properties'][$name],
$items
$existing,
['allOf' => [$items]]
);
} else {
$output['definitions'][$model->getType()]['properties'][$name]['items'] = $items;