/** * @depends testNavigatingARaml */ public function testFindingInlineBodySchema() { /* Given... (Fixture) */ $jsonCoder = Stub::makeEmpty('GoIntegro\\Json\\JsonCoder'); $ramlDoc = Stub::makeEmpty('GoIntegro\\Raml\\RamlDoc', ['rawRaml' => Yaml::parse(__DIR__ . self::INLINE_BODY_SCHEMA_RAML), 'schemas' => Stub::makeEmpty('GoIntegro\\Raml\\Root\\MapCollection')]); $navigator = new DocNavigator($ramlDoc, $jsonCoder); /* When... (Action) */ $schema = $navigator->findRequestSchema(RamlSpec::HTTP_POST, '/some-resources'); /* Then... (Assertions) */ $this->assertEquals(self::INLINE_BODY_SCHEMA, $schema); }
/** * @param Params $params * @param string $method * @return \stdClass * @throws Raml\MissingSchemaException * @throws Raml\MalformedSchemaException */ protected function findResourceObjectSchema(Params $params, $method) { $jsonSchema = $this->docNavigator->findRequestSchema($method, '/' . $params->primaryType); if (empty($jsonSchema)) { $message = sprintf(self::ERROR_MISSING_SCHEMA, $params->primaryType); throw new Raml\MissingSchemaException($message); } elseif (empty($jsonSchema->properties->{$params->primaryType})) { $message = sprintf(self::ERROR_MALFORMED_SCHEMA, $params->primaryType); throw new Raml\MalformedSchemaException($message); } // @todo Move. (To method? To DocNav?) return $jsonSchema->properties->{$params->primaryType}; }
/** * @param Request $request * @return array */ private function parsePath(Request $request) { $parts = $this->parsePathParts($request); $path = '/' . implode('/', $parts); $ramlDoc = $this->docNavigator->getDoc(); $method = strtolower($request->getMethod()); if (!$ramlDoc->isDefined($method, $path)) { $allowedMethods = $ramlDoc->getAllowedMethods($path, CASE_UPPER); $message = sprintf(self::ERROR_ACTION_NOT_ALLOWED, implode(', ', $allowedMethods)); throw new ActionNotAllowedException($allowedMethods, $message); } return $path; }
/** * @return array * @throws ResourceEntityMappingException * @todo The configuration doesn't actually allow overridding resource type to entity class mappings as the error message suggests. Oops. */ public function map() { if ($this->mapCache->isFresh()) { return $this->mapCache->read(); } $map = []; foreach ($this->docNavigator->getDoc()->getResources() as $type) { $resourceClasses = $this->getResourceClasses($type); if (1 < count($resourceClasses)) { $message = sprintf(self::ERROR_ENTITIES_PER_RESOURCE, $type, implode(', ', $resourceClasses)); throw new ResourceEntityMappingException($message); } $map[$type] = reset($resourceClasses); } $this->mapCache->keep($map); return $map; }