Skip to content
Merged
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
2 changes: 1 addition & 1 deletion app/validators/json_schema_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def json_schemer(schema)
when *NAMED_SCHEMA_VERSIONS
JSONSchemer.send(schema)
when String, Hash
JSONSchemer.schema(schema)
JSONSchemer.schema(schema, ref_resolver: proc { |_uri| {} })
when JSONSchemer::Schema
schema
else
Expand Down
25 changes: 24 additions & 1 deletion test/validators/json_schema_validator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,27 @@ class JsonSchemaTestModel
}
}.freeze

EXTERNAL_REF_SCHEMA = {
'$schema' => 'https://json-schema.org/draft/2019-09/schema',
'type' => 'object',
'properties' => {
'name' => {
'$ref': 'external://structured_store/json_date_range/',
'type' => 'string',
'example' => 'John Doe'
}
}
}.freeze

attr_accessor :draft201909_symbol_schema,
:hash_schema,
:instance_schema,
:lambda_schema,
:lambda_schema_dynamic,
:openapi31_symbol_schema,
:string_schema,
:unexpected_class_schema
:unexpected_class_schema,
:external_ref_schema

validates :draft201909_symbol_schema, json_schema: { allow_blank: true, schema: :draft201909 }
validates :hash_schema, json_schema: { allow_blank: true, schema: DRAFT201909_NAME_SCHEMA }
Expand Down Expand Up @@ -90,6 +103,7 @@ class JsonSchemaTestModel
validates :openapi31_symbol_schema, json_schema: { allow_blank: true, schema: :openapi31 }
validates :string_schema, json_schema: { allow_blank: true, schema: DRAFT201909_NAME_SCHEMA.to_json }
validates :unexpected_class_schema, json_schema: { allow_blank: true, schema: self }
validates :external_ref_schema, json_schema: { allow_blank: true, schema: EXTERNAL_REF_SCHEMA }
end

test 'validate test schemas' do
Expand Down Expand Up @@ -255,4 +269,13 @@ class JsonSchemaTestModel
object.valid?
end
end

test 'allows external refs' do
object = JsonSchemaTestModel.new
object.external_ref_schema = {
'name' => 'John Doe'
}

assert_nothing_raised { object.valid? }
end
end