File tree Expand file tree Collapse file tree 2 files changed +12
-5
lines changed Expand file tree Collapse file tree 2 files changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -41,11 +41,15 @@ install: composer.lock yarn.lock
4141 $(DOCKER_PHP ) composer install --prefer-dist --no-interaction --no-progress --ansi
4242 $(DOCKER_NODE ) yarn install
4343
44- test :
44+ test : unit test-recursion.json test-recursion2.yaml test-empty-maps.json
45+
46+ unit :
4547 $(DOCKER_PHP ) php $(PHPARGS ) $(XPHPARGS ) vendor/bin/phpunit --verbose --colors=always $(TESTCASE )
46- $(DOCKER_PHP ) php $(PHPARGS ) $(XPHPARGS ) bin/php-openapi validate tests/spec/data/recursion.json
47- $(DOCKER_PHP ) php $(PHPARGS ) $(XPHPARGS ) bin/php-openapi validate tests/spec/data/recursion2.yaml
48- $(DOCKER_PHP ) php $(PHPARGS ) $(XPHPARGS ) bin/php-openapi validate tests/spec/data/empty-maps.json
48+
49+ # test specific JSON files in tests/spec/data/
50+ # e.g. test-recursion will run validation on tests/spec/data/recursion.json
51+ test-% : tests/spec/data/%
52+ $(DOCKER_PHP ) php $(PHPARGS ) $(XPHPARGS ) bin/php-openapi validate $<
4953
5054lint : install
5155 $(DOCKER_PHP ) php $(PHPARGS ) $(XPHPARGS ) bin/php-openapi validate tests/spec/data/reference/playlist.json
Original file line number Diff line number Diff line change @@ -190,8 +190,11 @@ public function getSerializableData()
190190 if ($ v instanceof SpecObjectInterface) {
191191 $ data [$ k ] = $ v ->getSerializableData ();
192192 } elseif (is_array ($ v )) {
193+ // test if php arrays should be represented as object in YAML/JSON
193194 $ toObject = false ;
194195 if (!empty ($ v )) {
196+ // case 1: non-empty array should be an object if it does not contain
197+ // consecutive numeric keys
195198 $ j = 0 ;
196199 foreach ($ v as $ i => $ d ) {
197200 if ($ j ++ !== $ i ) {
@@ -202,7 +205,7 @@ public function getSerializableData()
202205 }
203206 }
204207 } elseif (isset ($ this ->attributes ()[$ k ]) && is_array ($ this ->attributes ()[$ k ]) && 2 === count ($ this ->attributes ()[$ k ])) {
205- // An empty Map, which is an empty array in PHP but needs to be an empty object in output.
208+ // case 2: Attribute type is an object (specified in attributes() by an array which specifies two items (key and value type)
206209 $ toObject = true ;
207210 }
208211 if ($ toObject ) {
You can’t perform that action at this time.
0 commit comments