Browse Source

dolibarr docs exclusion

Vincent GUFFON 3 years ago
parent
commit
ee2b3309fb
2 changed files with 46 additions and 0 deletions
  1. 5 0
      config/services.yaml
  2. 41 0
      src/OpenApi/OpenApiFactory.php

+ 5 - 0
config/services.yaml

@@ -28,6 +28,11 @@ services:
             - '../src/Kernel.php'
             - '../src/Tests/'
 
+    App\OpenApi\OpenApiFactory:
+        decorates: 'api_platform.openapi.factory'
+        arguments: [ '@App\OpenApi\OpenApiFactory.inner' ]
+        autoconfigure: false
+
     App\Service\Cotisation\Utils:
         public: true
 

+ 41 - 0
src/OpenApi/OpenApiFactory.php

@@ -0,0 +1,41 @@
+<?php
+declare(strict_types=1);
+
+namespace App\OpenApi;
+
+use ApiPlatform\Core\OpenApi\Factory\OpenApiFactoryInterface;
+use ApiPlatform\Core\OpenApi\OpenApi;
+use ApiPlatform\Core\OpenApi\Model;
+
+final class OpenApiFactory implements OpenApiFactoryInterface
+{
+    const PATH_TO_EXCLUDE = [
+        '/api/dolibarr_bills/{id}',
+        '/api/dolibarr_contract_lines/{id}',
+        '/api/dolibarr_contracts/{ref}',
+    ];
+
+    private $decorated;
+
+    public function __construct(OpenApiFactoryInterface $decorated)
+    {
+        $this->decorated = $decorated;
+    }
+
+    public function __invoke(array $context = []): OpenApi
+    {
+        $openApi = $this->decorated->__invoke($context);
+
+        $paths = $openApi->getPaths()->getPaths();
+
+        $filteredPaths = new Model\Paths();
+        foreach ($paths as $path => $pathItem) {
+            if (in_array($path, self::PATH_TO_EXCLUDE)) {
+                continue;
+            }
+            $filteredPaths->addPath($path, $pathItem);
+        }
+
+        return $openApi->withPaths($filteredPaths);
+    }
+}