Skip to content

Commit

Permalink
Merge remote-tracking branches 'origin/jsi_json_pointer' and 'origin/…
Browse files Browse the repository at this point in the history
…misc' into HEAD
  • Loading branch information
notEthan committed Jun 2, 2019
2 parents 7bd7f87 + 85854ff commit e72b6de
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v0.0.4

- minor bugfixes / improvements

# v0.0.3

- JSI::Base returns an instance of the default value for the schema if applicable
Expand Down
10 changes: 8 additions & 2 deletions lib/jsi/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class Base
include Enumerable

class << self
attr_accessor :in_schema_classes

# @return [String] absolute schema_id of the schema this class represents.
# see {Schema#schema_id}.
def schema_id
Expand All @@ -23,10 +25,13 @@ def schema_id

# @return [String] a string representing the class, with schema_id
def inspect
name # see #name for side effects
if !respond_to?(:schema)
super
elsif !name || name =~ /\AJSI::SchemaClasses::/
elsif in_schema_classes
%Q(#{SchemaClasses.inspect}[#{schema_id.inspect}])
elsif !name
%Q(#<Class for Schema: #{schema_id}>)
else
%Q(#{name} (#{schema_id}))
end
Expand Down Expand Up @@ -55,8 +60,9 @@ def schema_classes_const_name

# @return [String] a constant name of this class
def name
unless super
unless super || SchemaClasses.const_defined?(schema_classes_const_name)
SchemaClasses.const_set(schema_classes_const_name, self)
self.in_schema_classes = true
end
super
end
Expand Down
7 changes: 2 additions & 5 deletions lib/jsi/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,9 @@ def schema_class
def match_to_instance(instance)
# matching oneOf is good here. one schema for one instance.
# matching anyOf is okay. there could be more than one schema matched. it's often just one. if more
# than one is a match, the problems of allOf occur.
# matching allOf is questionable. all of the schemas must be matched but we just return the first match.
# there isn't really a better answer with the current implementation. merging the schemas together
# is a thought but is not practical.
# than one is a match, you just get the first one.
instance = instance.deref if instance.is_a?(JSI::JSON::Node)
%w(oneOf allOf anyOf).select { |k| schema_node[k].respond_to?(:to_ary) }.each do |someof_key|
%w(oneOf anyOf).select { |k| schema_node[k].respond_to?(:to_ary) }.each do |someof_key|
schema_node[someof_key].map(&:deref).map do |someof_node|
someof_schema = self.class.new(someof_node)
if someof_schema.validate(instance)
Expand Down
2 changes: 1 addition & 1 deletion lib/jsi/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module JSI
VERSION = "0.0.3".freeze
VERSION = "0.0.4".freeze
end

0 comments on commit e72b6de

Please sign in to comment.