Skip to content

Commit

Permalink
feature #1159 Added: JWT security scheme to openapi (Ninos)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.x branch.

Discussion
----------

Added: JWT security scheme to openapi

After that it's possible to add token in swagger ui without defining `Bearer` prefix.

PS: Currently there's a bug with `$checkPath`, `$usernamePath` & `$passwordPath`. If you're using route names instead of paths, in swagger ui/docs you get `POST auth` instead of `POST /auth`, so you cannot validate via swagger ui. I haven't found an elegant way to load `GeneratorInterface` service :/

Commits
-------

1e82b22 Added: JWT security scheme to openapi
  • Loading branch information
chalasr committed Nov 30, 2023
2 parents 5c9bcac + 1e82b22 commit 6b7397a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
11 changes: 11 additions & 0 deletions OpenApi/OpenApiFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,13 @@ public function testCheckOpenApiExportCommand()
"requestBodies": {},
"responses": {},
"schemas": {},
"securitySchemes": {}
"securitySchemes": {
"JWT": {
"bearerFormat": "JWT",
"scheme": "bearer",
"type": "http"
}
}
},
"security": [],
"tags": []
Expand Down

0 comments on commit 6b7397a

Please sign in to comment.