public function getDocumentation() { $resource = new Resource(Resource::STATUS_ACTIVE, $this->context->get(Context::KEY_PATH)); $resource->addMethod(Resource\Factory::getMethod('GET')->addQueryParameter(Property::getInteger('type'))->addResponse(200, $this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\Property'))); $resource->addMethod(Resource\Factory::getMethod('POST')->setRequest($this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\Property'))->addResponse(200, $this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\Property'))); return new Documentation\Simple($resource); }
/** * @param integer $version * @return \PSX\Api\Resource */ public function getDocumentation($version = null) { $resource = new Resource(Resource::STATUS_ACTIVE, $this->context->get(Context::KEY_PATH)); $resource->addMethod(Resource\Factory::getMethod('GET')->addResponse(200, $this->schemaManager->getSchema('Fusio\\Impl\\Consumer\\Schema\\Account'))); $resource->addMethod(Resource\Factory::getMethod('PUT')->setRequest($this->schemaManager->getSchema('Fusio\\Impl\\Consumer\\Schema\\Account'))->addResponse(200, $this->schemaManager->getSchema('Fusio\\Impl\\Backend\\Schema\\Message'))); return $resource; }
public function getDocumentation() { $resource = new Resource(Resource::STATUS_ACTIVE, $this->context->get(Context::KEY_PATH)); $resource->addMethod(Resource\Factory::getMethod('GET')); $resource->addMethod(Resource\Factory::getMethod('DELETE')); return new Documentation\Simple($resource); }
public function getDocumentation() { $doc = new Documentation\Version(); $resource = new Resource(Resource::STATUS_CLOSED, $this->context->get(Context::KEY_PATH)); $resource->addMethod(Resource\Factory::getMethod('GET')->addResponse(200, $this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\Collection'))); $resource->addMethod(Resource\Factory::getMethod('POST')->setRequest($this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\Create'))->addResponse(200, $this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\SuccessMessage'))); $resource->addMethod(Resource\Factory::getMethod('PUT')->setRequest($this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\Update'))->addResponse(200, $this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\SuccessMessage'))); $resource->addMethod(Resource\Factory::getMethod('DELETE')->setRequest($this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\Delete'))->addResponse(200, $this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\SuccessMessage'))); $doc->addResource(1, $resource); $resource = new Resource(Resource::STATUS_DEPRECATED, $this->context->get(Context::KEY_PATH)); $resource->addMethod(Resource\Factory::getMethod('GET')->addResponse(200, $this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\Collection'))); $resource->addMethod(Resource\Factory::getMethod('POST')->setRequest($this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\Create'))->addResponse(200, $this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\SuccessMessage'))); $resource->addMethod(Resource\Factory::getMethod('PUT')->setRequest($this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\Update'))->addResponse(200, $this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\SuccessMessage'))); $resource->addMethod(Resource\Factory::getMethod('DELETE')->setRequest($this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\Delete'))->addResponse(200, $this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\SuccessMessage'))); $doc->addResource(2, $resource); $resource = new Resource(Resource::STATUS_ACTIVE, $this->context->get(Context::KEY_PATH)); $resource->setTitle('foo'); $resource->setDescription('lorem ipsum'); $resource->addPathParameter(Property::getString('name')->setDescription('Name parameter')->setRequired(false)->setMinLength(0)->setMaxLength(16)->setPattern('[A-z]+')); $resource->addPathParameter(Property::getString('type')->setEnumeration(['foo', 'bar'])); $resource->addMethod(Resource\Factory::getMethod('GET')->setDescription('Returns a collection')->addQueryParameter(Property::getInteger('startIndex')->setDescription('startIndex parameter')->setRequired(false)->setMin(0)->setMax(32))->addQueryParameter(Property::getFloat('float'))->addQueryParameter(Property::getBoolean('boolean'))->addQueryParameter(Property::getDate('date'))->addQueryParameter(Property::getDateTime('datetime'))->addResponse(200, $this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\Collection'))); $resource->addMethod(Resource\Factory::getMethod('POST')->setRequest($this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\Create'))->addResponse(200, $this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\SuccessMessage'))); $resource->addMethod(Resource\Factory::getMethod('PUT')->setRequest($this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\Update'))->addResponse(200, $this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\SuccessMessage'))); $resource->addMethod(Resource\Factory::getMethod('DELETE')->setRequest($this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\Delete'))->addResponse(200, $this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\SuccessMessage'))); $doc->addResource(3, $resource); return $doc; }
/** * @return \PSX\Api\DocumentationInterface */ public function getDocumentation() { $resource = new Resource(Resource::STATUS_ACTIVE, $this->context->get(Context::KEY_PATH)); $resource->addMethod(Resource\Factory::getMethod('GET')->addResponse(200, $this->schemaManager->getSchema('Fusio\\Backend\\Schema\\Routes\\Collection'))); $resource->addMethod(Resource\Factory::getMethod('POST')->setRequest($this->schemaManager->getSchema('Fusio\\Backend\\Schema\\Routes\\Create'))->addResponse(201, $this->schemaManager->getSchema('Fusio\\Backend\\Schema\\Message'))); return new Documentation\Simple($resource); }
public function getDocumentation() { $resource = new Resource(Resource::STATUS_ACTIVE, $this->context->get(Context::KEY_PATH)); $resource->addPathParameter(Property::getInteger('fooId')); $resource->addMethod(Resource\Factory::getMethod('GET')->addQueryParameter(Property::getInteger('startIndex'))->addQueryParameter(Property::getInteger('count'))->addResponse(200, $this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\Collection'))); $resource->addMethod(Resource\Factory::getMethod('PUT')->setRequest($this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\Update'))->addResponse(200, $this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\SuccessMessage'))); $resource->addMethod(Resource\Factory::getMethod('DELETE')->setRequest($this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\Delete'))->addResponse(200, $this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\SuccessMessage'))); return new Documentation\Simple($resource); }
public function getDocumentation() { $resource = new Resource(Resource::STATUS_ACTIVE, $this->context->get(Context::KEY_PATH)); $resource->addMethod(Resource\Factory::getMethod('GET')->addResponse(200, $this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\Collection'))); $resource->addMethod(Resource\Factory::getMethod('POST')->setRequest($this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\Create'))->addResponse(201, $this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\SuccessMessage'))); $resource->addMethod(Resource\Factory::getMethod('PUT')->setRequest($this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\Update'))->addResponse(200, $this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\SuccessMessage'))); $resource->addMethod(Resource\Factory::getMethod('DELETE')->setRequest($this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\Delete'))->addResponse(200, $this->schemaManager->getSchema('PSX\\Controller\\Foo\\Schema\\SuccessMessage'))); return new Documentation\Simple($resource); }
public function testResource() { $resource = new Resource(Resource::STATUS_ACTIVE, '/foo'); $resource->setTitle('foobar'); $resource->setDescription('foobar'); $resource->addPathParameter(Property::getString('foo')); $resource->addMethod(Factory::getMethod('GET')); $this->assertEquals(Resource::STATUS_ACTIVE, $resource->getStatus()); $this->assertTrue($resource->isActive()); $this->assertFalse($resource->isDeprecated()); $this->assertFalse($resource->isClosed()); $this->assertEquals('/foo', $resource->getPath()); $this->assertEquals('foobar', $resource->getTitle()); $this->assertEquals('foobar', $resource->getDescription()); $this->assertInstanceOf('PSX\\Data\\SchemaInterface', $resource->getPathParameters()); $this->assertInstanceOf('PSX\\Api\\Resource\\MethodAbstract', $resource->getMethod('GET')); $this->assertEquals(['GET' => $resource->getMethod('GET')], $resource->getMethods()); $this->assertEquals(['GET'], $resource->getAllowedMethods()); $this->assertTrue($resource->hasMethod('GET')); $this->assertFalse($resource->hasMethod('POST')); }
public function getDocumentation($routeId, $version, $path) { if ($version == '*' || empty($version)) { $version = $this->methodTable->getLatestVersion($routeId); } $methods = $this->methodTable->getMethods($routeId, $version, true); $resource = new Resource($this->getStatusFromMethods($methods), $path); foreach ($methods as $method) { $resourceMethod = Resource\Factory::getMethod($method['method']); if ($method['status'] == Resource::STATUS_DEVELOPMENT) { if (!empty($method['request'])) { $resourceMethod->setRequest(new LazySchema($this->schemaLoader, $method['request'])); } } else { if (!empty($method['requestCache'])) { $request = unserialize($method['requestCache']); if ($request instanceof SchemaInterface) { $resourceMethod->setRequest($request); } } } if ($method['status'] == Resource::STATUS_DEVELOPMENT) { if (!empty($method['response'])) { $resourceMethod->addResponse(200, new LazySchema($this->schemaLoader, $method['response'])); } } else { if (!empty($method['responseCache'])) { $response = unserialize($method['responseCache']); if ($response instanceof SchemaInterface) { $resourceMethod->addResponse(200, $response); } } } $resource->addMethod($resourceMethod); } return $resource; }
public function getResourceIndex() { $collections = $this->routingParser->getCollection(); $result = array(); foreach ($collections as $collection) { list($methods, $path, $source) = $collection; $parts = explode('::', $source, 2); $className = isset($parts[0]) ? $parts[0] : null; $resource = new Resource(Resource::STATUS_ACTIVE, $path); foreach ($methods as $methodName) { $method = Resource\Factory::getMethod($methodName); if ($method instanceof MethodAbstract) { $resource->addMethod($method); } } // because creating a new instance of an controller is expensive // since we resolve all dependencies we use class_implements to // check whether this is an documented API endpoint if (class_exists($className) && in_array('PSX\\Api\\DocumentedInterface', class_implements($className))) { $result[] = $resource; } } return $result; }
/** * @expectedException \RuntimeException */ public function testGetResponseInvalid() { Factory::getMethod('POST')->getResponse(500); }
/** * @return \PSX\Api\DocumentationInterface */ public function getDocumentation() { $resource = new Resource(Resource::STATUS_ACTIVE, $this->context->get(Context::KEY_PATH)); $resource->addMethod(Resource\Factory::getMethod('PUT')->setRequest($this->schemaManager->getSchema('Fusio\\Impl\\Backend\\Schema\\Account\\ChangePassword'))->addResponse(200, $this->schemaManager->getSchema('Fusio\\Impl\\Backend\\Schema\\Message'))); return new Documentation\Simple($resource); }
/** * @return \PSX\Api\DocumentationInterface */ public function getDocumentation() { $resource = new Resource(Resource::STATUS_ACTIVE, $this->context->get(Context::KEY_PATH)); $resource->addMethod(Resource\Factory::getMethod('GET')->addResponse(200, $this->schemaManager->getSchema('Fusio\\Impl\\Backend\\Schema\\Log'))); return new Documentation\Simple($resource); }
protected function parseResource(array $data, $path) { $resource = new Resource(Resource::STATUS_ACTIVE, $path); if (isset($data['displayName'])) { $resource->setTitle($data['displayName']); } if (isset($data['description'])) { $resource->setDescription($data['description']); } $this->parseUriParameters($resource, $data); $mergedTrait = array(); if (isset($data['is']) && is_array($data['is'])) { foreach ($data['is'] as $traitName) { $trait = $this->getTrait($traitName); if (is_array($trait)) { $mergedTrait = array_merge_recursive($mergedTrait, $trait); } } } foreach ($data as $methodName => $row) { if (in_array($methodName, ['get', 'post', 'put', 'delete']) && is_array($row)) { if (!empty($mergedTrait)) { $row = array_merge_recursive($row, $mergedTrait); } $method = Resource\Factory::getMethod(strtoupper($methodName)); if (isset($row['description'])) { $method->setDescription($row['description']); } $this->parseQueryParameters($method, $row); $this->parseRequest($method, $row); $this->parseResponses($method, $row); $resource->addMethod($method); } } return $resource; }
public function getDocumentation() { $doc = new Documentation\Version(); $config = $this->context->get('fusio.config'); foreach ($config as $version) { $resource = new Resource($version->getStatus(), $this->context->get(Context::KEY_PATH)); $methods = $version->getMethods(); foreach ($methods as $method) { if ($method->getActive()) { $resourceMethod = Resource\Factory::getMethod($method->getName()); if (is_int($method->getRequest())) { $resourceMethod->setRequest(new LazySchema($this->schemaLoader, $method->getRequest())); } elseif ($method->getRequest() instanceof SchemaInterface) { $resourceMethod->setRequest($method->getRequest()); } if (is_int($method->getResponse())) { $resourceMethod->addResponse(200, new LazySchema($this->schemaLoader, $method->getResponse())); } elseif ($method->getRequest() instanceof SchemaInterface) { $resourceMethod->addResponse(200, $method->getResponse()); } $resource->addMethod($resourceMethod); } } $doc->addResource($version->getName(), $resource); } return $doc; }
/** * @param integer $version * @return \PSX\Api\Resource */ public function getDocumentation($version = null) { $resource = new Resource(Resource::STATUS_ACTIVE, $this->context->get(Context::KEY_PATH)); $resource->addMethod(Resource\Factory::getMethod('DELETE')); return $resource; }
/** * @param integer $version * @return \PSX\Api\Resource */ public function getDocumentation($version = null) { $resource = new Resource(Resource::STATUS_ACTIVE, $this->context->get(Context::KEY_PATH)); $resource->addMethod(Resource\Factory::getMethod('GET')->addResponse(200, $this->schemaManager->getSchema('Fusio\\Impl\\Consumer\\Schema\\App\\Grant\\Collection'))); return $resource; }
/** * @param integer $version * @return \PSX\Api\Resource */ public function getDocumentation($version = null) { $resource = new Resource(Resource::STATUS_ACTIVE, $this->context->get(Context::KEY_PATH)); $resource->addMethod(Resource\Factory::getMethod('POST')->addResponse(200, $this->schemaManager->getSchema('Fusio\\Impl\\Backend\\Schema\\Schema\\Preview\\Response'))); return $resource; }