예제 #1
0
파일: Schema.php 프로젝트: gossi/swagger
 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);
 }
예제 #2
0
 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());
 }
예제 #3
0
파일: License.php 프로젝트: gossi/swagger
 private function parse($contents = [])
 {
     $data = CollectionUtils::toMap($contents);
     $this->name = $data->get('name');
     // extensions
     $this->parseUrl($data);
     $this->parseExtensions($data);
 }
예제 #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());
 }
예제 #6
0
파일: Items.php 프로젝트: gossi/swagger
 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()));
 }
예제 #8
0
파일: Response.php 프로젝트: gossi/swagger
 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);
 }
예제 #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));
         }
     }
 }
예제 #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);
 }
예제 #11
0
파일: Info.php 프로젝트: gossi/swagger
 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);
 }
예제 #13
0
파일: Tag.php 프로젝트: gossi/swagger
 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);
     }
 }
예제 #14
0
파일: Parameter.php 프로젝트: gossi/swagger
 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);
 }
예제 #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;
 }
예제 #16
0
파일: Operation.php 프로젝트: gossi/swagger
 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);
 }
예제 #17
0
파일: Swagger.php 프로젝트: gossi/swagger
 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);
 }
예제 #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;
 }
예제 #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;
 }
예제 #20
0
파일: Json.php 프로젝트: phootwork/json
 /**
  * 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));
 }
예제 #21
0
파일: Path.php 프로젝트: gossi/swagger
 public function toArray()
 {
     return array_merge(CollectionUtils::toArrayRecursive($this->operations), CollectionUtils::toArrayRecursive($this->getExtensions()));
 }
예제 #22
0
 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));
 }
예제 #23
0
파일: Headers.php 프로젝트: gossi/swagger
 public function toArray()
 {
     return CollectionUtils::toArrayRecursive($this->headers);
 }
예제 #24
0
 public function toArray()
 {
     return CollectionUtils::toArrayRecursive($this->definitions);
 }
예제 #25
0
파일: Responses.php 프로젝트: gossi/swagger
 public function toArray()
 {
     $responses = clone $this->responses;
     $responses->setAll($this->getExtensions());
     return CollectionUtils::toArrayRecursive($responses);
 }
예제 #26
0
 public function toArray()
 {
     return CollectionUtils::toArrayRecursive($this->schemes);
 }