Skip to content

Commit

Permalink
OpenAPI: fix #3920 security scheme (#3927)
Browse files Browse the repository at this point in the history
* OpenAPI: fix #3920 security scheme

* Fix 5.2 yaml tests
  • Loading branch information
soyuka committed Jan 2, 2021
1 parent 91e4b18 commit 3d8449a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/OpenApi/Factory/OpenApiFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ private function getSecuritySchemes(): array

foreach ($this->openApiOptions->getApiKeys() as $key => $apiKey) {
$description = sprintf('Value for the %s %s parameter.', $apiKey['name'], $apiKey['type']);
$securitySchemes[$key] = new Model\SecurityScheme('apiKey', $description, $apiKey['name'], $apiKey['type'], 'bearer');
$securitySchemes[$key] = new Model\SecurityScheme('apiKey', $description, $apiKey['name'], $apiKey['type']);
}

return $securitySchemes;
Expand Down
2 changes: 1 addition & 1 deletion src/OpenApi/Model/SecurityScheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function getIn(): ?string
return $this->in;
}

public function getScheme(): string
public function getScheme(): ?string
{
return $this->scheme;
}
Expand Down
8 changes: 6 additions & 2 deletions tests/Bridge/Symfony/Bundle/Command/OpenApiCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,16 @@ public function testExecuteWithYaml()
$expected = <<<YAML
info:
title: 'My Dummy API'
description: |
YAML;
$this->assertStringContainsString(str_replace(PHP_EOL, "\n", $expected), $result, 'multiline formatting must be preserved (using literal style).');

$expected = <<<YAML
This is a test API.
Made with love
version: 0.0.0
YAML;
$this->assertStringContainsString(str_replace(PHP_EOL, "\n", $expected), $result, 'multiline formatting must be preserved (using literal style).');

$this->assertStringContainsString(str_replace(PHP_EOL, "\n", $expected), $result);
}

public function testWriteToFile()
Expand Down
8 changes: 6 additions & 2 deletions tests/Bridge/Symfony/Bundle/Command/SwaggerCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,15 @@ public function testExecuteWithYamlVersion3()
info:
title: 'My Dummy API'
version: 0.0.0
description: |
YAML;
$this->assertStringContainsString(str_replace(PHP_EOL, "\n", $expected), $result, 'multiline formatting must be preserved (using literal style).');

$expected = <<<YAML
This is a test API.
Made with love
YAML;
$this->assertStringContainsString(str_replace(PHP_EOL, "\n", $expected), $result, 'multiline formatting must be preserved (using literal style).');

$this->assertStringContainsString(str_replace(PHP_EOL, "\n", $expected), $result);
}

public function testExecuteWithBadArguments()
Expand Down
4 changes: 2 additions & 2 deletions tests/OpenApi/Factory/OpenApiFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ public function testInvoke(): void

$this->assertEquals($components->getSecuritySchemes(), new \ArrayObject([
'oauth' => new Model\SecurityScheme('oauth2', 'OAuth 2.0 authorization code Grant', null, null, 'oauth2', null, new Model\OAuthFlows(null, null, null, new Model\OAuthFlow('/oauth/v2/auth', '/oauth/v2/token', '/oauth/v2/refresh', new \ArrayObject(['scope param'])))),
'header' => new Model\SecurityScheme('apiKey', 'Value for the Authorization header parameter.', 'Authorization', 'header', 'bearer'),
'query' => new Model\SecurityScheme('apiKey', 'Value for the key query parameter.', 'key', 'query', 'bearer'),
'header' => new Model\SecurityScheme('apiKey', 'Value for the Authorization header parameter.', 'Authorization', 'header'),
'query' => new Model\SecurityScheme('apiKey', 'Value for the key query parameter.', 'key', 'query'),
]));

$paths = $openApi->getPaths();
Expand Down

0 comments on commit 3d8449a

Please sign in to comment.