Skip to content

Commit

Permalink
Updated models to contain parsed enums
Browse files Browse the repository at this point in the history
  • Loading branch information
calcinai committed Nov 29, 2016
1 parent bb17cd8 commit 4eb54ad
Show file tree
Hide file tree
Showing 39 changed files with 759 additions and 510 deletions.
25 changes: 23 additions & 2 deletions src/BaseSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ abstract class BaseSchema implements \JsonSerializable
{
protected $data;

protected static $enums = [];

protected static $properties = [];

protected static $pattern_properties = [];
Expand Down Expand Up @@ -53,17 +55,32 @@ public function set($property_name, $value)
public function add($property_name, $value)
{
$this->validateProperty($property_name, $value);
$this->data[$property_name][] = $value;
$this->data[$property_name][] =& $value;
return $this;
}

/**
* Property getter
*
* @param $property_name
* @return $this
*/
public function get($property_name)
{
return $this->data[$property_name];
}

/**
* @param $property_name
* @param $value
* @return bool
*/
private function validateProperty($property_name, $value)
{
//First check enums
if (isset(static::$enums[$property_name]) && !in_array($value, static::$enums[$property_name])) {
throw new \InvalidArgumentException(sprintf('Value for %s is not specified in the enum', $property_name));
}
//Test regular properties
if (isset(static::$properties[$property_name])) {
//There's no way to constrain it at this point
Expand Down Expand Up @@ -154,7 +171,11 @@ private function parseData($data)
}
}
//At this point we've done our best to cast, just leave as-is.
$this->data[$property_name] = $property;
if (is_scalar($property)) {
$this->set($property_name, $property);
} else {
$this->data[$property_name] = $property;
}
}
}

Expand Down
22 changes: 14 additions & 8 deletions src/Definitions/ApiKeySecurity.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ class ApiKeySecurity extends BaseSchema
*/
protected $data = ['type' => 'apiKey'];

/**
* Any enums that exist on this object
* @var array
*/
protected static $enums = ['type' => ['apiKey'], 'in' => ['header', 'query']];

/**
* Properties and types
* @var array
Expand All @@ -36,7 +42,7 @@ class ApiKeySecurity extends BaseSchema
*/
public function setType($type)
{
$this->data['type'] = $type;
$this->set('type', $type);
return $this;
}

Expand All @@ -45,7 +51,7 @@ public function setType($type)
*/
public function getType()
{
return $this->data['type'];
return $this->get('type');
}

/**
Expand All @@ -54,7 +60,7 @@ public function getType()
*/
public function setName($name)
{
$this->data['name'] = $name;
$this->set('name', $name);
return $this;
}

Expand All @@ -63,7 +69,7 @@ public function setName($name)
*/
public function getName()
{
return $this->data['name'];
return $this->get('name');
}

/**
Expand All @@ -72,7 +78,7 @@ public function getName()
*/
public function setIn($in)
{
$this->data['in'] = $in;
$this->set('in', $in);
return $this;
}

Expand All @@ -81,7 +87,7 @@ public function setIn($in)
*/
public function getIn()
{
return $this->data['in'];
return $this->get('in');
}

/**
Expand All @@ -90,7 +96,7 @@ public function getIn()
*/
public function setDescription($description)
{
$this->data['description'] = $description;
$this->set('description', $description);
return $this;
}

Expand All @@ -99,7 +105,7 @@ public function setDescription($description)
*/
public function getDescription()
{
return $this->data['description'];
return $this->get('description');
}

}
14 changes: 10 additions & 4 deletions src/Definitions/BasicAuthenticationSecurity.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ class BasicAuthenticationSecurity extends BaseSchema
*/
protected $data = ['type' => 'basic'];

/**
* Any enums that exist on this object
* @var array
*/
protected static $enums = ['type' => ['basic']];

/**
* Properties and types
* @var array
Expand All @@ -36,7 +42,7 @@ class BasicAuthenticationSecurity extends BaseSchema
*/
public function setType($type)
{
$this->data['type'] = $type;
$this->set('type', $type);
return $this;
}

Expand All @@ -45,7 +51,7 @@ public function setType($type)
*/
public function getType()
{
return $this->data['type'];
return $this->get('type');
}

/**
Expand All @@ -54,7 +60,7 @@ public function getType()
*/
public function setDescription($description)
{
$this->data['description'] = $description;
$this->set('description', $description);
return $this;
}

Expand All @@ -63,7 +69,7 @@ public function setDescription($description)
*/
public function getDescription()
{
return $this->data['description'];
return $this->get('description');
}

}
26 changes: 16 additions & 10 deletions src/Definitions/BodyParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ class BodyParameter extends BaseSchema
*/
protected $data = ['in' => 'body'];

/**
* Any enums that exist on this object
* @var array
*/
protected static $enums = ['in' => ['body']];

/**
* Properties and types
* @var array
Expand All @@ -37,7 +43,7 @@ class BodyParameter extends BaseSchema
*/
public function setDescription($description)
{
$this->data['description'] = $description;
$this->set('description', $description);
return $this;
}

Expand All @@ -47,7 +53,7 @@ public function setDescription($description)
*/
public function getDescription()
{
return $this->data['description'];
return $this->get('description');
}

/**
Expand All @@ -57,7 +63,7 @@ public function getDescription()
*/
public function setName($name)
{
$this->data['name'] = $name;
$this->set('name', $name);
return $this;
}

Expand All @@ -67,7 +73,7 @@ public function setName($name)
*/
public function getName()
{
return $this->data['name'];
return $this->get('name');
}

/**
Expand All @@ -77,7 +83,7 @@ public function getName()
*/
public function setIn($in)
{
$this->data['in'] = $in;
$this->set('in', $in);
return $this;
}

Expand All @@ -87,7 +93,7 @@ public function setIn($in)
*/
public function getIn()
{
return $this->data['in'];
return $this->get('in');
}

/**
Expand All @@ -97,7 +103,7 @@ public function getIn()
*/
public function setRequired($required)
{
$this->data['required'] = $required;
$this->set('required', $required);
return $this;
}

Expand All @@ -107,7 +113,7 @@ public function setRequired($required)
*/
public function getRequired()
{
return $this->data['required'];
return $this->get('required');
}

/**
Expand All @@ -117,7 +123,7 @@ public function getRequired()
*/
public function setSchema(Schema $schema)
{
$this->data['schema'] = $schema;
$this->set('schema', $schema);
return $this;
}

Expand All @@ -127,7 +133,7 @@ public function setSchema(Schema $schema)
*/
public function getSchema()
{
return $this->data['schema'];
return $this->get('schema');
}

}
18 changes: 12 additions & 6 deletions src/Definitions/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ class Contact extends BaseSchema
*/
protected $data = [];

/**
* Any enums that exist on this object
* @var array
*/
protected static $enums = [];

/**
* Properties and types
* @var array
Expand All @@ -40,7 +46,7 @@ class Contact extends BaseSchema
*/
public function setName($name)
{
$this->data['name'] = $name;
$this->set('name', $name);
return $this;
}

Expand All @@ -50,7 +56,7 @@ public function setName($name)
*/
public function getName()
{
return $this->data['name'];
return $this->get('name');
}

/**
Expand All @@ -60,7 +66,7 @@ public function getName()
*/
public function setUrl($url)
{
$this->data['url'] = $url;
$this->set('url', $url);
return $this;
}

Expand All @@ -70,7 +76,7 @@ public function setUrl($url)
*/
public function getUrl()
{
return $this->data['url'];
return $this->get('url');
}

/**
Expand All @@ -80,7 +86,7 @@ public function getUrl()
*/
public function setEmail($email)
{
$this->data['email'] = $email;
$this->set('email', $email);
return $this;
}

Expand All @@ -90,7 +96,7 @@ public function setEmail($email)
*/
public function getEmail()
{
return $this->data['email'];
return $this->get('email');
}

}
6 changes: 6 additions & 0 deletions src/Definitions/Definitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ class Definitions extends BaseSchema
*/
protected $data = [];

/**
* Any enums that exist on this object
* @var array
*/
protected static $enums = [];

/**
* Properties and types
* @var array
Expand Down
6 changes: 6 additions & 0 deletions src/Definitions/Examples.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ class Examples extends BaseSchema
*/
protected $data = [];

/**
* Any enums that exist on this object
* @var array
*/
protected static $enums = [];

/**
* Properties and types
* @var array
Expand Down
Loading

0 comments on commit 4eb54ad

Please sign in to comment.