/**
  * Get Handler
  *
  * @param OperationReference $operation
  *
  * @return array
  */
 public function getHandler(OperationReference $operation)
 {
     // remove route parameters
     $path = preg_replace('/\\/\\{.*\\}/', '', $operation->getPath());
     // lowerCamelCase to UpperCamelCase
     $paths = explode('/', $path);
     // path start with a /
     unset($paths[0]);
     $paths = array_map(function ($path) {
         return ucfirst($path);
     }, $paths);
     // path to 'relative' namespace
     $path = implode('\\', $paths);
     $controller = $this->namespace . $path . 'Controller';
     return ['uses' => $controller . '@' . $this->httpVerbToControllerMethod[strtoupper($operation->getMethod())], 'as' => $operation->getOperationId()];
 }
示例#2
0
 /**
  * get the schema
  *
  * @param OperationReference $service service endpoint
  *
  * @return \stdClass
  */
 private function getServiceSchema($service)
 {
     $operation = $service->getOperation();
     $schema = new \stdClass();
     switch (strtolower($service->getMethod())) {
         case "post":
         case "put":
             try {
                 $parameters = $operation->getDocumentObjectProperty('parameters', Parameter\Body::class, true);
             } catch (MissingDocumentPropertyException $e) {
                 // request has no params
                 break;
             }
             foreach ($parameters as $parameter) {
                 /**
                  * there is no schema information available, if $action->parameters[0]->in != 'body'
                  *
                  * @link http://swagger.io/specification/#parameterObject
                  */
                 if ($parameter instanceof Parameter\Body && $parameter->getIn() === 'body') {
                     $ref = $parameter->getDocumentObjectProperty('schema', Reference::class)->getDocument();
                     $schema = $this->resolveSchema($ref);
                     break;
                 }
             }
             break;
         case "get":
             try {
                 $response = $operation->getResponses()->getHttpStatusCode(200);
             } catch (MissingDocumentPropertyException $e) {
                 // no response with status code 200 is defined
                 break;
             }
             $schema = $this->resolveSchema($response->getSchema()->getDocument());
             break;
     }
     return $schema;
 }