Skip to content

Commit

Permalink
Merge pull request #155 from cnizzardini/bug/154-schema-property-item…
Browse files Browse the repository at this point in the history
…s-not-generated

Bug/154 schema property items not generated
  • Loading branch information
cnizzardini authored Aug 9, 2020
2 parents e38b8de + 6eec04f commit a51fe93
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
29 changes: 27 additions & 2 deletions src/Lib/OpenApi/SchemaProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,25 @@ class SchemaProperty implements JsonSerializable
*/
private $requirePresenceOnUpdate = false;

/**
* @var array
*/
private $items;

/**
* @return array
*/
public function toArray(): array
{
$vars = get_object_vars($this);
// allows remove this items from JSON

// remove internal properties
foreach (['name','required','requirePresenceOnCreate','requirePresenceOnUpdate'] as $v) {
unset($vars[$v]);
}

// reduce JSON clutter by removing empty values
foreach (['example','description','enum','format'] as $v) {
foreach (['example','description','enum','format','items'] as $v) {
if (empty($vars[$v])) {
unset($vars[$v]);
}
Expand Down Expand Up @@ -346,4 +352,23 @@ public function isTypeScalar(): bool
{
return in_array($this->type, ['integer','string','float','boolean','bool','int']);
}

/**
* @return array
*/
public function getItems(): array
{
return $this->items;
}

/**
* @param array $items array of items
* @return $this
*/
public function setItems(array $items)
{
$this->items = $items;

return $this;
}
}
3 changes: 2 additions & 1 deletion src/Lib/Schema/SchemaPropertyFromYamlFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public function create(string $name, array $yaml): SchemaProperty
->setWriteOnly($yaml['writeOnly'] ?? false)
->setRequired($yaml['required'] ?? false)
->setEnum($yaml['enum'] ?? [])
->setExample($yaml['example'] ?? '');
->setExample($yaml['example'] ?? '')
->setItems($yaml['items'] ?? []);

$properties = [
'maxLength',
Expand Down

0 comments on commit a51fe93

Please sign in to comment.