Skip to content

Commit ad9b69b

Browse files
authored
Merge pull request #96 from php-api-clients/validate-webhook-body-before-attempting-to-hydrate-it
Validate webhook body before attempting to hydrate it
2 parents d2a6594 + a2d5bd1 commit ad9b69b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/Generator/WebHook.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,23 @@ public static function generate(string $namespace, string $event, SchemaRegistry
106106
'stmts' => [
107107
new Node\Stmt\TryCatch([
108108
...$headers,
109+
new Node\Stmt\Expression(new Node\Expr\MethodCall(
110+
new Node\Expr\PropertyFetch(
111+
new Node\Expr\Variable('this'),
112+
'requestSchemaValidator'
113+
),
114+
new Node\Name('validate'),
115+
[
116+
new Node\Arg(new Node\Expr\Variable('data')),
117+
new Node\Arg(new Node\Expr\StaticCall(new Node\Name('\cebe\openapi\Reader'), new Node\Name('readFromJson'), [
118+
new Node\Expr\ClassConstFetch(
119+
new Node\Name('Schema\\' . $schema->className),
120+
new Node\Name('SCHEMA_JSON'),
121+
),
122+
new Node\Scalar\String_('\cebe\openapi\spec\Schema'),
123+
])),
124+
]
125+
)),
109126
new Node\Stmt\Return_(new Node\Expr\MethodCall(
110127
new Node\Expr\PropertyFetch(
111128
new Node\Expr\Variable('this'),

0 commit comments

Comments
 (0)