Skip to content

Draft: Symfony YAML does not parse all YAML #223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@
"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": {
"cebe/indent": "*",
"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": {
Expand Down
3 changes: 1 addition & 2 deletions src/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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));
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/ReferenceContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions src/Writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -35,7 +34,10 @@ 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()), true)
);
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/spec/Reference.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,7 +16,6 @@
use cebe\openapi\json\NonexistentJsonPointerReferenceException;
use cebe\openapi\ReferenceContext;
use cebe\openapi\SpecObjectInterface;
use Symfony\Component\Yaml\Yaml;

/**
* Reference Object
Expand Down
21 changes: 13 additions & 8 deletions tests/WriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,13 @@ public function testWriteYaml()


$this->assertEquals(preg_replace('~\R~', "\n", <<<YAML
---
openapi: 3.0.0
info:
title: 'Test API'
title: Test API
version: 1.0.0
paths: { }
paths: []
...

YAML
),
Expand Down Expand Up @@ -121,12 +123,14 @@ public function testWriteEmptySecurityYaml()


$this->assertEquals(preg_replace('~\R~', "\n", <<<YAML
---
openapi: 3.0.0
info:
title: 'Test API'
title: Test API
version: 1.0.0
paths: { }
paths: []
security: []
...

YAML
),
Expand Down Expand Up @@ -173,14 +177,15 @@ public function testWriteEmptySecurityPartYaml()


$this->assertEquals(preg_replace('~\R~', "\n", <<<YAML
---
openapi: 3.0.0
info:
title: 'Test API'
title: Test API
version: 1.0.0
paths: { }
paths: []
security:
-
Bearer: []
- Bearer: []
...

YAML
),
Expand Down
3 changes: 3 additions & 0 deletions tests/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
4 changes: 2 additions & 2 deletions tests/spec/MediaTypeTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

use cebe\openapi\Reader;
use cebe\openapi\spec\MediaType;
use cebe\openapi\spec\Example;
use cebe\openapi\spec\MediaType;
use cebe\openapi\spec\OpenApi;
use cebe\openapi\spec\Reference;
use Symfony\Component\Yaml\Yaml;
Expand Down Expand Up @@ -125,7 +125,7 @@ public function testPathsCanNotBeCreatedFromBullshit($config, $expectedException

public function testUnresolvedReferencesInEncoding()
{
$yaml = Yaml::parse(<<<'YAML'
$yaml = yaml_parse(<<<'YAML'
openapi: "3.0.0"
info:
version: 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion tests/spec/OpenApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testReadPetStore()
{
$openApiFile = __DIR__ . '/../../vendor/oai/openapi-specification/examples/v3.0/petstore.yaml';

$yaml = Yaml::parse(file_get_contents($openApiFile));
$yaml = yaml_parse(file_get_contents($openApiFile));
$openapi = new OpenApi($yaml);

$result = $openapi->validate();
Expand Down
Loading
Loading