Skip to content

Commit

Permalink
Make the Tool Work with NelmioApiDocBundle
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisguitarguy committed Jun 18, 2024
1 parent 2524493 commit 3c1d0f2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
9 changes: 5 additions & 4 deletions bin/openapi-rector
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

#set -x

dir=$(dirname $(realpath -P $0))
composer require zircote/swagger-php:^4.0 --dev
php $dir/fix-api-spec.php
php $dir/../vendor/bin/rector process src/application --config $dir/../rector.php
dir=$(dirname $(realpath $0))
#composer require zircote/swagger-php:^4.0 --dev
echo $dir
#php $dir/fix-api-spec.php
php $dir/../vendor/bin/rector process src --config $dir/../rector.php
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"require": {
"php": ">=8.1",
"rector/rector": "^0.15.25",
"zircote/swagger-php": "^4.7"
"zircote/swagger-php": "^4.7",
"nelmio/api-doc-bundle": "^4.27"
},
"require-dev": {
"phpunit/phpunit": "^10.1"
Expand Down
23 changes: 22 additions & 1 deletion utils/rector/src/OpenApiTagValueNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,27 @@ public function getValues(): array
);
break;
}

// request body wants `content` as the ref, so handle that first
$isModel = 'Nelmio\\ApiDocBundle\\Annotation\\Model' === $itemClass;
$isRequestBody = $attributeClass === 'OpenApi\\Attributes\\RequestBody';
if ($isRequestBody && 'content' === $name && $isModel) {
$newValues[$name] = new ArrayItemNode(
new OpenApiTagValueNode($item->value),
$name,
$item->kindValueQuoted,
$item->kindKeyQuoted
);
break;
} elseif (!$isRequestBody && 'ref' === $name && $isModel) {
$newValues[$name] = new ArrayItemNode(
new OpenApiTagValueNode($item->value),
$name,
$item->kindValueQuoted,
$item->kindKeyQuoted
);
break;
}
}
}
}
Expand All @@ -115,4 +136,4 @@ private function typeMatch(\ReflectionType $parameterType, string $class): bool
}
return false;
}
}
}

0 comments on commit 3c1d0f2

Please # to comment.