I had the same problem that you, I avoided the problem by using service decorations as described in the documentation.
config/services.yaml
# Customize Swagger documentation
'App\Swagger\SwaggerDecorator':
decorates: 'api_platform.swagger.normalizer.documentation'
arguments: [ '@App\Swagger\SwaggerDecorator.inner' ]
autoconfigure: false
src/Swagger/SwaggerDecorator.php
<?php
namespace App\Swagger;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
/**
* @link https://api-platform.com/docs/core/swagger/
*/
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);
$customDefinition = [
'name' => 'id',
'description' => 'ID of user',
'in' => 'path',
'required' => 'true',
];
$docs['paths']['/api/ben/stack_overflow/{id}']['post'] = [
'summary' => 'SO example',
'parameters' => [
$customDefinition,
],
'responses' => [
'200' => [
'description' => 'OK',
],
'400' => [
'description' => 'Error',
],
],
];
}
public function supportsNormalization($data, $format = null)
{
return $this->decorated->supportsNormalization($data, $format);
}
}
The syntax is the same as in Swagger but is written as PHP array instead of JSON.
It will generate the following Swagger documentation :

(I don't know yet how to change the default
title)