/** * Parses and resolves the json schema source and returns the object * presentation of the schema * * @param string $source */ public function parse($source) { $resolver = new RefResolver(); if ($this->connection !== null) { $resolver->addResolver('schema', new Resolver($this->connection)); } $parser = new JsonSchema(null, $resolver); $schema = $parser->parse($source); if (!$schema->getDefinition() instanceof Property\ComplexType) { throw new RuntimeException('Schema must be an object'); } return serialize($schema); }
/** * @expectedException \RuntimeException */ public function testParseInvalidHttpRef() { $handler = Http\Handler\Mock::getByXmlDefinition(__DIR__ . '/http_mock.xml'); $http = new Http($handler); $resolver = JsonSchema\RefResolver::createDefault($http); $parser = new JsonSchema(__DIR__, $resolver); $parser->parse(file_get_contents(__DIR__ . '/invalid_http_ref_schema.json')); }
protected function parseSchema($schema) { if (is_string($schema)) { if (substr($schema, 0, 8) == '!include') { $file = trim(substr($schema, 8)); if (!is_file($file)) { $file = $this->basePath . '/' . $file; } return JsonSchema::fromFile($file); } else { $parser = new JsonSchema($this->basePath); return $parser->parse($schema); } } else { throw new RuntimeException('Schema definition must be a string'); } }