From 1e82b222f7f0d46908d12104935333504f294f04 Mon Sep 17 00:00:00 2001
From: Ninos <me@ninosego.de>
Date: Mon, 27 Nov 2023 15:17:29 +0100
Subject: [PATCH] Added: JWT security scheme to openapi

---
 OpenApi/OpenApiFactory.php                            | 11 +++++++++++
 .../Command/ApiPlatformOpenApiExportCommandTest.php   |  8 +++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/OpenApi/OpenApiFactory.php b/OpenApi/OpenApiFactory.php
index 88227fb3..fe792dc7 100644
--- a/OpenApi/OpenApiFactory.php
+++ b/OpenApi/OpenApiFactory.php
@@ -43,6 +43,17 @@ public function __invoke(array $context = []): OpenApi
     {
         $openApi = ($this->decorated)($context);
 
+        $openApi
+            ->getComponents()->getSecuritySchemes()->offsetSet(
+                'JWT',
+                new \ArrayObject([
+                        'type' => 'http',
+                        'scheme' => 'bearer',
+                        'bearerFormat' => 'JWT',
+                    ]
+                )
+            );
+
         $openApi
             ->getPaths()
             ->addPath($this->checkPath, (new PathItem())->withPost(
diff --git a/Tests/Functional/Command/ApiPlatformOpenApiExportCommandTest.php b/Tests/Functional/Command/ApiPlatformOpenApiExportCommandTest.php
index 9f45d875..b6fdedec 100644
--- a/Tests/Functional/Command/ApiPlatformOpenApiExportCommandTest.php
+++ b/Tests/Functional/Command/ApiPlatformOpenApiExportCommandTest.php
@@ -118,7 +118,13 @@ public function testCheckOpenApiExportCommand()
     "requestBodies": {},
     "responses": {},
     "schemas": {},
-    "securitySchemes": {}
+    "securitySchemes": {
+      "JWT": {
+        "bearerFormat": "JWT",
+        "scheme": "bearer",
+        "type": "http"
+      }
+    }
   },
   "security": [],
   "tags": []