Ejemplo n.º 1
0
 /**
  * Get an array representation of this object.
  *
  * @return array
  */
 public function toArray()
 {
     return RamlUtils::filterEmptyValues(['example' => $this->example, 'schema' => $this->schema, 'formParameters' => Std::map(function (RamlParameter $parameter) {
         return $parameter->toArray();
     }, $this->formParameters)]);
 }
Ejemplo n.º 2
0
 /**
  * Get an array representation of this object.
  *
  * @return array
  */
 public function toArray()
 {
     return RamlUtils::filterEmptyValues(['displayName' => $this->displayName, 'description' => $this->description, 'type' => $this->type, 'enum' => $this->enum, 'pattern' => $this->pattern, 'minLength' => $this->minLength, 'maxLength' => $this->maxLength, 'minimum' => $this->minimum, 'maximum' => $this->maximum, 'example' => $this->example, 'repeat' => $this->repeat, 'required' => $this->required, 'default' => $this->default]);
 }
Ejemplo n.º 3
0
 /**
  * Get an array representation of this object.
  *
  * @return array
  */
 public function toArray()
 {
     return RamlUtils::filterEmptyValues(['description' => $this->description, 'type' => $this->type, 'describedBy' => RamlUtils::filterEmptyValues(['headers' => Std::map(function (RamlParameter $header) {
         return $header->toArray();
     }, $this->headers), 'queryParameters' => Std::map(function (RamlParameter $query) {
         return $query->toArray();
     }, $this->queryParameters), 'responses' => $this->responses ? $this->responses->toArray() : null]), 'settings' => $this->settings]);
 }
Ejemplo n.º 4
0
 protected function encodeResource(ResourceFactory $resource, RamlEncoderOptions $options)
 {
     $controller = $this->app->make($resource->getController());
     $ramlResource = ['displayName' => $resource->getName(), 'description' => $resource->getDescription()];
     foreach ($resource->getMethods() as $method) {
         $ramlAction = ['securedBy' => $this->middlewareToSecuritySchemes($options, $resource->getMiddleware())];
         if ($controller instanceof AnnotatedControllerInterface) {
             $ramlAction['description'] = $controller->getMethodDescription($method->getMethod());
             $ramlAction['body'] = $this->requestsToBody($controller->getMethodExampleRequests($method->getMethod()))->toArray();
             $ramlAction['responses'] = $this->responsesToGroup($controller->getMethodExampleResponses($method->getMethod()))->toArray();
         } else {
             $ramlAction['description'] = 'This method does not provide a description';
         }
         $reflector = new ResourceReflector($this->app);
         $request = $reflector->getMethodRequest($resource, $method);
         $uriParameters = [];
         $queryParameters = [];
         if ($request instanceof ApiCheckableRequest) {
             $spec = $request->getCheckable();
             if ($spec instanceof Validator) {
                 $spec = $spec->getSpec();
             }
             if ($spec instanceof Spec) {
                 if ($method->getVerb() == HttpMethods::POST || $method->getVerb() == HttpMethods::PUT || $method->getVerb() == HttpMethods::DELETE) {
                     $this->addPostSchema($ramlResource, $ramlAction, $uriParameters, $resource, $method, $spec, $reflector);
                 } else {
                     $parameters = $reflector->getMethodParameters($resource, $method);
                     $fields = array_unique(array_merge(array_keys($spec->getConstraints()), array_keys($spec->getDefaults()), $spec->getRequired()));
                     foreach ($fields as $field) {
                         if (in_array($field, $parameters)) {
                             $uriParameters[$field] = $this->specFieldToParameter($spec, $field);
                             continue;
                         }
                         $queryParameters[$field] = $this->specFieldToParameter($spec, $field);
                     }
                 }
             }
         }
         if (!Arr::has($ramlResource, $method->getPath())) {
             $ramlResource[$method->getPath()] = [];
         }
         $ramlResource[$method->getPath()]['uriParameters'] = $uriParameters;
         $ramlAction['queryParameters'] = $queryParameters;
         $verb = strtolower($method->getVerb());
         $ramlResource[$method->getPath()][$verb] = RamlUtils::filterEmptyValues($ramlAction);
         $ramlResource[$method->getPath()] = RamlUtils::filterEmptyValues($ramlResource[$method->getPath()]);
     }
     return RamlUtils::filterEmptyValues($ramlResource);
 }
Ejemplo n.º 5
0
 /**
  * Get an array representation of this object.
  *
  * @return array
  */
 public function toArray()
 {
     return RamlUtils::filterEmptyValues(['description' => $this->description, 'body' => $this->body ? $this->body->toArray() : null]);
 }