Skip to content

Commit

Permalink
Use correct API doc root by reading it from the request
Browse files Browse the repository at this point in the history
Fixes #2611

Also we should not append /api since the swagger already does this.
  • Loading branch information
nickygerritsen committed Jun 21, 2024
1 parent 61b2f7b commit bf6e3fc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions webapp/config/packages/nelmio_api_doc.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
nelmio_api_doc:
documentation:
servers:
- url: "%domjudge.baseurl%api"
- url: ~ # Will be set by App\NelmioApiDocBundle\ExternalDocDescriber
description: API used at this contest
- url: https://www.domjudge.org/demoweb/api
- url: https://www.domjudge.org/demoweb
description: New API in development
info:
title: DOMjudge
Expand Down
29 changes: 29 additions & 0 deletions webapp/src/NelmioApiDocBundle/ExternalDocDescriber.php
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);
}
}

0 comments on commit bf6e3fc

Please sign in to comment.