Exemplo n.º 1
0
 /**
  * @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);
 }
Exemplo n.º 2
0
 public function generate(Resource $resource)
 {
     $methods = $resource->getMethods();
     $definitions = array();
     $properties = array();
     foreach ($methods as $method) {
         $request = $method->getRequest();
         if ($request instanceof SchemaInterface) {
             list($defs, $props) = $this->getJsonSchema($request);
             $key = strtolower($method->getName()) . 'Request';
             $definitions = array_merge($definitions, $defs);
             if (isset($props['properties'])) {
                 $properties[$key] = $props;
             }
         }
         $response = $this->getSuccessfulResponse($method);
         if ($response instanceof SchemaInterface) {
             list($defs, $props) = $this->getJsonSchema($response);
             $key = strtolower($method->getName()) . 'Response';
             $definitions = array_merge($definitions, $defs);
             if (isset($props['properties'])) {
                 $properties[$key] = $props;
             }
         }
     }
     $result = array('$schema' => JsonSchemaGenerator::SCHEMA, 'id' => $this->targetNamespace, 'type' => 'object', 'definitions' => $definitions, 'properties' => $properties);
     return Json::encode($result, JSON_PRETTY_PRINT);
 }
Exemplo n.º 3
0
Arquivo: Wsdl.php Projeto: seytar/psx
 protected function getOperations(Resource $resource)
 {
     $operations = array();
     $methods = $resource->getMethods();
     foreach ($methods as $method) {
         $request = $method->getRequest();
         $response = $this->getSuccessfulResponse($method);
         if ($request instanceof SchemaInterface) {
             $entityName = $request->getDefinition()->getName();
         } elseif ($response instanceof SchemaInterface) {
             $entityName = $response->getDefinition()->getName();
         }
         $operation = new Operation(strtolower($method->getName()) . ucfirst($entityName));
         $operation->setMethod($method->getName());
         if ($request instanceof SchemaInterface) {
             $operation->setIn($request->getDefinition()->getName());
         }
         if ($response instanceof SchemaInterface) {
             $operation->setOut($response->getDefinition()->getName());
         }
         if ($operation->hasOperation()) {
             $operations[] = $operation;
         }
     }
     return $operations;
 }
 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);
 }
Exemplo n.º 5
0
 public function getDocumentation()
 {
     $table = $this->getTableSchema($this->getTable());
     $collection = $this->getCollectionSchema($table);
     $message = $this->getMessageSchema();
     $path = $this->context->get(Context::KEY_PATH);
     $resource = new Resource(Resource::STATUS_ACTIVE, $path);
     $method = new Resource\Get();
     $method->addQueryParameter(Property::getInteger('startIndex'));
     $method->addQueryParameter(Property::getInteger('count'));
     $method->addQueryParameter(Property::getInteger('totalResults'));
     $method->addResponse(200, $collection);
     $resource->addMethod($method);
     $method = new Resource\Post();
     $method->setRequest($table);
     $method->addResponse(200, $message);
     $resource->addMethod($method);
     $method = new Resource\Put();
     $method->setRequest($table);
     $method->addResponse(200, $message);
     $resource->addMethod($method);
     $method = new Resource\Delete();
     $method->setRequest($table);
     $method->addResponse(200, $message);
     $resource->addMethod($method);
     return new Documentation\Simple($resource);
 }
Exemplo n.º 6
0
 /**
  * @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;
 }
Exemplo n.º 7
0
 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);
 }
Exemplo n.º 8
0
 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;
 }
Exemplo n.º 9
0
Arquivo: Xsd.php Projeto: seytar/psx
 public function appendSchema(DOMElement $element, Resource $resource)
 {
     $methods = $resource->getMethods();
     foreach ($methods as $method) {
         $request = $method->getRequest();
         $response = $this->getSuccessfulResponse($method);
         $name = strtolower($method->getName()) . 'Request';
         if ($request instanceof SchemaInterface) {
             $this->appendSchemaElement($request, $element, $name);
         } else {
             $el = $element->ownerDocument->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:element');
             $el->setAttribute('name', $name);
             $el->setAttribute('type', 'tns:' . 'void');
             $element->appendChild($el);
         }
         $name = strtolower($method->getName()) . 'Response';
         if ($response instanceof SchemaInterface) {
             $this->appendSchemaElement($response, $element, $name);
         } else {
             $el = $element->ownerDocument->createElementNS('http://www.w3.org/2001/XMLSchema', 'xs:element');
             $el->setAttribute('name', $name);
             $el->setAttribute('type', 'tns:' . 'void');
             $element->appendChild($el);
         }
     }
     // add default schema types
     $this->appendDefaultSchema($element);
 }
Exemplo n.º 10
0
 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);
 }
Exemplo n.º 11
0
 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);
 }
Exemplo n.º 12
0
 protected function getApis(Resource $resource)
 {
     $api = new Api(ApiGeneration::transformRoutePlaceholder($resource->getPath()));
     $description = $resource->getDescription();
     $methods = $resource->getMethods();
     if (!empty($description)) {
         $api->setDescription($description);
     }
     foreach ($methods as $method) {
         // get operation name
         $request = $method->getRequest();
         $response = $this->getSuccessfulResponse($method);
         $description = $method->getDescription();
         $entityName = '';
         if ($request instanceof SchemaInterface) {
             $entityName = $request->getDefinition()->getName();
         } elseif ($response instanceof SchemaInterface) {
             $entityName = $response->getDefinition()->getName();
         }
         // create new operation
         $operation = new Operation($method->getName(), strtolower($method->getName()) . ucfirst($entityName));
         if (!empty($description)) {
             $operation->setSummary($description);
         }
         // path parameter
         $parameters = $resource->getPathParameters()->getDefinition();
         foreach ($parameters as $parameter) {
             $param = new Parameter('path', $parameter->getName(), $parameter->getDescription(), $parameter->isRequired());
             $this->setParameterType($parameter, $param);
             $operation->addParameter($param);
         }
         // query parameter
         $parameters = $method->getQueryParameters()->getDefinition();
         foreach ($parameters as $parameter) {
             $param = new Parameter('query', $parameter->getName(), $parameter->getDescription(), $parameter->isRequired());
             $this->setParameterType($parameter, $param);
             $operation->addParameter($param);
         }
         // request body
         if ($request instanceof SchemaInterface) {
             $description = $request->getDefinition()->getDescription();
             $type = strtolower($method->getName()) . 'Request';
             $parameter = new Parameter('body', 'body', $description, true);
             $parameter->setType($type);
             $operation->addParameter($parameter);
         }
         // response body
         $responses = $method->getResponses();
         foreach ($responses as $statusCode => $response) {
             $type = strtolower($method->getName()) . 'Response';
             $message = $response->getDefinition()->getDescription() ?: 'Response';
             $operation->addResponseMessage(new ResponseMessage($statusCode, $message, $type));
         }
         $api->addOperation($operation);
     }
     return array($api);
 }
Exemplo n.º 13
0
 public function onDelete()
 {
     $method = $this->resource->getMethod('DELETE');
     $record = $this->parseRequest($method);
     $response = $this->doDelete($record, $this->version);
     $this->sendResponse($method, $response);
 }
Exemplo n.º 14
0
 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;
 }
Exemplo n.º 15
0
 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;
 }
Exemplo n.º 16
0
 /**
  * @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;
 }
Exemplo n.º 17
0
 public function generate(Resource $resource)
 {
     $class = strtolower(str_replace('\\', '-', get_class($this)));
     $html = '<div class="psx-resource ' . $class . '" data-status="' . $resource->getStatus() . '" data-path="' . $resource->getPath() . '">';
     $html .= '<h4>' . $this->getName() . '</h4>';
     $description = $resource->getDescription();
     if (!empty($description)) {
         $html .= '<div class="psx-resource-description">' . $description . '</div>';
     }
     $methods = $resource->getMethods();
     foreach ($methods as $method) {
         $html .= '<div class="psx-resource-method" data-method="' . $method->getName() . '">';
         $description = $method->getDescription();
         if (!empty($description)) {
             $html .= '<div class="psx-resource-method-description">' . $description . '</div>';
         }
         // path parameters
         $pathParameters = $resource->getPathParameters();
         if ($pathParameters instanceof SchemaInterface) {
             $result = $this->generateHtml($pathParameters, self::TYPE_PATH, $method->getName(), $resource->getPath());
             if (!empty($result)) {
                 $html .= '<div class="psx-resource-data psx-resource-query">';
                 $html .= '<h5>' . $method->getName() . ' Path-Parameters</h5>';
                 $html .= '<div class="psx-resource-data-content">' . $result . '</div>';
                 $html .= '</div>';
             }
         }
         // query parameters
         $queryParameters = $method->getQueryParameters();
         if ($queryParameters instanceof SchemaInterface) {
             $result = $this->generateHtml($queryParameters, self::TYPE_QUERY, $method->getName(), $resource->getPath());
             if (!empty($result)) {
                 $html .= '<div class="psx-resource-data psx-resource-query">';
                 $html .= '<h5>' . $method->getName() . ' Query-Parameters</h5>';
                 $html .= '<div class="psx-resource-data-content">' . $result . '</div>';
                 $html .= '</div>';
             }
         }
         // request
         $request = $method->getRequest();
         if ($request instanceof SchemaInterface) {
             $result = $this->generateHtml($request, self::TYPE_REQUEST, $method->getName(), $resource->getPath());
             if (!empty($result)) {
                 $html .= '<div class="psx-resource-data psx-resource-request">';
                 $html .= '<h5>' . $method->getName() . ' Request</h5>';
                 $html .= '<div class="psx-resource-data-content">' . $result . '</div>';
                 $html .= '</div>';
             }
         }
         // responses
         $responses = $method->getResponses();
         foreach ($responses as $statusCode => $response) {
             $result = $this->generateHtml($response, self::TYPE_RESPONSE, $method->getName(), $resource->getPath(), $statusCode);
             if (!empty($result)) {
                 $message = isset(Http::$codes[$statusCode]) ? Http::$codes[$statusCode] : 'Unknown';
                 $html .= '<div class="psx-resource-data psx-resource-response">';
                 $html .= '<h5>' . $method->getName() . ' Response - ' . $statusCode . ' ' . $message . '</h5>';
                 $html .= '<div class="psx-resource-data-content">' . $result . '</div>';
                 $html .= '</div>';
             }
         }
         $html .= '</div>';
     }
     $html .= '</div>';
     return $html;
 }
Exemplo n.º 18
0
 /**
  * @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);
 }
Exemplo n.º 19
0
 /**
  * @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);
 }
Exemplo n.º 20
0
 /**
  * @expectedException \RuntimeException
  */
 public function testGetMethodInvalid()
 {
     $resource = new Resource(Resource::STATUS_ACTIVE, '/foo');
     $resource->getMethod('GET');
 }
Exemplo n.º 21
0
Arquivo: Raml.php Projeto: seytar/psx
 public function generate(Resource $resource)
 {
     $path = ApiGeneration::transformRoutePlaceholder($resource->getPath() ?: '/');
     $description = $resource->getDescription();
     $raml = '#%RAML 0.8' . "\n";
     $raml .= '---' . "\n";
     $raml .= 'baseUri: ' . Inline::dump($this->baseUri) . "\n";
     $raml .= 'version: v' . $this->version . "\n";
     $raml .= 'title: ' . Inline::dump($this->title) . "\n";
     $raml .= $path . ':' . "\n";
     if (!empty($description)) {
         $raml .= '  description: ' . Inline::dump($description) . "\n";
     }
     // path parameter
     $parameters = $resource->getPathParameters()->getDefinition();
     if (count($parameters) > 0) {
         $raml .= '  uriParameters:' . "\n";
         foreach ($parameters as $parameter) {
             $raml .= '    ' . $parameter->getName() . ':' . "\n";
             $this->setParameterType($parameter, $raml, 6);
         }
     }
     $generator = new SchemaGenerator\JsonSchema($this->targetNamespace);
     $methods = $resource->getMethods();
     foreach ($methods as $method) {
         $raml .= '  ' . strtolower($method->getName()) . ':' . "\n";
         // description
         $description = $method->getDescription();
         if (!empty($description)) {
             $raml .= '    description: ' . Inline::dump($description) . "\n";
         }
         // query parameter
         $parameters = $method->getQueryParameters()->getDefinition();
         if (count($parameters) > 0) {
             $raml .= '    queryParameters:' . "\n";
             foreach ($parameters as $parameter) {
                 $raml .= '      ' . $parameter->getName() . ':' . "\n";
                 $this->setParameterType($parameter, $raml, 8);
             }
         }
         // request body
         if ($method->hasRequest()) {
             $schema = $generator->generate($method->getRequest());
             $schema = str_replace("\n", "\n          ", $schema);
             $raml .= '    body:' . "\n";
             $raml .= '      application/json:' . "\n";
             $raml .= '        schema: |' . "\n";
             $raml .= '          ' . $schema . "\n";
         }
         // response body
         $raml .= '    responses:' . "\n";
         $responses = $method->getResponses();
         foreach ($responses as $statusCode => $response) {
             $schema = $generator->generate($response);
             $schema = str_replace("\n", "\n              ", $schema);
             $raml .= '      ' . $statusCode . ':' . "\n";
             $raml .= '        body:' . "\n";
             $raml .= '          application/json:' . "\n";
             $raml .= '            schema: |' . "\n";
             $raml .= '              ' . $schema . "\n";
         }
     }
     return $raml;
 }
Exemplo n.º 22
0
 /**
  * @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;
 }
Exemplo n.º 23
0
 /**
  * @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;
 }
Exemplo n.º 24
0
 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;
 }
Exemplo n.º 25
0
Arquivo: Raml.php Projeto: seytar/psx
 protected function parseUriParameters(Resource $resource, array $data)
 {
     if (isset($data['uriParameters']) && is_array($data['uriParameters'])) {
         foreach ($data['uriParameters'] as $name => $definition) {
             if (!empty($name) && is_array($definition)) {
                 $resource->addPathParameter($this->getParameter($name, $definition));
             }
         }
     }
 }