Skip to content

Commit

Permalink
feature/add-callbacks-to-operation (#38)
Browse files Browse the repository at this point in the history
Author: @vyuldashev 

* MediaType application/x-www-form-urlencoded

* add docblock

* #15 Extensions support

* #15 BaseObject getter for extension

* #15 BaseObject getter for all extensions

* #15 Extensions object, add readme for extensions

* resolve conflicts

* fix code style

* add callbacks to Operation
  • Loading branch information
vyuldashev authored and matthew-inamdar committed Nov 14, 2019
1 parent bd5f660 commit 0438a3c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/Objects/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ class Operation extends BaseObject
*/
protected $servers;

/**
* @var \GoldSpecDigital\ObjectOrientedOAS\Objects\PathItem[]|null
*/
protected $callbacks;

/**
* @param string|null $objectId
* @return \GoldSpecDigital\ObjectOrientedOAS\Objects\Operation
Expand Down Expand Up @@ -352,6 +357,19 @@ public function servers(Server ...$servers): self
return $instance;
}

/**
* @param \GoldSpecDigital\ObjectOrientedOAS\Objects\PathItem[] $callbacks
* @return $this
*/
public function callbacks(PathItem ...$callbacks): self
{
$instance = clone $this;

$instance->callbacks = $callbacks ?: null;

return $instance;
}

/**
* @return array
*/
Expand All @@ -362,6 +380,11 @@ protected function generate(): array
$responses[$response->statusCode ?? 'default'] = $response;
}

$callbacks = [];
foreach ($this->callbacks ?? [] as $callback) {
$callbacks[$callback->objectId] = $callback;
}

return Arr::filter([
'tags' => $this->tags,
'summary' => $this->summary,
Expand All @@ -374,6 +397,7 @@ protected function generate(): array
'deprecated' => $this->deprecated,
'security' => $this->noSecurity ? [] : $this->security,
'servers' => $this->servers,
'callbacks' => $callbacks ?: null,
]);
}
}
21 changes: 20 additions & 1 deletion tests/Objects/OperationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ public function create_with_all_parameters_works()
$securityScheme = SecurityScheme::create('OAuth2')
->type(SecurityScheme::TYPE_OAUTH2);

$callback = PathItem::create('MyEvent')
->route('{$request.query.callbackUrl}')
->operations(
Operation::post()->requestBody(
RequestBody::create()
->description('something happened')
)
);

$operation = Operation::create()
->action(Operation::ACTION_GET)
->tags(Tag::create()->name('Users'))
Expand All @@ -36,7 +45,8 @@ public function create_with_all_parameters_works()
->responses(Response::create())
->deprecated()
->security(SecurityRequirement::create()->securityScheme($securityScheme))
->servers(Server::create());
->servers(Server::create())
->callbacks($callback);

$pathItem = PathItem::create()
->operations($operation);
Expand Down Expand Up @@ -64,6 +74,15 @@ public function create_with_all_parameters_works()
'servers' => [
[],
],
'callbacks' => [
'MyEvent' => [
'post' => [
'requestBody' => [
'description' => 'something happened',
],
],
],
],
],
], $pathItem->toArray());
}
Expand Down

0 comments on commit 0438a3c

Please sign in to comment.