Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
.DS_Store
/.idea
/.phpunit.result.cache
Changelog.md
*.sh
45 changes: 36 additions & 9 deletions src/Objects/MediaType.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

/**
* OpenAPI Reader.
*
* @see https://github.com/hkarlstrom/openapi-reader
*
* @copyright Copyright (c) 2018 Henrik Karlström
* @license MIT
*/
Expand All @@ -13,25 +11,54 @@

class MediaType
{
/**
* @var string
*/
public $type;

/**
* @var mixed|null
*/
public $schema;

/**
* @var mixed|null
*/
public $example;

/**
* @var array|mixed|null
*/
public $examples = [];

/**
* @var array
*/
public $encoding = [];

/**
* @param string $type
* @param array $args
*/
public function __construct(string $type, array $args)
{
$this->type = $type;
$this->schema = $args['schema'] ?? null;
$this->example = $args['example'] ?? null;
$this->examples = $args['examples'] ?? null;
foreach ($args['encoding'] ?? [] as $property => $encodingArgs) {
$this->type = $type;
$this->schema = ($args['schema'] ?? null);
$this->example = ($args['example'] ?? null);
$this->examples = ($args['examples'] ?? null);

foreach (($args['encoding'] ?? []) as $property => $encodingArgs)
{
$this->encoding[$property] = new Encoding($property, $encodingArgs);
}
}

public function getExample(string $type = null) : ?array
/**
* @param string|null $type
* @return array|null
*/
public function getExample(?string $type = null): ?array
{
return $this->examples[$type] ?? $this->example;
return ($this->examples[$type] ?? $this->example);
}
}