Skip to content

Commit 7858e80

Browse files
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.
1 parent 61b2f7b commit 7858e80

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

webapp/config/packages/nelmio_api_doc.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
nelmio_api_doc:
22
documentation:
33
servers:
4-
- url: "%domjudge.baseurl%api"
4+
- url: ~ # Will be set by App\NelmioApiDocBundle\ExternalDocDescriber
55
description: API used at this contest
6-
- url: https://www.domjudge.org/demoweb/api
6+
- url: https://www.domjudge.org/demoweb
77
description: New API in development
88
info:
99
title: DOMjudge
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace App\NelmioApiDocBundle;
4+
5+
use Nelmio\ApiDocBundle\Describer\DescriberInterface;
6+
use Nelmio\ApiDocBundle\Describer\ExternalDocDescriber as BaseExternalDocDescriber;
7+
use Nelmio\ApiDocBundle\OpenApiPhp\Util;
8+
use OpenApi\Annotations\OpenApi;
9+
use Symfony\Component\DependencyInjection\Attribute\AsDecorator;
10+
use Symfony\Component\DependencyInjection\Attribute\AutowireDecorated;
11+
use Symfony\Component\HttpFoundation\RequestStack;
12+
13+
#[AsDecorator(decorates: 'nelmio_api_doc.describers.config')]
14+
class ExternalDocDescriber implements DescriberInterface
15+
{
16+
public function __construct(
17+
#[AutowireDecorated]
18+
protected BaseExternalDocDescriber $decorated,
19+
protected RequestStack $requestStack,
20+
) {}
21+
22+
public function describe(OpenApi $api): void
23+
{
24+
// Inject the correct server for the API docs
25+
$request = $this->requestStack->getCurrentRequest();
26+
$this->decorated->describe($api);
27+
Util::merge($api->servers[0], ['url' => $request->getSchemeAndHttpHost(),], true);
28+
}
29+
}

0 commit comments

Comments
 (0)