Skip to content

Commit

Permalink
Merge pull request #1 from DaveTD/0.4.0
Browse files Browse the repository at this point in the history
0.4.0
  • Loading branch information
DaveTD committed Jan 17, 2016
2 parents 2efbbde + 091603c commit 7ef1997
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion lib/superstudio.rb
Expand Up @@ -78,7 +78,7 @@ def insert_json_to_response(template, row_hash)
# Almost everything else can be ignored

def interpret_json_schema(json_hash, depth = 0, path_array = [], expected_mappings = [], node_name = 'root')
# in version 0.4.0, add support for "oneOf" and other non-type checks
json_hash = replace_reference_keys(json_hash)
level_keys = json_hash.keys
level_keys.each do |key|
if key == "type"
Expand All @@ -100,6 +100,19 @@ def interpret_json_schema(json_hash, depth = 0, path_array = [], expected_mappin
return expected_mappings.flatten
end

def replace_reference_keys(json_hash)
if json_hash.keys.include?("$ref")
# split on a hash character - the first piece is the file name, the second will, as of yet, be ignored
file_name = json_hash["$ref"].split('#')[0]
referenced_contents = parse_json_schema(file_name)
json_hash.delete("$ref")
json_hash = json_hash.merge(referenced_contents)
# let's do it again to see if there are more references
replace_reference_keys(json_hash)
end
return json_hash
end

# Generate a string JSON template like:
# {
# "firstName": %{root_firstName},
Expand Down
2 changes: 1 addition & 1 deletion superstudio.gemspec
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'superstudio'
s.version = '0.3.1'
s.version = '0.4.1'
s.date = '2016-01-04'
s.summary = "An alternative way of thinking about creating JSON output: life without creating ruby objects."
s.description = ""
Expand Down

0 comments on commit 7ef1997

Please sign in to comment.