/** * @return array */ public function toArray() { $data = parent::toArray(); $data['resources'] = $this->resources; $data['resourcesContent'] = $this->resourcesContent; return $data; }
/** * {@inheritdoc} */ public function handle(ApiDoc $annotation, array $annotations, Route $route, \ReflectionMethod $method) { foreach ($annotations as $description) { if (!$description instanceof ApiDescription) { continue; } $current = $annotation->toArray(); $request = []; foreach ($description->getRequest() as $name => $field) { $request[$name] = $this->convertField($field); } $annotation->setParameters(array_merge($annotation->getParameters(), $request)); if (!isset($current['response'])) { $response = []; foreach ($description->getResponse() as $name => $field) { $response[$name] = $this->convertField($field); } $annotation->setResponse($response); } } }
public function testConstructWithCache() { $data = array('cache' => '60'); $annot = new ApiDoc($data); $array = $annot->toArray(); $this->assertEquals($data['cache'], $array['cache']); }
/** * {@inheritdoc} */ public function formatOne(ApiDoc $annotation) { return $this->renderOne($this->processAnnotation($annotation->toArray())); }
public function testConstructWithMultipleTags() { $data = array('tags' => array('experimental' => '#0000ff', 'beta' => '#0000ff')); $annot = new ApiDoc($data); $array = $annot->toArray(); $this->assertTrue(is_array($array)); $this->assertTrue(is_array($array['tags']), 'Tags should be in array'); $this->assertEquals($data['tags'], $array['tags']); }
/** * {@inheritdoc} */ public function formatOne(ApiDoc $annotation) { return $annotation->toArray(); }
/** * @param $resource * @param ApiDoc $annotation * @param Resource|Resource $dunglasResource * @param Route $route * @return ApiDoc */ private function addFilters($resource, ApiDoc $annotation, Resource $dunglasResource, Route $route) { $data = $annotation->toArray(); $tags = isset($data['tags']) ? $data['tags'] : []; //filter embed if ('DELETE' !== $annotation->getMethod()) { $availableIncludes = $this->transformerHelper->getAvailableIncludes($resource); $defaultIncludes = $this->transformerHelper->getDefaultIncludes($resource); if (false === array_key_exists('embed', $tags)) { $annotation->addFilter('embed', ['requirement' => '\\t', 'description' => 'Include resources within other resources.', 'available' => is_array($availableIncludes) ? implode(',', $availableIncludes) : $availableIncludes, 'default' => is_array($defaultIncludes) ? implode(',', $defaultIncludes) : $defaultIncludes]); } else { unset($data['requirements']['embed']); $data['tags']['embed'] = "#298A08"; $path = explode('/', $route->getPath()); $embed = array_pop($path); $singularize = Inflector::singularize($embed); if ($embed !== $singularize) { $data['tags']['collection'] = "#0040FF"; } foreach ($data['requirements'] as $key => $value) { $data['requirements'][$key] = array_merge(['name' => $key], $value); } $annotation = new ApiDoc($data); $routeClone = clone $route; $annotation->setRoute($routeClone); $tags = isset($annotation->toArray()['tags']) ? $annotation->toArray()['tags'] : []; } } if (false !== array_key_exists('collection', $tags)) { foreach ($dunglasResource->getFilters() as $filter) { foreach ($filter->getDescription($dunglasResource) as $key => $value) { $annotation->addFilter($key, ['type' => isset($value['type']) ? $value['type'] : 'string', 'requirement' => isset($value['requirement']) ? $value['requirement'] : '[a-zA-Z0-9-]+', 'description' => isset($value['description']) ? $value['description'] : $key . ' filter', 'default' => '']); } } //filter perpage $annotation->addFilter('perpage', ['requirement' => '\\d+', 'description' => 'How many object return per page.', 'default' => 10]); //filter perpage $annotation->addFilter('page', ['requirement' => '\\d+', 'description' => 'How many page start to return.', 'default' => 1]); } return $annotation; }
public function testConstructWithRequestAndResponseBodyAsFile() { $data = array('requestBody' => array('file' => __DIR__ . '/../Fixtures/Resources/doc/exampleBody.json'), 'responseBody' => array('file' => __DIR__ . '/../Fixtures/Resources/doc/exampleBody.json')); $annot = new ApiDoc($data); $array = $annot->toArray(); $this->assertTrue(is_array($array)); $this->assertTrue(!empty($array['requestBodyExample'])); $this->assertTrue(!empty($array['responseBodyExample'])); }
public function testConstructWithParameters() { $data = array('parameters' => array(array('name' => 'fooId', 'dataType' => 'integer', 'description' => 'Some description'))); $annot = new ApiDoc($data); $array = $annot->toArray(); $this->assertTrue(is_array($array)); $this->assertTrue(isset($array['parameters']['fooId'])); $this->assertTrue(isset($array['parameters']['fooId']['dataType'])); }
public function testConstructWithHTTPResponseCodes() { $data = array('description' => 'Heya', 'statusCodes' => array(200 => "Returned when successful", 403 => "Returned when the user is not authorized")); $annot = new ApiDoc($data); $array = $annot->toArray(); $this->assertTrue(is_array($array)); $this->assertTrue(is_array($array['statusCodes'])); foreach ($data['statusCodes'] as $code => $message) { $this->assertEquals($array['statusCodes'][$code], $message); } }
public function toArray() { $array = parent::toArray(); $array['uri'] = $this->getRpcMethod() ? $this->getRpcMethod()->getMethod() : ''; // $array['method'] = 'RPC'; return $array; }