Skip to content

Commit 9c30903

Browse files
authored
Merge pull request #39 from php-api-clients/house-webhook-related-files
House webhook related files
2 parents 3c99df5 + 1de0622 commit 9c30903

File tree

9 files changed

+1425
-53
lines changed

9 files changed

+1425
-53
lines changed

composer.json

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
},
2121
"require": {
2222
"php": "^7.4",
23-
"cebe/php-openapi": "dev-webhooks as 1.6.0",
23+
"cebe/php-openapi": "^1.5",
2424
"jawira/case-converter": "^3.4",
2525
"twig/twig": "^3.0",
2626
"nikic/php-parser": "^4.8",
@@ -29,23 +29,22 @@
2929
"symfony/yaml": "^5.2",
3030
"wyrihaximus/composer-update-bin-autoload-path": "^1 || ^1.0.1",
3131
"wyrihaximus/hydrator": "dev-master",
32-
"league/openapi-psr7-validator": "dev-webhooks as 0.16.99"
32+
"league/openapi-psr7-validator": "^0.16"
3333
},
3434
"autoload": {
3535
"psr-4": {
3636
"ApiClients\\Tools\\OpenApiClientGenerator\\": "src/"
37-
}
38-
},
39-
"repositories": [
40-
{
41-
"type": "vcs",
42-
"url": "[email protected]:WyriHaximus-labs/php-openapi.git"
4337
},
44-
{
45-
"type": "vcs",
46-
"url": "[email protected]:WyriHaximus-labs/openapi-psr7-validator.git"
47-
}
48-
],
38+
"files": [
39+
"external_files/cebe/SpecBaseObject.php",
40+
"external_files/cebe/OpenApi.php",
41+
"external_files/cebe/Schema.php",
42+
"external_files/cebe/Type.php",
43+
"external_files/cebe/WebHooks.php",
44+
"external_files/thephpleague/SchemaValidator.php",
45+
"external_files/thephpleague/Type.php"
46+
]
47+
},
4948
"config": {
5049
"platform": {
5150
"php": "7.4.7"

composer.lock

Lines changed: 23 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

external_files/cebe/OpenApi.php

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (c) 2018 Carsten Brandt <[email protected]> and contributors
5+
* @license https://github.com/cebe/php-openapi/blob/master/LICENSE
6+
*/
7+
8+
namespace cebe\openapi\spec;
9+
10+
use cebe\openapi\exceptions\TypeErrorException;
11+
use cebe\openapi\SpecBaseObject;
12+
13+
/**
14+
* This is the root document object of the OpenAPI document.
15+
*
16+
* @link https://github.com/OAI/OpenAPI-Specification/blob/3.0.2/versions/3.0.2.md#openapi-object
17+
*
18+
* @property string $openapi
19+
* @property Info $info
20+
* @property Server[] $servers
21+
* @property Paths|PathItem[] $paths
22+
* @property Components|null $components
23+
* @property WebHooks|null $webhooks
24+
* @property SecurityRequirement[] $security
25+
* @property Tag[] $tags
26+
* @property ExternalDocumentation|null $externalDocs
27+
*
28+
*/
29+
class OpenApi extends SpecBaseObject
30+
{
31+
/**
32+
* @return array array of attributes available in this object.
33+
*/
34+
protected function attributes(): array
35+
{
36+
return [
37+
'openapi' => Type::STRING,
38+
'info' => Info::class,
39+
'servers' => [Server::class],
40+
'paths' => Paths::class,
41+
'webhooks' => WebHooks::class,
42+
'components' => Components::class,
43+
'security' => [SecurityRequirement::class],
44+
'tags' => [Tag::class],
45+
'externalDocs' => ExternalDocumentation::class,
46+
];
47+
}
48+
49+
/**
50+
* @return array array of attributes default values.
51+
*/
52+
protected function attributeDefaults(): array
53+
{
54+
return [
55+
// Spec: If the servers property is not provided, or is an empty array,
56+
// the default value would be a Server Object with a url value of /.
57+
'servers' => [
58+
new Server(['url' => '/'])
59+
],
60+
];
61+
}
62+
63+
public function __get($name)
64+
{
65+
$ret = parent::__get($name);
66+
// Spec: If the servers property is not provided, or is an empty array,
67+
// the default value would be a Server Object with a url value of /.
68+
if ($name === 'servers' && $ret === []) {
69+
return $this->attributeDefaults()['servers'];
70+
}
71+
return $ret;
72+
}
73+
74+
/**
75+
* Perform validation on this object, check data against OpenAPI Specification rules.
76+
*/
77+
public function performValidation()
78+
{
79+
$this->requireProperties(['openapi', 'info'], ['paths', 'webhooks']);
80+
if (!empty($this->openapi) && !preg_match('/^3\.(0|1)\.\d+(-rc\d)?$/i', $this->openapi)) {
81+
$this->addError('Unsupported openapi version: ' . $this->openapi);
82+
}
83+
}
84+
}

0 commit comments

Comments
 (0)