Skip to content

Commit

Permalink
Response attribute takes precedence over doc block (#531)
Browse files Browse the repository at this point in the history
* The response attribute takes precedence over doc blocks

* update pipeline for cakephp 4.5

* pipeline cleanup
  • Loading branch information
cnizzardini authored Oct 17, 2023
1 parent d7321ee commit 5a62174
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ on:

jobs:
build:
name: PHP ${{ matrix.php-versions }} Test
runs-on: ubuntu-latest
strategy:
matrix:
operating-system: [ ubuntu-20.04 ]
php-versions: ['8.0', '8.1', '8.2']

name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down Expand Up @@ -58,10 +57,11 @@ jobs:
# CakePHP version compatability
#
compatibility:
name: CakePHP ${{ matrix.version }} Test
runs-on: ubuntu-latest
strategy:
matrix:
version: ['~4.2.0', '~4.3.0', '^4.4']
version: ['~4.2.0', '~4.3.0', '~4.4', '~4.5']
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
4 changes: 2 additions & 2 deletions src/Lib/Operation/OperationFromRouteFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ public function create(RouteDecorator $route, string $httpMethod, ?Schema $schem

$operation = $this->createOperation($operation, $route, $openApiOperation);

$operation = (new OperationDocBlock($this->swagger, $config, $operation, $docBlock))->getOperation();

$operation = (new OperationPathParameter($operation, $route, $refMethod, $schema))
->getOperationWithPathParameters();

Expand All @@ -119,6 +117,8 @@ public function create(RouteDecorator $route, string $httpMethod, ?Schema $schem
$refMethod,
))->getOperationWithResponses();

$operation = (new OperationDocBlock($this->swagger, $config, $operation, $docBlock))->getOperation();

EventManager::instance()->dispatch(
new Event('SwaggerBake.Operation.created', $operation, [
'config' => $config,
Expand Down
22 changes: 17 additions & 5 deletions tests/TestCase/Lib/Attribute/OpenApiOperationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,32 @@ public function setUp(): void
'isVisible' => [
'action' => 'isVisible',
'method' => 'GET',
'path' => 'is-visible'
'path' => 'is-visible',
],
'tagNames' => [
'action' => 'tagNames',
'method' => 'GET',
'path' => 'tag-names'
'path' => 'tag-names',
],
'deprecated' => [
'action' => 'deprecated',
'method' => 'GET',
'path' => 'deprecated'
'path' => 'deprecated',
],
'externalDocs' => [
'action' => 'externalDocs',
'method' => 'GET',
'path' => 'external-docs'
'path' => 'external-docs',
],
'descriptions' => [
'action' => 'descriptions',
'method' => 'GET',
'path' => 'descriptions'
'path' => 'descriptions',
],
'throwPrecedence' => [
'action' => 'throwPrecedence',
'method' => 'GET',
'path' => 'throw-precedence',
],
]
]);
Expand Down Expand Up @@ -127,4 +132,11 @@ public function test_path_tags_should_take_precedence(): void
$this->assertCount(2, $arr['paths']['/operations/deprecated']['get']['tags']);
$this->assertCount(2, $arr['paths']['/operations/external-docs']['get']['tags']);
}

public function test_response_attribute_takes_precedence_over_docblock_tag(): void
{
$arr = json_decode($this->swagger->toString(), true);
$response = $arr['paths']['/operations/throw-precedence']['get']['responses'][400];
$this->assertEquals('This should take precedence over throw tag', $response['description']);
}
}
11 changes: 11 additions & 0 deletions tests/test_app/src/Controller/OperationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use SwaggerBake\Lib\Attribute\OpenApiOperation;
use SwaggerBake\Lib\Attribute\OpenApiPath;
use SwaggerBake\Lib\Attribute\OpenApiResponse;

#[OpenApiPath(tags: ['Test', 'Another Test'])]
class OperationsController extends AppController
Expand Down Expand Up @@ -38,4 +39,14 @@ public function descriptions(): void
{

}

/**
* @link https://github.com/cnizzardini/cakephp-swagger-bake/issues/525
* @throws \Cake\Http\Exception\BadRequestException
*/
#[OpenApiResponse(schemaType: 'string', statusCode: '400', description: 'This should take precedence over throw tag')]
public function throwPrecedence()
{

}
}

0 comments on commit 5a62174

Please sign in to comment.