Exemplo n.º 1
0
 protected function getJsonSchema(SchemaInterface $schema)
 {
     $generator = new JsonSchemaGenerator($this->targetNamespace);
     $data = json_decode($generator->generate($schema), true);
     $definitions = array();
     unset($data['$schema']);
     unset($data['id']);
     if (isset($data['definitions'])) {
         $definitions = $data['definitions'];
         unset($data['definitions']);
     }
     return [$definitions, $data];
 }
Exemplo n.º 2
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;
 }