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
41
41
$(DOCKER_PHP ) composer install --prefer-dist --no-interaction --no-progress --ansi
42
42
$(DOCKER_NODE ) yarn install
43
43
44
- test :
44
+ test : unit test-recursion.json test-recursion2.yaml test-empty-maps.json
45
+
46
+ unit :
45
47
$(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 $<
49
53
50
54
lint : install
51
55
$(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()
190
190
if ($ v instanceof SpecObjectInterface) {
191
191
$ data [$ k ] = $ v ->getSerializableData ();
192
192
} elseif (is_array ($ v )) {
193
+ // test if php arrays should be represented as object in YAML/JSON
193
194
$ toObject = false ;
194
195
if (!empty ($ v )) {
196
+ // case 1: non-empty array should be an object if it does not contain
197
+ // consecutive numeric keys
195
198
$ j = 0 ;
196
199
foreach ($ v as $ i => $ d ) {
197
200
if ($ j ++ !== $ i ) {
@@ -202,7 +205,7 @@ public function getSerializableData()
202
205
}
203
206
}
204
207
} 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)
206
209
$ toObject = true ;
207
210
}
208
211
if ($ toObject ) {
You can’t perform that action at this time.
0 commit comments