From 317dfbfd8115bbfb74a9b43fad681a1e3cf70f9d Mon Sep 17 00:00:00 2001 From: wolfgang kuehn Date: Fri, 17 Jun 2016 19:18:37 +0200 Subject: [PATCH] Issue #6 --- lib/JSON.m | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/JSON.m b/lib/JSON.m index 014775d..4b49194 100644 --- a/lib/JSON.m +++ b/lib/JSON.m @@ -80,6 +80,7 @@ localSchemaCache(uri) = schema; end elseif this.isaMap(schema) + % TODO: Do we not need to call this.resolveSchema()? return; elseif isempty(schema) schema = []; @@ -89,7 +90,7 @@ end this.resolveSchema(localSchemaCache); - schema = JSON.getSchemaFromCache(uri, localSchemaCache); + schema = JSON.getSchemaFromCache(uri, []); end @@ -133,12 +134,12 @@ function resolveSchema(this, localSchemaCache) schema = localSchemaCache(uri); if schema.isKey('allOf') %TODO: At any level - this.mergeSchemas(schema); + schema = this.mergeSchemas(schema); end - if ~isempty(uri) + %if ~isempty(uri) JSON.cacheSchema(uri, schema); - end + %end end end @@ -207,7 +208,7 @@ function addError(this, pointer, msg, value, type) % Merge properties and required fields of all schemas. mergedSchema = containers.Map(); - mergedSchema('type') = 'object'; % TODO: Why not {'object'}? + mergedSchema('type') = {'object'}; mergedProperties = containers.Map(); mergedSchema('properties') = mergedProperties; mergedSchema('required') = {}; @@ -720,7 +721,7 @@ function log(level, fmt, varargin) value = []; end elseif nargin >= 3 - config(key) = value; + config(key) = value; %#ok end end @@ -732,8 +733,12 @@ function log(level, fmt, varargin) end end + function clearSchemaCache() + JSON.configParam('cache', []); + end + function schema = getSchemaFromCache(uri, localSchemaCache) - if localSchemaCache.isKey(uri) + if ~isempty(localSchemaCache) && localSchemaCache.isKey(uri) schema = localSchemaCache(uri); return; end @@ -769,11 +774,13 @@ function cacheSchema(uri, schema) % end function [value, errors] = parse(varargin) + JSON.clearSchemaCache(); parser = JSON_Parser(); [value, errors] = parse(parser, varargin{:}); end function [json, errors] = stringify(varargin) + JSON.clearSchemaCache(); stringifier = JSON_Stringifier(); [json, errors] = stringifier.stringify(varargin{:}); end