From 38c86b061f7d7a44cbca28b4e5f7d78541f3732a Mon Sep 17 00:00:00 2001 From: Garrett Grimm Date: Sat, 22 Oct 2022 18:38:59 -0700 Subject: [PATCH 1/6] Implement JsonSerializable on OpenApi class --- src/spec/OpenApi.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/spec/OpenApi.php b/src/spec/OpenApi.php index 29d38b3..6ec0342 100644 --- a/src/spec/OpenApi.php +++ b/src/spec/OpenApi.php @@ -9,6 +9,8 @@ use cebe\openapi\exceptions\TypeErrorException; use cebe\openapi\SpecBaseObject; +use cebe\openapi\Writer; +use \JsonSerializable; /** * This is the root document object of the OpenAPI document. @@ -25,7 +27,7 @@ * @property ExternalDocumentation|null $externalDocs * */ -class OpenApi extends SpecBaseObject +class OpenApi extends SpecBaseObject implements JsonSerializable { /** * @return array array of attributes available in this object. @@ -79,4 +81,8 @@ public function performValidation() $this->addError('Unsupported openapi version: ' . $this->openapi); } } + + public function jsonSerialize() { + return Writer::writeToJson($this); + } } From 400221eb29a2d3850d4bf7ca5bf7495d24498dd3 Mon Sep 17 00:00:00 2001 From: Garrett Grimm Date: Sat, 22 Oct 2022 18:44:34 -0700 Subject: [PATCH 2/6] Use getSerializableData() instead --- src/spec/OpenApi.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/spec/OpenApi.php b/src/spec/OpenApi.php index 6ec0342..abf3675 100644 --- a/src/spec/OpenApi.php +++ b/src/spec/OpenApi.php @@ -9,7 +9,6 @@ use cebe\openapi\exceptions\TypeErrorException; use cebe\openapi\SpecBaseObject; -use cebe\openapi\Writer; use \JsonSerializable; /** @@ -83,6 +82,6 @@ public function performValidation() } public function jsonSerialize() { - return Writer::writeToJson($this); + return $this->getSerializableData(); } } From db00996d2f8ba2ed258c02fae832a4601e99fc70 Mon Sep 17 00:00:00 2001 From: Garrett Grimm Date: Sat, 22 Oct 2022 18:54:26 -0700 Subject: [PATCH 3/6] Move up to SpecBaseObject --- src/SpecBaseObject.php | 7 ++++++- src/spec/OpenApi.php | 7 +------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/SpecBaseObject.php b/src/SpecBaseObject.php index 1de429b..570b6f1 100644 --- a/src/SpecBaseObject.php +++ b/src/SpecBaseObject.php @@ -13,6 +13,7 @@ use cebe\openapi\json\JsonReference; use cebe\openapi\spec\Reference; use cebe\openapi\spec\Type; +use \JsonSerializable; /** * Base class for all spec objects. @@ -20,7 +21,7 @@ * Implements property management and validation basics. * */ -abstract class SpecBaseObject implements SpecObjectInterface, DocumentContextInterface +abstract class SpecBaseObject implements SpecObjectInterface, DocumentContextInterface, JsonSerializable { private $_properties = []; private $_errors = []; @@ -525,4 +526,8 @@ public function getExtensions(): array } return $extensions; } + + public function jsonSerialize() { + return $this->getSerializableData(); + } } diff --git a/src/spec/OpenApi.php b/src/spec/OpenApi.php index abf3675..29d38b3 100644 --- a/src/spec/OpenApi.php +++ b/src/spec/OpenApi.php @@ -9,7 +9,6 @@ use cebe\openapi\exceptions\TypeErrorException; use cebe\openapi\SpecBaseObject; -use \JsonSerializable; /** * This is the root document object of the OpenAPI document. @@ -26,7 +25,7 @@ * @property ExternalDocumentation|null $externalDocs * */ -class OpenApi extends SpecBaseObject implements JsonSerializable +class OpenApi extends SpecBaseObject { /** * @return array array of attributes available in this object. @@ -80,8 +79,4 @@ public function performValidation() $this->addError('Unsupported openapi version: ' . $this->openapi); } } - - public function jsonSerialize() { - return $this->getSerializableData(); - } } From 7f8c5180abcce5e512906c56d6d8ada8aaa861e7 Mon Sep 17 00:00:00 2001 From: Garrett Grimm Date: Tue, 29 Nov 2022 12:00:42 -0800 Subject: [PATCH 4/6] Use array of operations to support multiple definitions per method --- src/spec/PathItem.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/spec/PathItem.php b/src/spec/PathItem.php index 4b2debc..2a76964 100644 --- a/src/spec/PathItem.php +++ b/src/spec/PathItem.php @@ -50,14 +50,14 @@ protected function attributes(): array return [ 'summary' => Type::STRING, 'description' => Type::STRING, - 'get' => Operation::class, - 'put' => Operation::class, - 'post' => Operation::class, - 'delete' => Operation::class, - 'options' => Operation::class, - 'head' => Operation::class, - 'patch' => Operation::class, - 'trace' => Operation::class, + 'get' => [Operation::class], + 'put' => [Operation::class], + 'post' => [Operation::class], + 'delete' => [Operation::class], + 'options' => [Operation::class], + 'head' => [Operation::class], + 'patch' => [Operation::class], + 'trace' => [Operation::class], 'servers' => [Server::class], 'parameters' => [Parameter::class], ]; From 85fe8d1e36c423205aa6617b8d98aaf7c0074d00 Mon Sep 17 00:00:00 2001 From: Garrett Grimm Date: Tue, 29 Nov 2022 13:44:58 -0800 Subject: [PATCH 5/6] Update getOperations() to work with new structure --- src/spec/PathItem.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spec/PathItem.php b/src/spec/PathItem.php index 2a76964..623656f 100644 --- a/src/spec/PathItem.php +++ b/src/spec/PathItem.php @@ -116,7 +116,7 @@ public function getOperations() { $operations = []; foreach ($this->attributes() as $attribute => $type) { - if ($type === Operation::class && isset($this->$attribute)) { + if (\is_array($type) && $type[0] === Operation::class && isset($this->$attribute)) { $operations[$attribute] = $this->$attribute; } } From 76714d9cfb19fa32abdf576dec1d9b97390a5fe7 Mon Sep 17 00:00:00 2001 From: Garrett Grimm Date: Sun, 26 Feb 2023 11:12:09 -0800 Subject: [PATCH 6/6] Remove changes from master --- src/spec/PathItem.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/spec/PathItem.php b/src/spec/PathItem.php index 623656f..4b2debc 100644 --- a/src/spec/PathItem.php +++ b/src/spec/PathItem.php @@ -50,14 +50,14 @@ protected function attributes(): array return [ 'summary' => Type::STRING, 'description' => Type::STRING, - 'get' => [Operation::class], - 'put' => [Operation::class], - 'post' => [Operation::class], - 'delete' => [Operation::class], - 'options' => [Operation::class], - 'head' => [Operation::class], - 'patch' => [Operation::class], - 'trace' => [Operation::class], + 'get' => Operation::class, + 'put' => Operation::class, + 'post' => Operation::class, + 'delete' => Operation::class, + 'options' => Operation::class, + 'head' => Operation::class, + 'patch' => Operation::class, + 'trace' => Operation::class, 'servers' => [Server::class], 'parameters' => [Parameter::class], ]; @@ -116,7 +116,7 @@ public function getOperations() { $operations = []; foreach ($this->attributes() as $attribute => $type) { - if (\is_array($type) && $type[0] === Operation::class && isset($this->$attribute)) { + if ($type === Operation::class && isset($this->$attribute)) { $operations[$attribute] = $this->$attribute; } }