From ca11c05f981b1488560ba9d4c342f1a7547b041f Mon Sep 17 00:00:00 2001 From: Sohel Ahmed Mesaniya Date: Thu, 16 Oct 2025 17:57:12 +0530 Subject: [PATCH 1/3] Commit for creating PR --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d7cd0715..1c9bddea 100644 --- a/README.md +++ b/README.md @@ -332,3 +332,4 @@ Professional support, consulting as well as software development services are av https://www.cebe.cc/en/contact Development of this library is sponsored by [cebe.:cloud: "Your Professional Deployment Platform"](https://cebe.cloud). + From 5b00c4e738bc66bb7ecf7fbb46a4e29217296dc7 Mon Sep 17 00:00:00 2001 From: Sohel Ahmed Mesaniya Date: Fri, 17 Oct 2025 15:57:10 +0530 Subject: [PATCH 2/3] Add test --- README.md | 1 - src/SpecBaseObject.php | 8 +++++++- tests/spec/OpenApiTest.php | 34 ++++++++++++++++++++++++++++------ 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 1c9bddea..d7cd0715 100644 --- a/README.md +++ b/README.md @@ -332,4 +332,3 @@ Professional support, consulting as well as software development services are av https://www.cebe.cc/en/contact Development of this library is sponsored by [cebe.:cloud: "Your Professional Deployment Platform"](https://cebe.cloud). - diff --git a/src/SpecBaseObject.php b/src/SpecBaseObject.php index ef93401e..dd414970 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, RawSpecDataInterface +abstract class SpecBaseObject implements SpecObjectInterface, DocumentContextInterface, JsonSerializable, RawSpecDataInterface { private $_rawSpec; private $_properties = []; @@ -528,6 +529,11 @@ public function getExtensions(): array return $extensions; } + public function jsonSerialize() + { + return $this->getSerializableData(); + } + public function getRawSpecData(): array { return $this->_rawSpec; diff --git a/tests/spec/OpenApiTest.php b/tests/spec/OpenApiTest.php index 433bd352..de2d3440 100644 --- a/tests/spec/OpenApiTest.php +++ b/tests/spec/OpenApiTest.php @@ -83,7 +83,7 @@ public function testReadPetStore() public function assertAllInstanceOf($className, $array) { - foreach($array as $k => $v) { + foreach ($array as $k => $v) { $this->assertInstanceOf($className, $v, "Asserting that item with key '$k' is instance of $className"); } } @@ -147,7 +147,7 @@ public function specProvider() /** @var $it RecursiveDirectoryIterator|RecursiveIteratorIterator */ $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__ . '/../../vendor/apis-guru/openapi-directory/APIs')); $it->rewind(); - while($it->valid()) { + while ($it->valid()) { if ($it->getBasename() === 'openapi.yaml') { $apisGuruExamples[] = $it->key(); } @@ -159,10 +159,10 @@ public function specProvider() /** @var $it RecursiveDirectoryIterator|RecursiveIteratorIterator */ $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__ . '/../../vendor/nexmo/api-specification/definitions')); $it->rewind(); - while($it->valid()) { + while ($it->valid()) { if ($it->getExtension() === 'yml' - && strpos($it->getSubPath(), 'common') === false - && $it->getBasename() !== 'voice.v2.yml' // contains invalid references + && strpos($it->getSubPath(), 'common') === false + && $it->getBasename() !== 'voice.v2.yml' // contains invalid references ) { $nexmoExamples[] = $it->key(); } @@ -175,7 +175,7 @@ public function specProvider() $apisGuruExamples, $nexmoExamples ); - foreach($all as $path) { + foreach ($all as $path) { yield [ substr($path, strlen(__DIR__ . '/../../vendor/')), basename(dirname($path, 2)) . DIRECTORY_SEPARATOR . basename(dirname($path, 1)) . DIRECTORY_SEPARATOR . basename($path) @@ -233,4 +233,26 @@ public function testSpecs($openApiFile) } } + + public function testJsonSerialize() + { + $spec = <<assertSame(json_encode($openapi), '{"openapi":"3.0.0","info":{"title":"Minimal API","version":"1.0.0"},"paths":{"\/":{"get":{"summary":"Retrieves a minimal response","responses":{"200":{"description":"OK"}}}}}}'); + } } From 807aa5198044900c5ac6edfc353febf1f24e69fe Mon Sep 17 00:00:00 2001 From: Sohel Ahmed Mesaniya Date: Fri, 17 Oct 2025 16:05:34 +0530 Subject: [PATCH 3/3] Fix failing test --- src/SpecBaseObject.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/SpecBaseObject.php b/src/SpecBaseObject.php index dd414970..fd2b1402 100644 --- a/src/SpecBaseObject.php +++ b/src/SpecBaseObject.php @@ -529,6 +529,7 @@ public function getExtensions(): array return $extensions; } + #[\ReturnTypeWillChange] public function jsonSerialize() { return $this->getSerializableData();