Exemplo n.º 1
0
 /**
  * @param string $method
  * @param string $resourceType
  * @param string $mediaType
  * @return \stdClass|NULL
  */
 public function findRequestSchema($method, $resourceUri, $mediaType = RamlSpec::MEDIA_TYPE_JSON)
 {
     if (!RamlDoc::isValidMethod($method)) {
         $message = sprintf(self::ERROR_INVALID_METHOD, $method);
         throw new \UnexpectedValueException($message);
     }
     if (!RamlDoc::isValidMediaType($mediaType)) {
         $message = sprintf(self::ERROR_INVALID_MEDIA_TYPE, $mediaType);
         throw new \UnexpectedValueException($mediaType);
     }
     try {
         $schema = $this->navigate($resourceUri, $method, RamlSpec::REQUEST_BODY, $mediaType, RamlSpec::BODY_SCHEMA);
     } catch (PathNotFoundException $e) {
         // In this case, this is OK. Return values are based on navigation,
         // any value may be found and thus is valid, hence return values
         // can't be used to express "not found".
     }
     if (isset($schema)) {
         if (RamlDoc::isInclude($schema)) {
             $schema = $this->dereferenceInclude($schema, $this->ramlDoc->fileDir);
         } elseif ($this->ramlDoc->schemas->has($schema)) {
             $schema = $this->ramlDoc->schemas->get($schema);
         }
         /* elseif (!$this->jsonCoder->assertJsonSchema($schema)) {
                throw new MalformedSchemaException(self::ERROR_INVALID_SCHEMA);
            }*/
         return $schema;
     } else {
         list($resourceType) = explode('/', substr($resourceUri, 1));
         return $this->ramlDoc->schemas->get($resourceType);
     }
 }
Exemplo n.º 2
0
 /**
  * @param array &$map
  * @param string $fileDir
  * @return array
  */
 protected function dereferenceIncludes(array &$map, $fileDir = __DIR__)
 {
     foreach ($map as &$value) {
         if (is_string($value)) {
             if (RamlDoc::isInclude($value)) {
                 $value = $this->dereferenceInclude($value, $fileDir);
             } else {
                 throw new \ErrorException(self::ERROR_UNEXPECTED_VALUE);
             }
         }
     }
     return $map;
 }