/** * 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')); }
public function __construct($basePath = null, RefResolver $resolver = null) { $this->basePath = $basePath; $this->resolver = $resolver ?: RefResolver::createDefault(); }