Skip to content

Commit 9538035

Browse files
committed
Example usage for #98 (comment)
1 parent 633cfcc commit 9538035

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/lib/FakerStubResolver.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use cebe\openapi\ReferenceContext;
1717
use cebe\openapi\spec\Reference;
1818
use cebe\openapi\spec\Schema;
19+
use cebe\openapi\SpecBaseObject;
1920
use cebe\openapi\SpecObjectInterface;
2021
use cebe\yii2openapi\lib\exceptions\InvalidDefinitionException;
2122
use cebe\yii2openapi\lib\items\Attribute;
@@ -329,7 +330,9 @@ public function fakeForObject(SpecObjectInterface $items): string
329330
if (!empty($prop->properties)) { // nested object
330331
$result = $this->{__FUNCTION__}($prop);
331332
} else {
332-
$result = $this->aElementFaker(['items' => $prop->getSerializableData()], $name);
333+
// ($prop instanceof SpecBaseObject) && var_dump($prop->rawSpec);
334+
// $result = $this->aElementFaker(['items' => $prop->getSerializableData()], $name);
335+
$result = $this->aElementFaker(['items' => $prop->rawSpec], $name);
333336
}
334337
$props .= '\'' . $name . '\' => ' . $result . ',' . PHP_EOL;
335338
}
@@ -358,7 +361,7 @@ public function handleOneOf(SpecObjectInterface $items, int $count): string
358361
foreach ($items->oneOf as $key => $aDataType) {
359362
/** @var Schema|Reference $aDataType */
360363

361-
$inp = $aDataType instanceof Reference ? $aDataType : ['items' => $aDataType->getSerializableData()];
364+
$inp = $aDataType instanceof Reference ? $aDataType : ['items' => $aDataType->rawSpec];
362365
$aFaker = $this->aElementFaker($inp, $this->attribute->columnName);
363366
$result .= '$dataType' . $key . ' = ' . $aFaker . ';';
364367
}
@@ -403,7 +406,7 @@ public function aElementFaker($data, ?string $columnName = null): ?string
403406
return '(new ' . $class . ')->generateModel()->attributes';
404407
}
405408

406-
$inp = $data instanceof SpecObjectInterface ? $data->getSerializableData() : $data;
409+
$inp = $data instanceof SpecObjectInterface ? $data->rawSpec : $data;
407410
$aElementData = Json::decode(Json::encode($inp));
408411
$columnName = $columnName ?? 'unnamedProp';
409412
$compoSchemaData = [

0 commit comments

Comments
 (0)