Skip to content

Commit

Permalink
fix(openapi): webhook has pathItem
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Mar 21, 2024
1 parent 94d4a95 commit 23a9f2a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 32 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,8 @@ jobs:
node-version: '14'
- name: Validate OpenAPI documents
run: |
npx git+https://github.com/soyuka/swagger-cli#master validate build/out/openapi/openapi_v3.json
npx git+https://github.com/soyuka/swagger-cli#master validate build/out/openapi/openapi_v3.yaml
npx swagger-cli validate build/out/openapi/openapi_v3.json
npx swagger-cli validate build/out/openapi/openapi_v3.yaml
- name: Upload OpenAPI artifacts
if: always()
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -1212,8 +1212,8 @@ jobs:
node-version: '14'
- name: Validate OpenAPI documents
run: |
npx git+https://github.com/soyuka/swagger-cli#master validate build/out/openapi/openapi_v3.json
npx git+https://github.com/soyuka/swagger-cli#master validate build/out/openapi/openapi_v3.yaml
npx swagger-cli validate build/out/openapi/openapi_v3.json
npx swagger-cli validate build/out/openapi/openapi_v3.yaml
- name: Upload OpenAPI artifacts
if: always()
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -1281,8 +1281,8 @@ jobs:
node-version: '14'
- name: Validate OpenAPI documents
run: |
npx git+https://github.com/soyuka/swagger-cli#master validate build/out/openapi/openapi_v3.json
npx git+https://github.com/soyuka/swagger-cli#master validate build/out/openapi/openapi_v3.yaml
npx swagger-cli validate build/out/openapi/openapi_v3.json
npx swagger-cli validate build/out/openapi/openapi_v3.yaml
- name: Upload OpenAPI artifacts
if: always()
uses: actions/upload-artifact@v4
Expand Down
4 changes: 2 additions & 2 deletions features/openapi/docs.feature
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ Feature: Documentation support
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}"

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

# Subcollection - check filter on subResource
And the JSON node "paths./related_dummies/{id}/related_to_dummy_friends.get.parameters[0].name" should be equal to "id"
Expand Down
5 changes: 1 addition & 4 deletions src/OpenApi/Factory/OpenApiFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,7 @@ private function collectPaths(ApiResource $resource, ResourceMetadataCollection
}

if ($openapiAttribute instanceof Webhook) {
if (!isset($webhooks[$openapiAttribute->getName()])) {
$webhooks[$openapiAttribute->getName()] = new \ArrayObject();
}
$webhooks[$openapiAttribute->getName()]->append($pathItem->{'with'.ucfirst($method)}($openapiOperation));
$webhooks[$openapiAttribute->getName()] = $pathItem->{'with'.ucfirst($method)}($openapiOperation);
} else {
$paths->addPath($path, $pathItem->{'with'.ucfirst($method)}($openapiOperation));
}
Expand Down
12 changes: 4 additions & 8 deletions src/OpenApi/Tests/Factory/OpenApiFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function testInvoke(): void
'class' => OutputDto::class,
])->withPaginationClientItemsPerPage(true)->withShortName('Dummy')->withDescription('This is a dummy');
$dummyResourceWebhook = (new ApiResource())->withOperations(new Operations([
'dummy webhook' => (new Get())->withUriTemplate('/dummy/{id}')->withShortName('short')->withOpenapi(new Webhook('happy webhook')),
'dummy webhook' => (new Get())->withUriTemplate('/dummy/{id}')->withShortName('short')->withOpenapi(new Webhook('first webhook')),
'an other dummy webhook' => (new Post())->withUriTemplate('/dummies')->withShortName('short something')->withOpenapi(new Webhook('happy webhook', new Model\PathItem(post: new Operation(
summary: 'well...',
description: 'I dont\'t know what to say',
Expand Down Expand Up @@ -492,14 +492,10 @@ public function testInvoke(): void
$this->assertEquals($openApi->getServers(), [new Server('/app_dev.php/')]);

$webhooks = $openApi->getWebhooks();
$this->assertCount(1, $webhooks);

$this->assertNotNull($webhooks['happy webhook']);
$this->assertCount(2, $webhooks['happy webhook']);

$firstOperationWebhook = $webhooks['happy webhook'][0];
$secondOperationWebhook = $webhooks['happy webhook'][1];
$this->assertCount(2, $webhooks);

$firstOperationWebhook = $webhooks['first webhook'];
$secondOperationWebhook = $webhooks['happy webhook'];
$this->assertSame('dummy webhook', $firstOperationWebhook->getGet()->getOperationId());
$this->assertSame('an other dummy webhook', $secondOperationWebhook->getPost()->getOperationId());
$this->assertSame('I dont\'t know what to say', $secondOperationWebhook->getPost()->getDescription());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,25 @@

declare(strict_types=1);

namespace ApiPlatform\Tests\Fixtures\TestBundle\Entity;
namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource;

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\Post;
use ApiPlatform\OpenApi\Attributes\Webhook;
use ApiPlatform\OpenApi\Model\Operation;
use ApiPlatform\OpenApi\Model\PathItem;
use Doctrine\ORM\Mapping as ORM;

#[ApiResource(operations: [new Get(openapi: new Webhook(
name: 'webhook',
name: 'a',
pathItem: new PathItem(
get: new Operation(
summary: 'Something else here',
description: 'Something else here for example',
),
)
)), new Post(openapi: new Webhook(
name: 'webhook',
name: 'b',
pathItem: new PathItem(
post: new Operation(
summary: 'Something else here',
Expand All @@ -39,14 +38,7 @@
)
)),
])]
#[ORM\Entity]
class DummyWebhook
{
/**
* @var int|null The id
*/
#[ORM\Column(type: 'integer', nullable: true)]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
private $id;
public $id;
}

0 comments on commit 23a9f2a

Please sign in to comment.