forked from zircote/swagger-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for OpenApi 3.1.0 Webhooks (zircote#1511)
- Loading branch information
1 parent
8ea52e3
commit 5087638
Showing
16 changed files
with
443 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace OpenApi\Examples\Webhooks; | ||
|
||
use OpenApi\Annotations as OA; | ||
|
||
/** | ||
* @OA\OpenApi( | ||
* @OA\Info( | ||
* version="1.0.0", | ||
* title="Webhook Example" | ||
* ), | ||
* @OA\Webhook( | ||
* webhook="newPet", | ||
* @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\Response( | ||
* response=200, | ||
* description="Return a 200 status to indicate that the data was received successfully" | ||
* ) | ||
* ) | ||
* ) | ||
* ) | ||
* ) | ||
*/ | ||
class OpenApiSpec | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace OpenApi\Examples\Webhooks; | ||
|
||
use OpenApi\Annotations as OA; | ||
|
||
/** | ||
* @OA\Schema(required={"id", "name"}) | ||
*/ | ||
final class Pet | ||
{ | ||
/** | ||
* @OA\Property(format="int64") | ||
* | ||
* @var int | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* @OA\Property | ||
* | ||
* @var string | ||
*/ | ||
public $name; | ||
|
||
/** | ||
* @OA\Property | ||
* | ||
* @var string | ||
*/ | ||
public $tag; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: 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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?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', | ||
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 | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/** | ||
* @license Apache 2.0 | ||
*/ | ||
|
||
namespace OpenApi\Annotations; | ||
|
||
use OpenApi\Generator; | ||
|
||
/** | ||
* Acts like a `PathItem` with the main difference being that it requires `webhook` instead of `path`. | ||
* | ||
* @Annotation | ||
*/ | ||
class Webhook extends PathItem | ||
{ | ||
/** | ||
* Key for the webhooks map. | ||
* | ||
* @var string | ||
*/ | ||
public $webhook = Generator::UNDEFINED; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public static $_required = ['webhook']; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public static $_parents = [ | ||
OpenApi::class, | ||
]; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public static $_types = [ | ||
'webhook' => 'string', | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.