-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use correct API doc root by reading it from the request
Fixes #2611 Also we should not append /api since the swagger already does this.
- Loading branch information
1 parent
61b2f7b
commit bf6e3fc
Showing
2 changed files
with
31 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace App\NelmioApiDocBundle; | ||
|
||
use Nelmio\ApiDocBundle\Describer\DescriberInterface; | ||
use Nelmio\ApiDocBundle\Describer\ExternalDocDescriber as BaseExternalDocDescriber; | ||
use Nelmio\ApiDocBundle\OpenApiPhp\Util; | ||
use OpenApi\Annotations\OpenApi; | ||
use Symfony\Component\DependencyInjection\Attribute\AsDecorator; | ||
use Symfony\Component\DependencyInjection\Attribute\AutowireDecorated; | ||
use Symfony\Component\HttpFoundation\RequestStack; | ||
|
||
#[AsDecorator(decorates: 'nelmio_api_doc.describers.config')] | ||
class ExternalDocDescriber implements DescriberInterface | ||
{ | ||
public function __construct( | ||
#[AutowireDecorated] | ||
protected BaseExternalDocDescriber $decorated, | ||
protected RequestStack $requestStack, | ||
) {} | ||
|
||
public function describe(OpenApi $api): void | ||
{ | ||
// Inject the correct server for the API docs | ||
$request = $this->requestStack->getCurrentRequest(); | ||
$this->decorated->describe($api); | ||
Util::merge($api->servers[0], ['url' => $request->getSchemeAndHttpHost(),], true); | ||
} | ||
} |