Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand references of DocuemntStore schemas #93

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/json_matchers/matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def build_and_populate_document_store
map { |schema_path| Parser.new(schema_path).parse }.
each { |schema| document_store.add_schema(schema) }

document_store.to_a.each do |_k, schema|
schema.expand_references!(store: document_store)
end

document_store
end
end
Expand Down
1 change: 1 addition & 0 deletions spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@

initialize_with do
FakeSchema.new(name, {
"id": "file:/#{name}.json#",
"$schema": "https://json-schema.org/draft-04/schema#",
"type": "array",
"items": { "$ref": "file:/#{items.name}.json#" },
Expand Down
18 changes: 18 additions & 0 deletions spec/json_matchers/match_json_schema_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,24 @@
expect(json_as_array).not_to match_json_schema(schema)
end

it "validates against a schema that uses nested $refs" do
schema = create(:schema, :referencing_locations,
items: create(:schema, :referencing_locations))
json = build(:response, :location)
json_as_array = [[json.to_h]]

expect(json_as_array).to match_json_schema(schema)
end

it "fails against a schema that uses nested $refs" do
schema = create(:schema, :referencing_locations,
items: create(:schema, :referencing_locations))
json = build(:response, :invalid_location)
json_as_array = [[json.to_h]]

expect(json_as_array).not_to match_json_schema(schema)
end

it "validates against a schema referencing with 'definitions'" do
schema = create(:schema, :referencing_definitions)

Expand Down