Example #1
0
 private function parse($contents = [])
 {
     $data = CollectionUtils::toMap($contents);
     $this->title = $data->get('title');
     $this->discriminator = $data->get('discriminator');
     $this->readOnly = $data->has('readOnly') && $data->get('readOnly');
     $this->example = $data->get('example');
     $this->required = $data->get('required');
     $this->properties = new Definitions($data->get('properties'));
     if ($data->has('additionalProperties')) {
         $this->additionalProperties = new self($data->get('additionalProperties'));
     }
     $this->allOf = new ArrayList();
     if ($data->has('allOf')) {
         foreach ($data->get('allOf') as $schema) {
             $this->allOf->add(new self($schema));
         }
     }
     // parts
     $this->parseRef($data);
     $this->parseType($data);
     $this->parseDescription($data);
     $this->parseItems($data);
     $this->parseExternalDocs($data);
     $this->parseExtensions($data);
 }
 private function parse($contents)
 {
     $this->data = CollectionUtils::toMap($contents);
     $this->models = $this->data->get('models', new Map());
     $this->excluded = $this->data->get('excluded', new Map());
     $this->api = $this->data->get('api', new Map());
 }
Example #3
0
 private function parse($contents = [])
 {
     $data = CollectionUtils::toMap($contents);
     $this->name = $data->get('name');
     // extensions
     $this->parseUrl($data);
     $this->parseExtensions($data);
 }
Example #4
0
 private function parse($contents = [])
 {
     $data = CollectionUtils::toMap($contents);
     // parts
     $this->parseDescription($data);
     $this->parseUrl($data);
     $this->parseExtensions($data);
 }
 public function testExport()
 {
     $data = [1, 2, ['a' => 'b', 'c' => [7, 8, 9]], 4];
     $map = CollectionUtils::fromArray($data);
     $this->assertSame($data, $map->toArray());
     $data = ['a' => 'b', 'c' => [1, ['x' => 'y'], 4], 'd' => 'e'];
     $list = CollectionUtils::fromArray($data);
     $this->assertSame($data, $list->toArray());
 }
Example #6
0
 private function parse($contents = [])
 {
     $data = CollectionUtils::toMap($contents);
     // parts
     $this->parseRef($data);
     $this->parseType($data);
     $this->parseItems($data);
     $this->parseExtensions($data);
 }
 public function testExport()
 {
     $data = [1, 2, ['a' => 'b', 'c' => [7, 8, 9]], 4];
     $list = CollectionUtils::fromCollection($data);
     $this->assertEquals(4, count($list->toArray()));
     $data = ['a' => 'b', 'c' => [1, ['x' => 'y'], 4], 'd' => 'e'];
     $map = CollectionUtils::fromCollection($data);
     $this->assertEquals(3, count($map->toArray()));
 }
Example #8
0
 private function parse($contents)
 {
     $data = CollectionUtils::toMap($contents);
     $this->examples = $data->get('examples', new Map());
     $this->headers = new Headers($data->get('headers'));
     // parts
     $this->parseRef($data);
     $this->parseDescription($data);
     $this->parseSchema($data);
     $this->parseExtensions($data);
 }
Example #9
0
 private function parse($contents)
 {
     $data = CollectionUtils::toList($contents);
     // schemes
     $this->securities = new Map();
     foreach ($data as $security) {
         foreach ($security as $id => $scopes) {
             $this->securities->set($id, new Set($scopes));
         }
     }
 }
Example #10
0
 /**
  * @param array $contents
  */
 private function parse($contents = [])
 {
     $data = CollectionUtils::toMap($contents);
     $this->type = $data->get('type');
     $this->name = $data->get('name');
     $this->in = $data->get('in');
     $this->flow = $data->get('flow');
     $this->authorizationUrl = $data->get('authorizationUrl');
     $this->tokenUrl = $data->get('tokenUrl');
     $this->scopes = $data->get('scopes', new Map());
     $this->parseDescription($data);
 }
Example #11
0
 private function parse($contents = [])
 {
     $data = CollectionUtils::toMap($contents);
     $this->title = $data->get('title');
     $this->termsOfService = $data->get('termsOfService');
     $this->contact = new Contact($data->get('contact', new Map()));
     $this->license = new License($data->get('license', new Map()));
     $this->version = $data->get('version');
     // extensions
     $this->parseDescription($data);
     $this->parseExtensions($data);
 }
 public function testComplex()
 {
     $data = [['a' => 'b'], ['c' => 'd']];
     $list = CollectionUtils::fromArray($data);
     $this->assertTrue($list instanceof ArrayList);
     $this->assertTrue($list->get(1) instanceof Map);
     $data = ['a' => [1, 2, 3], 'c' => 'd'];
     $map = CollectionUtils::fromArray($data);
     $this->assertTrue($map instanceof Map);
     $this->assertTrue($map->get('a') instanceof ArrayList);
     $data = ['a' => 'b', 'c' => [1, ['x' => 'y'], 4], 'd' => 'e'];
     $map = CollectionUtils::fromArray($data);
     $this->assertTrue($map->get('c')->get(1) instanceof Map);
 }
Example #13
0
 private function parse($contents = [])
 {
     if (is_string($contents)) {
         $this->isObject = false;
         $this->name = $contents;
     } else {
         $data = CollectionUtils::toMap($contents);
         $this->isObject = true;
         $this->name = $data->get('name');
         // parts
         $this->parseDescription($data);
         $this->parseExternalDocs($data);
         $this->parseExtensions($data);
     }
 }
Example #14
0
 private function parse($contents = [])
 {
     $data = CollectionUtils::toMap($contents);
     $this->name = $data->get('name');
     $this->in = $data->get('in');
     $this->allowEmptyValue = $data->has('allowEmptyValue') && $data->get('allowEmptyValue');
     // parts
     $this->parseRef($data);
     $this->parseDescription($data);
     $this->parseSchema($data);
     $this->parseRequired($data);
     $this->parseType($data);
     $this->parseItems($data);
     $this->parseExtensions($data);
 }
Example #15
0
 /**
  * @param array $contents
  */
 protected function parse($contents = [])
 {
     $data = new Map($contents);
     $this->title = $data->get('title', '');
     $this->class = $data->get('class', '');
     $this->extensionPoints = $data->get('extension-points', new Map());
     $this->extensions = new Map();
     $extensions = CollectionUtils::toMap($data->get('extensions', []));
     foreach ($extensions as $key => $val) {
         $this->extensions->set($key, $val->map(function ($v) {
             return $v->toArray();
         }));
     }
     return $data;
 }
Example #16
0
 private function parse($contents = [])
 {
     $data = CollectionUtils::toMap($contents);
     $this->summary = $data->get('summary');
     $this->description = $data->get('description');
     $this->operationId = $data->get('operationId');
     $this->deprecated = $data->has('deprecated') && $data->get('deprecated');
     // parts
     $this->parseConsumes($data);
     $this->parseProduces($data);
     $this->parseTags($data);
     $this->parseParameters($data);
     $this->parseResponses($data);
     $this->parseSchemes($data);
     $this->parseSecurity($data);
     $this->parseExternalDocs($data);
     $this->parseExtensions($data);
 }
Example #17
0
 private function parse($contents)
 {
     $data = CollectionUtils::toMap($contents);
     $this->swagger = $data->get('version', $this->swagger);
     $this->host = $data->get('host');
     $this->basePath = $data->get('basePath');
     $this->info = new Info($data->get('info', []));
     $this->paths = new Paths($data->get('paths'));
     $this->definitions = new Definitions($data->get('definitions', new Map()));
     $this->securityDefinitions = new SecurityDefinitions($data->get('securityDefinitions', new Map()));
     // parts
     $this->parseSchemes($data);
     $this->parseConsumes($data);
     $this->parseProduces($data);
     $this->parseTags($data);
     $this->parseParameters($data);
     $this->parseResponses($data);
     $this->parseSecurity($data);
     $this->parseExternalDocs($data);
     $this->parseExtensions($data);
 }
Example #18
0
 private function parse($contents)
 {
     $data = new Map($contents);
     $this->setFullName($data->get('name'));
     $this->description = $data->get('description');
     $this->type = $data->get('type');
     $this->license = $data->get('license');
     $this->keywords = new ArrayList($data->get('keywords', []));
     $this->authors = new ArrayList();
     if ($data->has('authors')) {
         foreach ($data->get('authors') as $authorData) {
             $this->authors->add(new AuthorSchema($authorData));
         }
     }
     $this->autoload = new AutoloadSchema($data->get('autoload', []));
     $this->require = new Map($data->get('require', []));
     $this->requireDev = new Map($data->get('require-dev', []));
     $this->extra = CollectionUtils::toMap($data->get('extra', []));
     $this->keeko = new KeekoSchema($this, $this->extra->get('keeko', []));
     $this->data = $data;
 }
Example #19
0
 protected function export()
 {
     $cols = func_get_args();
     // add cols
     if (method_exists($this, 'hasRef') && $this->hasRef()) {
         $cols = array_merge(['$ref'], $cols);
     }
     // flatten array
     $fields = [];
     array_walk_recursive($cols, function ($a) use(&$fields) {
         $fields[] = $a;
     });
     $out = [];
     $refl = new \ReflectionClass(get_class($this));
     foreach ($fields as $field) {
         if ($field == 'tags') {
             $val = $this->exportTags();
         } else {
             $prop = $refl->getProperty($field == '$ref' ? 'ref' : $field);
             $prop->setAccessible(true);
             $val = $prop->getValue($this);
             if ($val instanceof Collection) {
                 $val = CollectionUtils::toArrayRecursive($val);
             } else {
                 if (is_object($val) && method_exists($val, 'toArray')) {
                     $val = $val->toArray();
                 }
             }
         }
         if ($field == 'required' && is_bool($val) || !empty($val)) {
             $out[$field] = $val;
         }
     }
     if (method_exists($this, 'getExtensions')) {
         $out = array_merge($out, $this->getExtensions()->toArray());
     }
     return $out;
 }
Example #20
0
 /**
  * Returns a collection (list or map) of the provided json
  *
  * @param string $json
  * @return ArrayList
  */
 public static function toCollection($json)
 {
     return CollectionUtils::fromArray(json_decode($json, true));
 }
Example #21
0
 public function toArray()
 {
     return array_merge(CollectionUtils::toArrayRecursive($this->operations), CollectionUtils::toArrayRecursive($this->getExtensions()));
 }
 public function testToRecursiveArray()
 {
     $data = ['a' => 'b', 'c' => [1, ['x' => 'y'], 4], 'd' => ['x' => 'y', 'z' => 'zz']];
     $collection = CollectionUtils::fromCollection($data);
     $this->assertEquals($data, CollectionUtils::toArrayRecursive($collection));
 }
Example #23
0
 public function toArray()
 {
     return CollectionUtils::toArrayRecursive($this->headers);
 }
Example #24
0
 public function toArray()
 {
     return CollectionUtils::toArrayRecursive($this->definitions);
 }
Example #25
0
 public function toArray()
 {
     $responses = clone $this->responses;
     $responses->setAll($this->getExtensions());
     return CollectionUtils::toArrayRecursive($responses);
 }
Example #26
0
 public function toArray()
 {
     return CollectionUtils::toArrayRecursive($this->schemes);
 }