/** * Return schema GET results. * * @param Request $request Current http request * @param string $id ID of record * * @throws SerializationException * @return \Symfony\Component\HttpFoundation\Response $response Result of the action */ public function schemaAction(Request $request, $id = null) { $request->attributes->set('schemaRequest', true); list($app, $module, , $modelName, $schemaType) = explode('.', $request->attributes->get('_route')); $response = $this->response; $response->setStatusCode(Response::HTTP_OK); $response->setPublic(); if (!$id && $schemaType != 'canonicalIdSchema') { $schema = $this->schemaUtils->getCollectionSchema($modelName, $this->getModel()); } else { $schema = $this->schemaUtils->getModelSchema($modelName, $this->getModel()); } // enabled methods for CorsListener $corsMethods = 'GET, POST, PUT, PATCH, DELETE, OPTIONS'; try { $router = $this->getRouter(); // if post route is available we assume everything is readable $router->generate(implode('.', array($app, $module, 'rest', $modelName, 'post'))); } catch (RouteNotFoundException $exception) { // only allow read methods $corsMethods = 'GET, OPTIONS'; } $request->attributes->set('corsMethods', $corsMethods); return $this->render('GravitonRestBundle:Main:index.json.twig', ['response' => $this->serialize($schema)], $response); }