Skip to content

Commit 77f6ff2

Browse files
committed
Fix bug
1 parent 65625f0 commit 77f6ff2

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/lib/FakerStubResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ public function fakeForObject(SpecObjectInterface $items): string
332332
foreach ($items->properties as $name => $prop) {
333333
/** @var SpecObjectInterface $prop */
334334

335-
if ($prop->properties) { // nested object
335+
if (!empty($prop->properties)) { // nested object
336336
$result = $this->{__FUNCTION__}($prop);
337337
} else {
338338
$result = $this->aElementFaker(['items' => $prop->getSerializableData()], $name);

tests/specs/issue_fix/20_consider_openapi_spec_examples_in_faker_code_generation/index.yaml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ components:
123123
type: integer
124124
minimum: 0
125125
maximum: 200
126+
user:
127+
$ref: '#/components/schemas/User'
128+
user_2:
129+
type: array
130+
# x-no-relation: true # it is not required since we only implemented handling of such object for arrays only
131+
items:
132+
$ref: '#/components/schemas/User'
126133
tags:
127134
type: array
128135
items:
@@ -155,14 +162,13 @@ components:
155162
user_ref_obj_arr_normal: # faker for this won't be generated
156163
type: array
157164
maxItems: 3
158-
# x-no-relation: true
159165
items:
160166
$ref: '#/components/schemas/User'
161167

162168
user_ref_obj_arr: # special
163169
type: array
164170
maxItems: 3
165-
x-no-relation: true
171+
x-no-relation: true # it is required because this property is not part of any array
166172
items:
167173
$ref: '#/components/schemas/User'
168174

@@ -198,12 +204,8 @@ components:
198204

199205
one_of_from_multi_ref_arr:
200206
type: array
201-
x-no-relation: true
207+
# x-no-relation: true # it is not required since we only implemented handling of oneOf for arrays only
202208
items:
203209
oneOf:
204210
- $ref: '#/components/schemas/User'
205211
- $ref: '#/components/schemas/Fruit'
206-
207-
208-
209-
# TODO count is not working in some cases

0 commit comments

Comments
 (0)