Skip to content
This repository has been archived by the owner on Mar 23, 2021. It is now read-only.

Commit

Permalink
Issue #6
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfgang kuehn authored Jun 17, 2016
1 parent 069691c commit 317dfbf
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions lib/JSON.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -89,7 +90,7 @@
end

this.resolveSchema(localSchemaCache);
schema = JSON.getSchemaFromCache(uri, localSchemaCache);
schema = JSON.getSchemaFromCache(uri, []);

end

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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') = {};
Expand Down Expand Up @@ -720,7 +721,7 @@ function log(level, fmt, varargin)
value = [];
end
elseif nargin >= 3
config(key) = value;
config(key) = value; %#ok<NASGU>
end
end

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 317dfbf

Please sign in to comment.