public function parse($schema, $path) { $this->data = $this->parser->parse($schema); $path = ApiGeneration::transformRoutePlaceholder($path); if (isset($this->data[$path]) && is_array($this->data[$path])) { $resource = $this->parseResource($this->data[$path], $path); } else { // we check whether the path is nested $parts = explode('/', trim($path, '/')); $data = $this->data; foreach ($parts as $part) { if (isset($data['/' . $part])) { $data = $data['/' . $part]; } else { $data = null; break; } } if (!empty($data) && is_array($data)) { $resource = $this->parseResource($data, $path); } else { throw new RuntimeException('Could not find resource definition "' . $path . '" in RAML schema'); } } $version = $this->getNormalizedVersion(); $title = null; if (isset($this->data['title'])) { $title = $this->data['title']; } $doc = new Documentation\Version($title); $doc->addResource($version, $resource); return $doc; }
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; }
public function testGetLatestVersionNoResource() { $version = new Version(); $this->assertEquals(1, $version->getLatestVersion()); }
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; }