php-openapi
php-openapi copied to clipboard
Symfony YAML does not parse all YAML
trafficstars
While trying to add more tests for more specs from these sources:
- https://github.com/Mermade/openapi3-examples/tree/master/resources
- https://github.com/Nexmo/api-specification/tree/master/definitions
- https://github.com/APIs-guru/openapi-directory
I found that symfony YAML fails on a lot of these. We either need an alternative YAML parser or improve symfony YAML to not fail.
- https://github.com/yaml/yaml-test-suite
- https://github.com/symfony/symfony/issues/27965
https://github.com/mustangostang/spyc/blob/master/Spyc.php
I've encountered the same issue. The problem is that it parses only arrays while getSerializableData() return stdClasses.
I'm using typical trick from js world:
Yaml::dump(
json_decode(json_encode($openApiSpec->create()->getSerializableData()), true),
flags: Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE
)