From cf0ebc651710d5583d8706403413abda71f412d4 Mon Sep 17 00:00:00 2001 From: Sohel Ahmed Mesaniya Date: Mon, 27 Jan 2025 19:29:52 +0530 Subject: [PATCH 1/5] Create PR --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ea32da82..a077b532 100644 --- a/README.md +++ b/README.md @@ -298,3 +298,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 7bad5d11ae37ded5f73e2a222fea742ea0c1003a Mon Sep 17 00:00:00 2001 From: Sohel Ahmed Mesaniya Date: Tue, 28 Jan 2025 19:21:41 +0530 Subject: [PATCH 2/5] Install yaml --- tests/docker/Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/docker/Dockerfile b/tests/docker/Dockerfile index 4dce3b53..95d01c69 100644 --- a/tests/docker/Dockerfile +++ b/tests/docker/Dockerfile @@ -19,11 +19,14 @@ RUN apt-get update && \ curl \ libcurl4-openssl-dev \ libssl-dev \ + libyaml-dev \ --no-install-recommends && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \ && pecl install xdebug-2.9.6 \ + && pecl install yaml \ && docker-php-ext-enable xdebug \ + && docker-php-ext-enable yaml \ && docker-php-ext-install \ zip \ curl \ From 02f7da3b01ca00ca2fa14c0991437bc06b0da2d3 Mon Sep 17 00:00:00 2001 From: Sohel Ahmed Mesaniya Date: Thu, 30 Jan 2025 18:40:03 +0530 Subject: [PATCH 3/5] WIP --- Makefile | 6 ++++++ README.md | 1 - composer.json | 4 +--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index acfca9e2..0d7ca4cf 100644 --- a/Makefile +++ b/Makefile @@ -37,6 +37,12 @@ fix-style: php-cs-fixer.phar $(DOCKER_PHP) vendor/bin/indent --spaces .php_cs.dist $(DOCKER_PHP) ./php-cs-fixer.phar fix src/ --diff +cli: + docker-compose run --rm php bash + +#cli_root: +# docker-compose exec --user="root" php bash + install: $(DOCKER_PHP) composer install --prefer-dist --no-interaction --no-progress --ansi $(DOCKER_NODE) yarn install diff --git a/README.md b/README.md index a077b532..ea32da82 100644 --- a/README.md +++ b/README.md @@ -298,4 +298,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/composer.json b/composer.json index a3054a52..7bbadcae 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "require": { "php": ">=7.1.0", "ext-json": "*", - "symfony/yaml": "^3.4 || ^4 || ^5 || ^6 || ^7.0", + "ext-yaml": "*", "justinrainbow/json-schema": "^5.2" }, "require-dev": { @@ -28,8 +28,6 @@ "phpunit/phpunit": "^6.5 || ^7.5 || ^8.5 || ^9.4", "oai/openapi-specification": "3.0.3", "mermade/openapi3-examples": "1.0.0", - "apis-guru/openapi-directory": "1.0.0", - "nexmo/api-specification": "1.0.0", "phpstan/phpstan": "^0.12.0" }, "conflict": { From 2b2953c0a07ef06fcc3549741f396a49f7337fbd Mon Sep 17 00:00:00 2001 From: Sohel Ahmed Mesaniya Date: Wed, 5 Feb 2025 13:15:44 +0530 Subject: [PATCH 4/5] Use php-ext-yaml and remove symfony/yaml component usage --- src/Reader.php | 3 +- src/ReferenceContext.php | 3 +- src/Writer.php | 7 ++- src/spec/Reference.php | 2 - tests/WriterTest.php | 21 +++++--- tests/spec/MediaTypeTest.php | 4 +- tests/spec/OpenApiTest.php | 2 +- tests/spec/ReferenceTest.php | 100 +++++++++++++++++++---------------- 8 files changed, 76 insertions(+), 66 deletions(-) diff --git a/src/Reader.php b/src/Reader.php index 99ee5c36..c229fe07 100644 --- a/src/Reader.php +++ b/src/Reader.php @@ -13,7 +13,6 @@ use cebe\openapi\json\InvalidJsonPointerSyntaxException; use cebe\openapi\json\JsonPointer; use cebe\openapi\spec\OpenApi; -use Symfony\Component\Yaml\Yaml; /** * Utility class to simplify reading JSON or YAML OpenAPI specs. @@ -54,7 +53,7 @@ public static function readFromJson(string $json, string $baseType = OpenApi::cl */ public static function readFromYaml(string $yaml, string $baseType = OpenApi::class): SpecObjectInterface { - return new $baseType(Yaml::parse($yaml)); + return new $baseType(yaml_parse($yaml)); } /** diff --git a/src/ReferenceContext.php b/src/ReferenceContext.php index bde0a964..e5233539 100644 --- a/src/ReferenceContext.php +++ b/src/ReferenceContext.php @@ -11,7 +11,6 @@ use cebe\openapi\exceptions\UnresolvableReferenceException; use cebe\openapi\json\JsonPointer; use cebe\openapi\spec\Reference; -use Symfony\Component\Yaml\Yaml; /** * ReferenceContext represents a context in which references are resolved. @@ -224,7 +223,7 @@ public function fetchReferencedFile($uri) if (strpos(ltrim($content), '{') === 0) { $parsedContent = json_decode($content, true); } else { - $parsedContent = Yaml::parse($content); + $parsedContent = yaml_parse($content); } $this->_cache->set('FILE_CONTENT://' . $uri, 'FILE_CONTENT', $parsedContent); return $parsedContent; diff --git a/src/Writer.php b/src/Writer.php index faa08f46..95e200ea 100644 --- a/src/Writer.php +++ b/src/Writer.php @@ -9,7 +9,6 @@ use cebe\openapi\exceptions\IOException; use cebe\openapi\spec\OpenApi; -use Symfony\Component\Yaml\Yaml; /** * Utility class to simplify writing JSON or YAML OpenAPI specs. @@ -35,7 +34,11 @@ public static function writeToJson(SpecObjectInterface $object, int $flags = JSO */ public static function writeToYaml(SpecObjectInterface $object): string { - return Yaml::dump($object->getSerializableData(), 256, 2, Yaml::DUMP_OBJECT_AS_MAP | Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE); +// return Yaml::dump($object->getSerializableData(), 256, 2, Yaml::DUMP_OBJECT_AS_MAP | Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE); + return yaml_emit( + json_decode(json_encode($object->getSerializableData(), JSON_FORCE_OBJECT), true), + YAML_UTF8_ENCODING + ); } /** diff --git a/src/spec/Reference.php b/src/spec/Reference.php index cda612a9..7b37b0d8 100644 --- a/src/spec/Reference.php +++ b/src/spec/Reference.php @@ -8,7 +8,6 @@ namespace cebe\openapi\spec; use cebe\openapi\DocumentContextInterface; -use cebe\openapi\exceptions\IOException; use cebe\openapi\exceptions\TypeErrorException; use cebe\openapi\exceptions\UnresolvableReferenceException; use cebe\openapi\json\InvalidJsonPointerSyntaxException; @@ -17,7 +16,6 @@ use cebe\openapi\json\NonexistentJsonPointerReferenceException; use cebe\openapi\ReferenceContext; use cebe\openapi\SpecObjectInterface; -use Symfony\Component\Yaml\Yaml; /** * Reference Object diff --git a/tests/WriterTest.php b/tests/WriterTest.php index fc415b51..7a9f4f78 100644 --- a/tests/WriterTest.php +++ b/tests/WriterTest.php @@ -74,11 +74,13 @@ public function testWriteYaml() $this->assertEquals(preg_replace('~\R~', "\n", <<assertEquals(preg_replace('~\R~', "\n", <<assertEquals(preg_replace('~\R~', "\n", <<validate(); diff --git a/tests/spec/ReferenceTest.php b/tests/spec/ReferenceTest.php index b94c946e..a7983d00 100644 --- a/tests/spec/ReferenceTest.php +++ b/tests/spec/ReferenceTest.php @@ -1,13 +1,13 @@ Date: Wed, 5 Feb 2025 13:18:19 +0530 Subject: [PATCH 5/5] Remove changes --- src/Writer.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Writer.php b/src/Writer.php index 95e200ea..030ba267 100644 --- a/src/Writer.php +++ b/src/Writer.php @@ -36,8 +36,7 @@ public static function writeToYaml(SpecObjectInterface $object): string { // return Yaml::dump($object->getSerializableData(), 256, 2, Yaml::DUMP_OBJECT_AS_MAP | Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE); return yaml_emit( - json_decode(json_encode($object->getSerializableData(), JSON_FORCE_OBJECT), true), - YAML_UTF8_ENCODING + json_decode(json_encode($object->getSerializableData()), true) ); }