-
Notifications
You must be signed in to change notification settings - Fork 65
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
Changes dynamic and lexical schemas to be stored internally by the URI as a string #189
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
module JSONSchemer | ||
class Resources | ||
|
||
def initialize | ||
@resources ||= { :lexical => {}, :dynamic => {} } | ||
end | ||
|
||
def register(type, namespace_uri, schema) | ||
@resources[type][namespace_uri.to_s] = schema | ||
end | ||
|
||
def lexical!(namespace_uri) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's just call these |
||
@resources[:lexical].fetch(namespace_uri.to_s) | ||
end | ||
|
||
def lexical(namespace_uri) | ||
@resources[:lexical][namespace_uri.to_s] | ||
end | ||
|
||
def dynamic!(namespace_uri) | ||
@resources[:dynamic].fetch(namespace_uri.to_s) | ||
end | ||
|
||
def dynamic?(namespace_uri) | ||
@resources[:dynamic].key?(namespace_uri.to_s) | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -174,13 +174,12 @@ def resolve_ref(uri) | |
uri.fragment = nil | ||
end | ||
|
||
lexical_resources = resources.fetch(:lexical) | ||
schema = lexical_resources[uri] | ||
schema = resources.lexical(uri) | ||
|
||
if !schema && uri.fragment.nil? | ||
empty_fragment_uri = uri.dup | ||
empty_fragment_uri.fragment = '' | ||
schema = lexical_resources[empty_fragment_uri] | ||
schema = resources.lexical(empty_fragment_uri) | ||
end | ||
|
||
unless schema | ||
|
@@ -196,7 +195,7 @@ def resolve_ref(uri) | |
) | ||
remote_uri = remote_schema.base_uri.dup | ||
remote_uri.fragment = location_independent_identifier if location_independent_identifier | ||
schema = remote_schema.resources.fetch(:lexical).fetch(remote_uri) | ||
schema = remote_schema.resources.lexical!(remote_uri) | ||
end | ||
|
||
schema = Hana::Pointer.parse(pointer).reduce(schema) do |obj, token| | ||
|
@@ -328,7 +327,7 @@ def defs_keyword | |
end | ||
|
||
def resources | ||
@resources ||= { :lexical => {}, :dynamic => {} } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think instead of wrapping both of these in a single object, we should pull them into separate objects. Something like: def resources
@resources ||= { :lexical => Resources.new, :dynamic => Resources.new }
end Or even separate And then on |
||
@resources ||= Resources.new | ||
end | ||
|
||
def error(formatted_instance_location:, **options) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check whether the URI is already used for possibly another schema. It makes a couple of tests fail though.