ypereirareis.github.io
ypereirareis.github.io copied to clipboard
api-platform openapi-generator x-group-parameters
Generate a PHP client library with openapi-denerator (https://github.com/OpenAPITools/openapi-generator) from an openapi file generated from an api-platform project.
We want to generate endpoints in the client lib that groups parameters into a single parameter bag (array) => x-group-parameters
Swagger decorator
<?php
namespace App\Swagger;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
/**
* Class SwaggerDecorator.
*/
final class SwaggerDecorator implements NormalizerInterface
{
private $decorated;
public function __construct(NormalizerInterface $decorated)
{
$this->decorated = $decorated;
}
public function normalize($object, $format = null, array $context = [])
{
$docs = $this->decorated->normalize($object, $format, $context);
if (isset($docs['paths'])) {
foreach ($docs['paths'] as $uri => $path) {
foreach ($path as $operation => $route) {
$docs['paths'][$uri][$operation]['x-group-parameters'] = true;
}
}
}
return $docs;
}
public function supportsNormalization($data, $format = null)
{
return $this->decorated->supportsNormalization($data, $format);
}
}
services.yml
App\Swagger\SwaggerDecorator:
decorates: 'api_platform.swagger.normalizer.documentation'
arguments: [ '@App\Swagger\SwaggerDecorator.inner' ]
autoconfigure: false