Skip to content

Commit 23a9f2a

Browse files
committed
fix(openapi): webhook has pathItem
1 parent 94d4a95 commit 23a9f2a

File tree

5 files changed

+17
-32
lines changed

5 files changed

+17
-32
lines changed

.github/workflows/ci.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,8 @@ jobs:
383383
node-version: '14'
384384
- name: Validate OpenAPI documents
385385
run: |
386-
npx git+https://github.com/soyuka/swagger-cli#master validate build/out/openapi/openapi_v3.json
387-
npx git+https://github.com/soyuka/swagger-cli#master validate build/out/openapi/openapi_v3.yaml
386+
npx swagger-cli validate build/out/openapi/openapi_v3.json
387+
npx swagger-cli validate build/out/openapi/openapi_v3.yaml
388388
- name: Upload OpenAPI artifacts
389389
if: always()
390390
uses: actions/upload-artifact@v4
@@ -1212,8 +1212,8 @@ jobs:
12121212
node-version: '14'
12131213
- name: Validate OpenAPI documents
12141214
run: |
1215-
npx git+https://github.com/soyuka/swagger-cli#master validate build/out/openapi/openapi_v3.json
1216-
npx git+https://github.com/soyuka/swagger-cli#master validate build/out/openapi/openapi_v3.yaml
1215+
npx swagger-cli validate build/out/openapi/openapi_v3.json
1216+
npx swagger-cli validate build/out/openapi/openapi_v3.yaml
12171217
- name: Upload OpenAPI artifacts
12181218
if: always()
12191219
uses: actions/upload-artifact@v4
@@ -1281,8 +1281,8 @@ jobs:
12811281
node-version: '14'
12821282
- name: Validate OpenAPI documents
12831283
run: |
1284-
npx git+https://github.com/soyuka/swagger-cli#master validate build/out/openapi/openapi_v3.json
1285-
npx git+https://github.com/soyuka/swagger-cli#master validate build/out/openapi/openapi_v3.yaml
1284+
npx swagger-cli validate build/out/openapi/openapi_v3.json
1285+
npx swagger-cli validate build/out/openapi/openapi_v3.yaml
12861286
- name: Upload OpenAPI artifacts
12871287
if: always()
12881288
uses: actions/upload-artifact@v4

features/openapi/docs.feature

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ Feature: Documentation support
117117
And the JSON node "paths./dummy_cars.get.parameters[8].description" should be equal to "Allows you to reduce the response to contain only the properties you need. If your desired property is nested, you can address it using nested arrays. Example: foobar[]={propertyName}&foobar[]={anotherPropertyName}&foobar[{nestedPropertyParent}][]={nestedProperty}"
118118

119119
# Webhook
120-
And the JSON node "webhooks.webhook[0].get.description" should be equal to "Something else here for example"
121-
And the JSON node "webhooks.webhook[1].post.description" should be equal to "Hi! it's me, I'm the problem, it's me"
120+
And the JSON node "webhooks.a.get.description" should be equal to "Something else here for example"
121+
And the JSON node "webhooks.b.post.description" should be equal to "Hi! it's me, I'm the problem, it's me"
122122

123123
# Subcollection - check filter on subResource
124124
And the JSON node "paths./related_dummies/{id}/related_to_dummy_friends.get.parameters[0].name" should be equal to "id"

src/OpenApi/Factory/OpenApiFactory.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,7 @@ private function collectPaths(ApiResource $resource, ResourceMetadataCollection
405405
}
406406

407407
if ($openapiAttribute instanceof Webhook) {
408-
if (!isset($webhooks[$openapiAttribute->getName()])) {
409-
$webhooks[$openapiAttribute->getName()] = new \ArrayObject();
410-
}
411-
$webhooks[$openapiAttribute->getName()]->append($pathItem->{'with'.ucfirst($method)}($openapiOperation));
408+
$webhooks[$openapiAttribute->getName()] = $pathItem->{'with'.ucfirst($method)}($openapiOperation);
412409
} else {
413410
$paths->addPath($path, $pathItem->{'with'.ucfirst($method)}($openapiOperation));
414411
}

src/OpenApi/Tests/Factory/OpenApiFactoryTest.php

+4-8
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function testInvoke(): void
8181
'class' => OutputDto::class,
8282
])->withPaginationClientItemsPerPage(true)->withShortName('Dummy')->withDescription('This is a dummy');
8383
$dummyResourceWebhook = (new ApiResource())->withOperations(new Operations([
84-
'dummy webhook' => (new Get())->withUriTemplate('/dummy/{id}')->withShortName('short')->withOpenapi(new Webhook('happy webhook')),
84+
'dummy webhook' => (new Get())->withUriTemplate('/dummy/{id}')->withShortName('short')->withOpenapi(new Webhook('first webhook')),
8585
'an other dummy webhook' => (new Post())->withUriTemplate('/dummies')->withShortName('short something')->withOpenapi(new Webhook('happy webhook', new Model\PathItem(post: new Operation(
8686
summary: 'well...',
8787
description: 'I dont\'t know what to say',
@@ -492,14 +492,10 @@ public function testInvoke(): void
492492
$this->assertEquals($openApi->getServers(), [new Server('/app_dev.php/')]);
493493

494494
$webhooks = $openApi->getWebhooks();
495-
$this->assertCount(1, $webhooks);
496-
497-
$this->assertNotNull($webhooks['happy webhook']);
498-
$this->assertCount(2, $webhooks['happy webhook']);
499-
500-
$firstOperationWebhook = $webhooks['happy webhook'][0];
501-
$secondOperationWebhook = $webhooks['happy webhook'][1];
495+
$this->assertCount(2, $webhooks);
502496

497+
$firstOperationWebhook = $webhooks['first webhook'];
498+
$secondOperationWebhook = $webhooks['happy webhook'];
503499
$this->assertSame('dummy webhook', $firstOperationWebhook->getGet()->getOperationId());
504500
$this->assertSame('an other dummy webhook', $secondOperationWebhook->getPost()->getOperationId());
505501
$this->assertSame('I dont\'t know what to say', $secondOperationWebhook->getPost()->getDescription());

tests/Fixtures/TestBundle/Entity/DummyWebhook.php renamed to tests/Fixtures/TestBundle/ApiResource/DummyWebhook.php

+4-12
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,25 @@
1111

1212
declare(strict_types=1);
1313

14-
namespace ApiPlatform\Tests\Fixtures\TestBundle\Entity;
14+
namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource;
1515

1616
use ApiPlatform\Metadata\ApiResource;
1717
use ApiPlatform\Metadata\Get;
1818
use ApiPlatform\Metadata\Post;
1919
use ApiPlatform\OpenApi\Attributes\Webhook;
2020
use ApiPlatform\OpenApi\Model\Operation;
2121
use ApiPlatform\OpenApi\Model\PathItem;
22-
use Doctrine\ORM\Mapping as ORM;
2322

2423
#[ApiResource(operations: [new Get(openapi: new Webhook(
25-
name: 'webhook',
24+
name: 'a',
2625
pathItem: new PathItem(
2726
get: new Operation(
2827
summary: 'Something else here',
2928
description: 'Something else here for example',
3029
),
3130
)
3231
)), new Post(openapi: new Webhook(
33-
name: 'webhook',
32+
name: 'b',
3433
pathItem: new PathItem(
3534
post: new Operation(
3635
summary: 'Something else here',
@@ -39,14 +38,7 @@
3938
)
4039
)),
4140
])]
42-
#[ORM\Entity]
4341
class DummyWebhook
4442
{
45-
/**
46-
* @var int|null The id
47-
*/
48-
#[ORM\Column(type: 'integer', nullable: true)]
49-
#[ORM\Id]
50-
#[ORM\GeneratedValue(strategy: 'AUTO')]
51-
private $id;
43+
public $id;
5244
}

0 commit comments

Comments
 (0)