cebe / php-openapi

Read and write OpenAPI yaml/json files and make the content accessible in PHP objects.
MIT License
466 stars 88 forks source link

Empty security array incorrectly converted to empty object (YAML) #52

Closed coatesap closed 4 years ago

coatesap commented 4 years ago

When using $schema = Reader::readFromYaml($content) followed by Writer::writeToYaml($schema) any instances of security: [] are incorrectly converted to security: { }. This is invalid (it should remain as an empty array) and causes any tooling that reads the newly written spec to fall over.

coatesap commented 4 years ago

It looks like the fix for this would probably be to change line 37 of Writer.php from:

return Yaml::dump($object->getSerializableData(), 256, 2, Yaml::DUMP_OBJECT_AS_MAP);

to

return Yaml::dump($object->getSerializableData(), 256, 2, Yaml::DUMP_OBJECT_AS_MAP | Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE);

This may well also fix #46

cebe commented 4 years ago

https://github.com/OAI/OpenAPI-Specification/pull/1886

coatesap commented 4 years ago

Hi @cebe - does my suggestion above seem sensible, or are there any other considerations that need to be taken into account? If it looks ok, I'm happy to test it and open a PR...

cebe commented 4 years ago

if there is no valid case where an empty object needs to represent something else, we can apply this change.