Skip to content

Commit 05ebb2b

Browse files
committed
Set validate flag if either json-ld-1.0 or json-ld-1.1, and don't override that passed in through options.
1 parent d9d652d commit 05ebb2b

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

lib/json/ld/api.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class API
7373
# @option options [String] :processingMode ("json-ld-1.1")
7474
# Processing mode, json-ld-1.0 or json-ld-1.1. Also can have other values:
7575
#
76-
# * expand-frame – special frame expansion mode.
76+
# * json-ld-1.1-expand-frame – special frame expansion mode.
7777
# @option options [Boolean] :rename_bnodes (true)
7878
# Rename bnodes as part of expansion, or keep them the same.
7979
# @option options [Boolean] :unique_bnodes (false)
@@ -89,10 +89,11 @@ def initialize(input, context, options = {}, &block)
8989
@options = {
9090
compactArrays: true,
9191
rename_bnodes: true,
92-
processingMode: "json-ld-1.1"
93-
}.merge(options)
94-
@options[:validate] = @options[:processingMode] == "json-ld-1.0"
95-
@options[:documentLoader] ||= self.class.method(:documentLoader)
92+
processingMode: "json-ld-1.1",
93+
documentLoader: self.class.method(:documentLoader)
94+
}
95+
@options[:validate] = %w(json-ld-1.0 json-ld-1.1).include?(@options[:processingMode])
96+
@options = @options.merge(options)
9697
@namer = options[:unique_bnodes] ? BlankNodeUniqer.new : (@options[:rename_bnodes] ? BlankNodeNamer.new("b") : BlankNodeMapper.new)
9798

9899
# For context via Link header

lib/json/ld/format.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ def self.cli_commands
6262
# If files are empty, either use options[:execute]
6363
input = options[:evaluate] ? StringIO.new(options[:evaluate]) : STDIN
6464
input.set_encoding(options.fetch(:encoding, Encoding::UTF_8))
65-
JSON::LD::API.expand(input, options) do |expanded|
65+
JSON::LD::API.expand(input, options.merge(validate: false)) do |expanded|
6666
out.puts expanded.to_json(JSON::LD::JSON_STATE)
6767
end
6868
else
6969
files.each do |file|
70-
JSON::LD::API.expand(file, options) do |expanded|
70+
JSON::LD::API.expand(file, options.merge(validate: false)) do |expanded|
7171
out.puts expanded.to_json(JSON::LD::JSON_STATE)
7272
end
7373
end

spec/format_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,25 +78,25 @@
7878
expect {RDF::CLI.exec(["expand", ttl], format: :ttl)}.to write.to(:output)
7979
end
8080
it "expands JSON" do
81-
expect {RDF::CLI.exec(["expand", json], format: :jsonld)}.to write.to(:output)
81+
expect {RDF::CLI.exec(["expand", json], format: :jsonld, validate: false)}.to write.to(:output)
8282
end
8383
end
8484

8585
describe "#compact" do
8686
it "compacts RDF" do
87-
expect {RDF::CLI.exec(["compact", ttl], context: context, format: :ttl)}.to write.to(:output)
87+
expect {RDF::CLI.exec(["compact", ttl], context: context, format: :ttl, validate: false)}.to write.to(:output)
8888
end
8989
it "compacts JSON" do
90-
expect {RDF::CLI.exec(["compact", json], context: context, format: :jsonld)}.to write.to(:output)
90+
expect {RDF::CLI.exec(["compact", json], context: context, format: :jsonld, validate: false)}.to write.to(:output)
9191
end
9292
end
9393

9494
describe "#flatten" do
9595
it "flattens RDF" do
96-
expect {RDF::CLI.exec(["flatten", ttl], context: context, format: :ttl)}.to write.to(:output)
96+
expect {RDF::CLI.exec(["flatten", ttl], context: context, format: :ttl, validate: false)}.to write.to(:output)
9797
end
9898
it "flattens JSON" do
99-
expect {RDF::CLI.exec(["flatten", json], context: context, format: :jsonld)}.to write.to(:output)
99+
expect {RDF::CLI.exec(["flatten", json], context: context, format: :jsonld, validate: false)}.to write.to(:output)
100100
end
101101
end
102102

@@ -105,7 +105,7 @@
105105
expect {RDF::CLI.exec(["frame", ttl], frame: context, format: :ttl)}.to write.to(:output)
106106
end
107107
it "frames JSON" do
108-
expect {RDF::CLI.exec(["frame", json], frame: context, format: :jsonld)}.to write.to(:output)
108+
expect {RDF::CLI.exec(["frame", json], frame: context, format: :jsonld, validate: false)}.to write.to(:output)
109109
end
110110
end
111111
end

0 commit comments

Comments
 (0)