Skip to content

Commit 76722a7

Browse files
authored
OpenAPI: default to v2 (#2408)
* OpenAPI: default to v2 * default export command to v2 and fix test
1 parent 8435f25 commit 76722a7

File tree

7 files changed

+16
-16
lines changed

7 files changed

+16
-16
lines changed

features/openapi/docs.feature

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Feature: Documentation support
55

66
@createSchema
77
Scenario: Retrieve the OpenAPI documentation
8-
Given I send a "GET" request to "/docs.json"
8+
Given I send a "GET" request to "/docs.json?spec_version=3"
99
Then the response status code should be 200
1010
And the response should be in JSON
1111
And the header "Content-Type" should be equal to "application/json; charset=utf-8"
@@ -89,15 +89,15 @@ Feature: Documentation support
8989

9090
Scenario: OpenAPI UI is enabled for docs endpoint
9191
Given I add "Accept" header equal to "text/html"
92-
And I send a "GET" request to "/docs"
92+
And I send a "GET" request to "/docs?spec_version=3"
9393
Then the response status code should be 200
9494
And I should see text matching "My Dummy API"
9595
And I should see text matching "openapi"
9696
And I should see text matching "3.0.2"
9797

9898
Scenario: OpenAPI UI is enabled for an arbitrary endpoint
9999
Given I add "Accept" header equal to "text/html"
100-
And I send a "GET" request to "/dummies"
100+
And I send a "GET" request to "/dummies?spec_version=3"
101101
Then the response status code should be 200
102102
And I should see text matching "openapi"
103103
And I should see text matching "3.0.2"

features/swagger/docs.feature

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Feature: Documentation support
55

66
@createSchema
77
Scenario: Retrieve the Swagger/OpenAPI documentation
8-
Given I send a "GET" request to "/docs.json?spec_version=2"
8+
Given I send a "GET" request to "/docs.json"
99
Then the response status code should be 200
1010
And the response should be in JSON
1111
And the header "Content-Type" should be equal to "application/json; charset=utf-8"
@@ -89,15 +89,15 @@ Feature: Documentation support
8989

9090
Scenario: Swagger UI is enabled for docs endpoint
9191
Given I add "Accept" header equal to "text/html"
92-
And I send a "GET" request to "/docs?spec_version=2"
92+
And I send a "GET" request to "/docs"
9393
Then the response status code should be 200
9494
And I should see text matching "My Dummy API"
9595
And I should see text matching "swagger"
9696
And I should see text matching "2.0"
9797

9898
Scenario: Swagger UI is enabled for an arbitrary endpoint
9999
Given I add "Accept" header equal to "text/html"
100-
And I send a "GET" request to "/dummies?spec_version=2"
100+
And I send a "GET" request to "/dummies"
101101
Then the response status code should be 200
102102
And I should see text matching "My Dummy API"
103103
And I should see text matching "swagger"

src/Bridge/Symfony/Bundle/Action/SwaggerUiAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ private function getContext(Request $request, Documentation $documentation): arr
124124
'graphqlEnabled' => $this->graphqlEnabled,
125125
];
126126

127-
$swaggerContext = ['spec_version' => $request->query->getInt('spec_version', 3)];
127+
$swaggerContext = ['spec_version' => $request->query->getInt('spec_version', 2)];
128128
if ('' !== $baseUrl = $request->getBaseUrl()) {
129129
$swaggerContext['base_url'] = $baseUrl;
130130
}

src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ protected function configure()
6161
->setAliases(['api:swagger:export'])
6262
->setDescription('Dump the OpenAPI documentation')
6363
->addOption('yaml', 'y', InputOption::VALUE_NONE, 'Dump the documentation in YAML')
64-
->addOption('spec-version', null, InputOption::VALUE_OPTIONAL, 'OpenAPI version to use ("2" or "3")', '3')
64+
->addOption('spec-version', null, InputOption::VALUE_OPTIONAL, 'OpenAPI version to use ("2" or "3")', '2')
6565
->addOption('output', 'o', InputOption::VALUE_OPTIONAL, 'Write output to file');
6666
}
6767

src/Documentation/Action/DocumentationAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function __construct(ResourceNameCollectionFactoryInterface $resourceName
6262
public function __invoke(Request $request = null): Documentation
6363
{
6464
if (null !== $request) {
65-
$context = ['base_url' => $request->getBaseUrl(), 'spec_version' => $request->query->getInt('spec_version', 3)];
65+
$context = ['base_url' => $request->getBaseUrl(), 'spec_version' => $request->query->getInt('spec_version', 2)];
6666
if ($request->query->getBoolean('api_gateway', false)) {
6767
$context['api_gateway'] = true;
6868
}

tests/Bridge/Symfony/Bundle/Command/SwaggerCommandTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,23 @@ protected function setUp()
4141
$this->tester = new ApplicationTester($application);
4242
}
4343

44-
public function testExecuteWithAlias()
44+
public function testExecuteWithAliasVersion3()
4545
{
46-
$this->tester->run(['command' => 'api:swagger:export']);
46+
$this->tester->run(['command' => 'api:swagger:export', '--spec-version' => '3']);
4747

4848
$this->assertJson($this->tester->getDisplay());
4949
}
5050

5151
public function testExecuteOpenApiVersion2()
5252
{
53-
$this->tester->run(['command' => 'api:openapi:export', '--spec-version' => '2']);
53+
$this->tester->run(['command' => 'api:openapi:export']);
5454

5555
$this->assertJson($this->tester->getDisplay());
5656
}
5757

58-
public function testExecuteWithYaml()
58+
public function testExecuteWithYamlVersion3()
5959
{
60-
$this->tester->run(['command' => 'api:swagger:export', '--yaml' => true]);
60+
$this->tester->run(['command' => 'api:swagger:export', '--yaml' => true, '--spec-version' => '3']);
6161

6262
$result = $this->tester->getDisplay();
6363
$this->assertYaml($result);
@@ -85,7 +85,7 @@ public function testExecuteWithYaml()
8585

8686
public function testExecuteOpenApiVersion2WithYaml()
8787
{
88-
$this->tester->run(['command' => 'api:openapi:export', '--spec-version' => '2', '--yaml' => true]);
88+
$this->tester->run(['command' => 'api:openapi:export', '--yaml' => true]);
8989

9090
$result = $this->tester->getDisplay();
9191
$this->assertYaml($result);

tests/Documentation/Action/DocumentationActionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function testDocumentationAction()
4040
$requestProphecy->query = $queryProphecy->reveal();
4141
$requestProphecy->getBaseUrl()->willReturn('/api')->shouldBeCalledTimes(1);
4242
$queryProphecy->getBoolean('api_gateway', false)->willReturn(true)->shouldBeCalledTimes(1);
43-
$queryProphecy->getInt('spec_version', 3)->willReturn(2)->shouldBeCalledTimes(1);
43+
$queryProphecy->getInt('spec_version', 2)->willReturn(2)->shouldBeCalledTimes(1);
4444
$attributesProphecy->all()->willReturn(['_api_normalization_context' => ['foo' => 'bar', 'base_url' => '/api', 'api_gateway' => true, 'spec_version' => 2]])->shouldBeCalledTimes(1);
4545
$attributesProphecy->get('_api_normalization_context', [])->willReturn(['foo' => 'bar'])->shouldBeCalledTimes(1);
4646
$attributesProphecy->set('_api_normalization_context', ['foo' => 'bar', 'base_url' => '/api', 'api_gateway' => true, 'spec_version' => 2])->shouldBeCalledTimes(1);

0 commit comments

Comments
 (0)