/** * @param Visitor $visitor rql query visitor * @param array $notModifiableOriginRecords strings with not modifiable recordOrigin values * @param integer $paginationDefaultLimit amount of data records to be returned when in pagination context. */ public function __construct(Visitor $visitor, $notModifiableOriginRecords, $paginationDefaultLimit) { parent::__construct(); $this->visitor = $visitor; $this->notModifiableOriginRecords = $notModifiableOriginRecords; $this->paginationDefaultLimit = (int) $paginationDefaultLimit; }
/** * Returns the swagger spec as array * * @return array Swagger spec */ public function getSwaggerSpec() { $ret = $this->getBasicStructure(); $routingMap = $this->restUtils->getServiceRoutingMap(); $paths = array(); foreach ($routingMap as $contName => $routes) { list(, $bundle, , $document) = explode('.', $contName); foreach ($routes as $routeName => $route) { $routeMethod = strtolower($route->getMethods()[0]); // skip /schema/ stuff if (strpos($route->getPath(), '/schema/') !== false) { continue; } $thisModel = $this->restUtils->getModelFromRoute($route); if ($thisModel === false) { throw new \LogicException(sprintf('Could not resolve route "%s" to model', $routeName)); } $entityClassName = str_replace('\\', '', get_class($thisModel)); $schema = $this->schemaUtils->getModelSchema($entityClassName, $thisModel); $ret['definitions'][$entityClassName] = json_decode($this->restUtils->serializeContent($schema), true); $isCollectionRequest = true; if (in_array('id', array_keys($route->getRequirements())) === true) { $isCollectionRequest = false; } $thisPattern = $route->getPattern(); $entityName = ucfirst($document); $thisPath = $this->getBasicPathStructure($isCollectionRequest, $entityName, $entityClassName, $schema->getProperty('id')->getType()); $thisPath['tags'] = $this->getPathTags($route); $thisPath['operationId'] = $routeName; $thisPath['summary'] = $this->getSummary($routeMethod, $isCollectionRequest, $entityName); // post body stuff if ($routeMethod == 'put' || $routeMethod == 'post') { // special handling for POST/PUT.. we need to have 2 schemas, one for response, one for request.. // we don't want to have ID in the request body within those requests do we.. // an exception is when id is required.. $incomingEntitySchema = $entityClassName; if (is_null($schema->getRequired()) || !in_array('id', $schema->getRequired())) { $incomingEntitySchema = $incomingEntitySchema . 'Incoming'; $incomingSchema = clone $schema; $incomingSchema->removeProperty('id'); $ret['definitions'][$incomingEntitySchema] = json_decode($this->restUtils->serializeContent($incomingSchema), true); } $thisPath['parameters'][] = array('name' => $bundle, 'in' => 'body', 'description' => 'Post', 'required' => true, 'schema' => array('$ref' => '#/definitions/' . $incomingEntitySchema)); // add error responses.. $thisPath['responses'][400] = array('description' => 'Bad request', 'schema' => array('type' => 'object')); } if ($routeMethod == 'options') { $thisPath['responses'][200] = array('description' => 'Schema response', 'schema' => array('$ref' => '#/definitions/SchemaModel')); } $paths[$thisPattern][$routeMethod] = $thisPath; } } $ret['definitions']['SchemaModel'] = $this->schemaModel->getSchema(); ksort($paths); $ret['paths'] = $paths; return $ret; }
/** * @param Factory $rqlFactory factory object to use */ public function __construct(Factory $rqlFactory) { parent::__construct(); $this->rqlFactory = $rqlFactory; }