Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
DerManoMann committed Dec 4, 2023
1 parent 3b6b680 commit b25ac10
Show file tree
Hide file tree
Showing 17 changed files with 264 additions and 261 deletions.
41 changes: 16 additions & 25 deletions Examples/webhooks/OpenApiSpec.php
Original file line number Diff line number Diff line change
@@ -1,43 +1,34 @@
<?php
<?php declare(strict_types=1);

namespace OpenApi\Examples\Webhooks;

use OpenApi\Attributes as OAT;
use OpenApi\Annotations as OA;

#[OAT\OpenApi(
info: new OAT\Info(version: '1.0.0', title: 'Webhook Example'),
webhooks: [
new OAT\Webhook(
webhook: 'newPet',
path: new OAT\PathItem(

)
)
],
)]
/*
/**
* @OA\OpenApi(
* @OA\Info(
* version="1.0.0",
* title="Webhook Example",
* title="Webhook Example"
* ),
* webhooks={
* "newPet": @OA\PathItem(
* @OA\Webhook(
* webhook="newPet",
* @OA\PathItem(
* @OA\Post(
* @OA\RequestBody(
* description="Information about a new pet in the system",
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(ref="#/components/schemas/Pet")
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(ref="#/components/schemas/Pet")
* ),
* ),
* ),
* @OA\Response(
* response=200,
* description="Return a 200 status to indicate that the data was received successfully"
* @OA\Response(
* response=200,
* description="Return a 200 status to indicate that the data was received successfully"
* )
* )
* )
* )
* }
* )
* )
*/
class OpenApiSpec
Expand Down
34 changes: 23 additions & 11 deletions Examples/webhooks/Pet.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
<?php

declare(strict_types=1);
<?php declare(strict_types=1);

namespace OpenApi\Examples\Webhooks;

use OpenApi\Attributes as OAT;
use OpenApi\Annotations as OA;

#[OAT\Schema(required: ['id', 'name'])]
/**
* @OA\Schema(required={"id", "name"})
*/
final class Pet
{
#[OAT\Property(format: 'int64')]
public int $id;
/**
* @OA\Property(format="int64")
*
* @var int
*/
public $id;

#[OAT\Property]
public string $name;
/**
* @OA\Property
*
* @var string
*/
public $name;

#[OAT\Property]
public string $tag;
/**
* @OA\Property
*
* @var string
*/
public $tag;
}
12 changes: 11 additions & 1 deletion Examples/webhooks/webhooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,14 @@ components:
type: object
webhooks:
newPet:
path: { }
post:
operationId: 072580cbd56e3fef2b4c81536d3fd1c6
requestBody:
description: 'Information about a new pet in the system'
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
responses:
'200':
description: 'Return a 200 status to indicate that the data was received successfully'
31 changes: 0 additions & 31 deletions Examples/webhooks/xwebhooks.yaml

This file was deleted.

34 changes: 34 additions & 0 deletions Examples/webhooks81/OpenApiSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php declare(strict_types=1);

namespace OpenApi\Examples\Webhooks81;

use OpenApi\Attributes as OAT;

#[OAT\OpenApi(
info: new OAT\Info(version: '1.0.0', title: 'Webhook Example'),
webhooks: [
new OAT\Webhook(
webhook: 'newPet',
path: new OAT\PathItem(
post: new OAT\Post(
requestBody: new OAT\RequestBody(
description: 'Information about a new pet in the system',
content: new OAT\MediaType(
mediaType: 'application/json',
schema: new OAT\Schema(ref: Pet::class)
)
),
responses: [
new OAT\Response(
response: 200,
description: 'Return a 200 status to indicate that the data was received successfully'
),
]
)
)
),
],
)]
class OpenApiSpec
{
}
18 changes: 18 additions & 0 deletions Examples/webhooks81/Pet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php declare(strict_types=1);

namespace OpenApi\Examples\Webhooks81;

use OpenApi\Attributes as OAT;

#[OAT\Schema(required: ['id', 'name'])]
final class Pet
{
#[OAT\Property(format: 'int64')]
public int $id;

#[OAT\Property]
public string $name;

#[OAT\Property]
public string $tag;
}
32 changes: 32 additions & 0 deletions Examples/webhooks81/webhooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
openapi: 3.1.0
info:
title: 'Webhook Example'
version: 1.0.0
components:
schemas:
Pet:
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
type: object
webhooks:
newPet:
post:
operationId: bbbe318bf00166ae6ba3552197e5f089
requestBody:
description: 'Information about a new pet in the system'
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
responses:
'200':
description: 'Return a 200 status to indicate that the data was received successfully'
1 change: 0 additions & 1 deletion src/Annotations/Attachable.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class Attachable extends AbstractAnnotation
Post::class,
Property::class,
Put::class,
Reference::class,
RequestBody::class,
Response::class,
Schema::class,
Expand Down
2 changes: 0 additions & 2 deletions src/Annotations/OpenApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,6 @@ public function validate(array $stack = null, array $skip = null, string $ref =
/* paths is optional in 3.1.0 */
if ($this->openapi === self::VERSION_3_0_0 && Generator::isDefault($this->paths)) {
$this->_context->logger->warning('Required @OA\PathItem() not found');

return false;
}

if ($this->openapi === self::VERSION_3_1_0
Expand Down
56 changes: 0 additions & 56 deletions src/Annotations/Reference.php

This file was deleted.

33 changes: 23 additions & 10 deletions src/Annotations/Webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

use OpenApi\Generator;

/**
* @Annotation
*/
class Webhook extends AbstractAnnotation
{
/**
Expand All @@ -26,15 +29,6 @@ class Webhook extends AbstractAnnotation
*/
public $path = Generator::UNDEFINED;

/**
* The reference.
*
* Required unless `path` is set.
*
* @var Reference
*/
public $reference = Generator::UNDEFINED;

/**
* @inheritdoc
*/
Expand All @@ -47,7 +41,6 @@ class Webhook extends AbstractAnnotation
*/
public static $_nested = [
PathItem::class => 'path',
Reference::class => 'reference',
Attachable::class => ['attachables'],
];

Expand All @@ -57,4 +50,24 @@ class Webhook extends AbstractAnnotation
public static $_types = [
'webhook' => 'string',
];

/**
* @inheritdoc
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
$data = parent::jsonSerialize();

if (isset($data->path)) {
foreach (get_object_vars($data->path) as $property => $value) {
if ('_' != $property[0] && !Generator::isDefault($value)) {
$data->{$property} = $value;
}
}
unset($data->path);
}

return $data;
}
}
Loading

0 comments on commit b25ac10

Please sign in to comment.