Skip to content

Commit

Permalink
Adds OAS 3.0 support, fixes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
calcinai committed Jan 14, 2019
1 parent 09aae70 commit 13d6c1c
Show file tree
Hide file tree
Showing 60 changed files with 2,875 additions and 3,820 deletions.
28 changes: 22 additions & 6 deletions src/BaseSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ abstract class BaseSchema implements \IteratorAggregate, \Countable, \JsonSerial
*/
protected static $additional_properties = [];

/**
* @param array $data
* @throws \Exception
*/
public function __construct($data = [])
{
$this->parseData($data);
Expand Down Expand Up @@ -110,8 +114,11 @@ private function validateProperty($property_name, $value)
if (empty(static::$properties[$property_name])) {
return true;
}
foreach (static::$properties[$property_name] as $allowed_class) {
$fq_class = self::getFQCN($allowed_class);
foreach (static::$properties[$property_name] as $allowed_type) {
if (gettype($value) === $allowed_type) {
return true;
}
$fq_class = self::getFQCN($allowed_type);
if ($value instanceof $fq_class) {
return true;
}
Expand All @@ -124,8 +131,11 @@ private function validateProperty($property_name, $value)
if (empty(static::$additional_properties)) {
return true;
}
foreach (static::$additional_properties as $allowed_class) {
$fq_class = self::getFQCN($allowed_class);
foreach (static::$additional_properties as $allowed_type) {
if (gettype($value) === $allowed_type) {
return true;
}
$fq_class = self::getFQCN($allowed_type);
if ($value instanceof $fq_class) {
return true;
}
Expand All @@ -145,8 +155,11 @@ private function validateProperty($property_name, $value)
if (!isset($types[0])) {
return true;
}
foreach ($types as $allowed_class) {
$fq_class = self::getFQCN($allowed_class);
foreach ($types as $allowed_type) {
if (gettype($value) === $allowed_type) {
return true;
}
$fq_class = self::getFQCN($allowed_type);
if ($value instanceof $fq_class) {
return true;
}
Expand All @@ -160,6 +173,7 @@ private function validateProperty($property_name, $value)
* Parse a schema object into the correct objects
*
* @param $data
* @throws \Exception
*/
private function parseData($data)
{
Expand Down Expand Up @@ -193,6 +207,7 @@ private function parseData($data)
* @param $types_to_try
* @param $object
* @return BaseSchema
* @throws \Exception
*/
private static function tryToCast($types_to_try, $object)
{
Expand Down Expand Up @@ -225,6 +240,7 @@ protected static function getFQCN($relative_class)
/**
* @param array $data
* @return static
* @throws \Exception
*/
public static function create($data = [])
{
Expand Down
39 changes: 39 additions & 0 deletions src/Definitions/AnysOrExpressions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Calcinai\Strut\Definitions;

use Calcinai\Strut\BaseSchema;

class AnysOrExpressions extends BaseSchema
{
/**
* Array to store schema data and default values
* @var array
*/
protected $data = [];

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

/**
* Properties and types
* @var array
*/
protected static $properties = [];

/**
* Allowed additional properties
* @var array
*/
protected static $additional_properties = ['mixed', 'Definitions\\Expression'];

/**
* Array to store any allowed pattern properties
* @var array
*/
protected static $pattern_properties = [];

}
139 changes: 0 additions & 139 deletions src/Definitions/BodyParameter.php

This file was deleted.

42 changes: 42 additions & 0 deletions src/Definitions/Callback.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Calcinai\Strut\Definitions;

use Calcinai\Strut\BaseSchema;
/**
* A map of possible out-of band callbacks related to the parent operation. Each value in the map is a Path Item Object that describes a set of requests that may be initiated by the API provider and the expected responses. The key value used to identify the callback object is an expression, evaluated at runtime, that identifies a URL to use for the callback operation.
*/

class Callback extends BaseSchema
{
/**
* Array to store schema data and default values
* @var array
*/
protected $data = [];

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

/**
* Properties and types
* @var array
*/
protected static $properties = [];

/**
* Allowed additional properties
* @var array
*/
protected static $additional_properties = false;

/**
* Array to store any allowed pattern properties
* @var array
*/
protected static $pattern_properties = ['^' => ['Definitions\\PathItem'], '^x-' => ['null', 'integer', 'boolean', 'string', 'object', 'array']];

}
39 changes: 39 additions & 0 deletions src/Definitions/CallbacksOrReferences.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Calcinai\Strut\Definitions;

use Calcinai\Strut\BaseSchema;

class CallbacksOrReferences extends BaseSchema
{
/**
* Array to store schema data and default values
* @var array
*/
protected $data = [];

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

/**
* Properties and types
* @var array
*/
protected static $properties = [];

/**
* Allowed additional properties
* @var array
*/
protected static $additional_properties = ['Definitions\\Callback', 'Definitions\\Reference'];

/**
* Array to store any allowed pattern properties
* @var array
*/
protected static $pattern_properties = [];

}
Loading

0 comments on commit 13d6c1c

Please sign in to comment.