Skip to content

Commit

Permalink
use Schema#keyword?
Browse files Browse the repository at this point in the history
  • Loading branch information
notEthan committed Jun 13, 2022
1 parent 438b273 commit d426090
Show file tree
Hide file tree
Showing 27 changed files with 57 additions and 57 deletions.
2 changes: 1 addition & 1 deletion lib/jsi/base.rb
Expand Up @@ -370,7 +370,7 @@ def [](token, as_jsi: :auto, use_default: true)
if use_default
defaults = Set.new
subinstance_schemas.each do |subinstance_schema|
if subinstance_schema.respond_to?(:to_hash) && subinstance_schema.key?('default')
if subinstance_schema.keyword?('default')
defaults << subinstance_schema['default']
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/jsi/schema.rb
Expand Up @@ -34,7 +34,7 @@ module BigMoneyId
# the contents of a $id keyword whose value is a string, or nil
# @return [#to_str, nil]
def id
if schema_content.respond_to?(:to_hash) && schema_content['$id'].respond_to?(:to_str)
if keyword?('$id') && schema_content['$id'].respond_to?(:to_str)
schema_content['$id']
else
nil
Expand All @@ -47,7 +47,7 @@ module OldId
# the contents of an `id` keyword whose value is a string, or nil
# @return [#to_str, nil]
def id
if schema_content.respond_to?(:to_hash) && schema_content['id'].respond_to?(:to_str)
if keyword?('id') && schema_content['id'].respond_to?(:to_str)
schema_content['id']
else
nil
Expand Down
2 changes: 1 addition & 1 deletion lib/jsi/schema/application/child_application/contains.rb
Expand Up @@ -4,7 +4,7 @@ module JSI
module Schema::Application::ChildApplication::Contains
# @private
def internal_applicate_contains(idx, instance, &block)
if schema_content.key?('contains')
if keyword?('contains')
contains_schema = subschema(['contains'])

if contains_schema.instance_valid?(instance[idx])
Expand Down
4 changes: 2 additions & 2 deletions lib/jsi/schema/application/child_application/items.rb
Expand Up @@ -7,10 +7,10 @@ def internal_applicate_items(idx, &block)
if schema_content['items'].respond_to?(:to_ary)
if schema_content['items'].each_index.to_a.include?(idx)
yield subschema(['items', idx])
elsif schema_content.key?('additionalItems')
elsif keyword?('additionalItems')
yield subschema(['additionalItems'])
end
elsif schema_content.key?('items')
elsif keyword?('items')
yield subschema(['items'])
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/jsi/schema/application/child_application/properties.rb
Expand Up @@ -5,7 +5,7 @@ module Schema::Application::ChildApplication::Properties
# @private
def internal_applicate_properties(property_name, &block)
apply_additional = true
if schema_content.key?('properties') && schema_content['properties'].respond_to?(:to_hash) && schema_content['properties'].key?(property_name)
if keyword?('properties') && schema_content['properties'].respond_to?(:to_hash) && schema_content['properties'].key?(property_name)
apply_additional = false
yield subschema(['properties', property_name])
end
Expand All @@ -17,7 +17,7 @@ def internal_applicate_properties(property_name, &block)
end
end
end
if apply_additional && schema_content.key?('additionalProperties')
if apply_additional && keyword?('additionalProperties')
yield subschema(['additionalProperties'])
end
end
Expand Down
Expand Up @@ -4,7 +4,7 @@ module JSI
module Schema::Application::InplaceApplication::Dependencies
# @private
def internal_applicate_dependencies(instance, visited_refs, &block)
if schema_content.key?('dependencies')
if keyword?('dependencies')
value = schema_content['dependencies']
# This keyword's value MUST be an object. Each property specifies a dependency. Each dependency
# value MUST be an array or a valid JSON Schema.
Expand Down
6 changes: 3 additions & 3 deletions lib/jsi/schema/application/inplace_application/ifthenelse.rb
Expand Up @@ -4,13 +4,13 @@ module JSI
module Schema::Application::InplaceApplication::IfThenElse
# @private
def internal_applicate_ifthenelse(instance, visited_refs, &block)
if schema_content.key?('if')
if keyword?('if')
if subschema(['if']).instance_valid?(instance)
if schema_content.key?('then')
if keyword?('then')
subschema(['then']).each_inplace_applicator_schema(instance, visited_refs: visited_refs, &block)
end
else
if schema_content.key?('else')
if keyword?('else')
subschema(['else']).each_inplace_applicator_schema(instance, visited_refs: visited_refs, &block)
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/jsi/schema/validation/array.rb
Expand Up @@ -4,7 +4,7 @@ module JSI
module Schema::Validation::ArrayLength
# @private
def internal_validate_maxItems(result_builder)
if schema_content.key?('maxItems')
if keyword?('maxItems')
value = schema_content['maxItems']
# The value of this keyword MUST be a non-negative integer.
if internal_integer?(value) && value >= 0
Expand All @@ -24,7 +24,7 @@ def internal_validate_maxItems(result_builder)

# @private
def internal_validate_minItems(result_builder)
if schema_content.key?('minItems')
if keyword?('minItems')
value = schema_content['minItems']
# The value of this keyword MUST be a non-negative integer.
if internal_integer?(value) && value >= 0
Expand All @@ -45,7 +45,7 @@ def internal_validate_minItems(result_builder)
module Schema::Validation::UniqueItems
# @private
def internal_validate_uniqueItems(result_builder)
if schema_content.key?('uniqueItems')
if keyword?('uniqueItems')
value = schema_content['uniqueItems']
# The value of this keyword MUST be a boolean.
if value == false
Expand Down
2 changes: 1 addition & 1 deletion lib/jsi/schema/validation/const.rb
Expand Up @@ -4,7 +4,7 @@ module JSI
module Schema::Validation::Const
# @private
def internal_validate_const(result_builder)
if schema_content.key?('const')
if keyword?('const')
value = schema_content['const']
# The value of this keyword MAY be of any type, including null.
# An instance validates successfully against this keyword if its value is equal to the value of
Expand Down
2 changes: 1 addition & 1 deletion lib/jsi/schema/validation/contains.rb
Expand Up @@ -4,7 +4,7 @@ module JSI
module Schema::Validation::Contains
# @private
def internal_validate_contains(result_builder)
if schema_content.key?('contains')
if keyword?('contains')
# An array instance is valid against "contains" if at least one of its elements is valid against
# the given schema.
if result_builder.instance.respond_to?(:to_ary)
Expand Down
2 changes: 1 addition & 1 deletion lib/jsi/schema/validation/dependencies.rb
Expand Up @@ -4,7 +4,7 @@ module JSI
module Schema::Validation::Dependencies
# @private
def internal_validate_dependencies(result_builder)
if schema_content.key?('dependencies')
if keyword?('dependencies')
value = schema_content['dependencies']
# This keyword's value MUST be an object. Each property specifies a dependency. Each dependency
# value MUST be an array or a valid JSON Schema.
Expand Down
12 changes: 6 additions & 6 deletions lib/jsi/schema/validation/draft04/minmax.rb
Expand Up @@ -4,18 +4,18 @@ module JSI
module Schema::Validation::Draft04::MinMax
# @private
def internal_validate_maximum(result_builder)
if schema_content.key?('exclusiveMaximum')
if keyword?('exclusiveMaximum')
value = schema_content['exclusiveMaximum']
# The value of "exclusiveMaximum" MUST be a boolean.
unless [true, false].include?(value)
result_builder.schema_error('`exclusiveMaximum` is not true or false', 'exclusiveMaximum')
end
if !schema_content.key?('maximum')
if !keyword?('maximum')
result_builder.schema_error('`exclusiveMaximum` has no effect without adjacent `maximum` keyword', 'exclusiveMaximum')
end
end

if schema_content.key?('maximum')
if keyword?('maximum')
value = schema_content['maximum']
# The value of "maximum" MUST be a JSON number.
if value.is_a?(Numeric)
Expand Down Expand Up @@ -47,18 +47,18 @@ def internal_validate_maximum(result_builder)

# @private
def internal_validate_minimum(result_builder)
if schema_content.key?('exclusiveMinimum')
if keyword?('exclusiveMinimum')
value = schema_content['exclusiveMinimum']
# The value of "exclusiveMinimum" MUST be a boolean.
unless [true, false].include?(value)
result_builder.schema_error('`exclusiveMinimum` is not true or false', 'exclusiveMinimum')
end
if !schema_content.key?('minimum')
if !keyword?('minimum')
result_builder.schema_error('`exclusiveMinimum` has no effect without adjacent `minimum` keyword', 'exclusiveMinimum')
end
end

if schema_content.key?('minimum')
if keyword?('minimum')
value = schema_content['minimum']
# The value of "minimum" MUST be a JSON number.
if value.is_a?(Numeric)
Expand Down
2 changes: 1 addition & 1 deletion lib/jsi/schema/validation/enum.rb
Expand Up @@ -4,7 +4,7 @@ module JSI
module Schema::Validation::Enum
# @private
def internal_validate_enum(result_builder)
if schema_content.key?('enum')
if keyword?('enum')
value = schema_content['enum']
# The value of this keyword MUST be an array. This array SHOULD have at least one element.
# Elements in the array SHOULD be unique.
Expand Down
10 changes: 5 additions & 5 deletions lib/jsi/schema/validation/ifthenelse.rb
Expand Up @@ -4,7 +4,7 @@ module JSI
module Schema::Validation::IfThenElse
# @private
def internal_validate_ifthenelse(result_builder)
if schema_content.key?('if')
if keyword?('if')
# This keyword's value MUST be a valid JSON Schema.
# This validation outcome of this keyword's subschema has no direct effect on the overall validation
# result. Rather, it controls which of the "then" or "else" keywords are evaluated.
Expand All @@ -13,7 +13,7 @@ def internal_validate_ifthenelse(result_builder)
result_builder.merge_schema_issues(if_result)

if if_result.valid?
if schema_content.key?('then')
if keyword?('then')
then_result = result_builder.inplace_subschema_validate(['then'])
result_builder.validate(
then_result.valid?,
Expand All @@ -23,7 +23,7 @@ def internal_validate_ifthenelse(result_builder)
)
end
else
if schema_content.key?('else')
if keyword?('else')
else_result = result_builder.inplace_subschema_validate(['else'])
result_builder.validate(
else_result.valid?,
Expand All @@ -34,10 +34,10 @@ def internal_validate_ifthenelse(result_builder)
end
end
else
if schema_content.key?('then')
if keyword?('then')
result_builder.schema_warning('`then` has no effect without adjacent `if` keyword', 'then')
end
if schema_content.key?('else')
if keyword?('else')
result_builder.schema_warning('`else` has no effect without adjacent `if` keyword', 'else')
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/jsi/schema/validation/items.rb
Expand Up @@ -4,7 +4,7 @@ module JSI
module Schema::Validation::Items
# @private
def internal_validate_items(result_builder)
if schema_content.key?('items')
if keyword?('items')
value = schema_content['items']
# The value of "items" MUST be either a valid JSON Schema or an array of valid JSON Schemas.
if value.respond_to?(:to_ary)
Expand All @@ -15,7 +15,7 @@ def internal_validate_items(result_builder)
result_builder.instance.each_index do |i|
if i < value.size
results[i] = result_builder.child_subschema_validate(['items', i], [i])
elsif schema_content.key?('additionalItems')
elsif keyword?('additionalItems')
results[i] = result_builder.child_subschema_validate(['additionalItems'], [i])
end
end
Expand All @@ -40,12 +40,12 @@ def internal_validate_items(result_builder)
results: results,
)
end
if schema_content.key?('additionalItems')
if keyword?('additionalItems')
result_builder.schema_warning('`additionalItems` has no effect when adjacent `items` keyword is not an array', 'items')
end
end
else
if schema_content.key?('additionalItems')
if keyword?('additionalItems')
result_builder.schema_warning('`additionalItems` has no effect without adjacent `items` keyword', 'items')
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/jsi/schema/validation/not.rb
Expand Up @@ -4,7 +4,7 @@ module JSI
module Schema::Validation::Not
# @private
def internal_validate_not(result_builder)
if schema_content.key?('not')
if keyword?('not')
# This keyword's value MUST be a valid JSON Schema.
# An instance is valid against this keyword if it fails to validate successfully against the schema
# defined by this keyword.
Expand Down
10 changes: 5 additions & 5 deletions lib/jsi/schema/validation/numeric.rb
Expand Up @@ -4,7 +4,7 @@ module JSI
module Schema::Validation::MultipleOf
# @private
def internal_validate_multipleOf(result_builder)
if schema_content.key?('multipleOf')
if keyword?('multipleOf')
value = schema_content['multipleOf']
# The value of "multipleOf" MUST be a number, strictly greater than 0.
if value.is_a?(Numeric) && value > 0
Expand Down Expand Up @@ -36,7 +36,7 @@ def internal_validate_multipleOf(result_builder)
module Schema::Validation::MinMax
# @private
def internal_validate_maximum(result_builder)
if schema_content.key?('maximum')
if keyword?('maximum')
value = schema_content['maximum']
# The value of "maximum" MUST be a number, representing an inclusive upper limit for a numeric instance.
if value.is_a?(Numeric)
Expand All @@ -57,7 +57,7 @@ def internal_validate_maximum(result_builder)

# @private
def internal_validate_exclusiveMaximum(result_builder)
if schema_content.key?('exclusiveMaximum')
if keyword?('exclusiveMaximum')
value = schema_content['exclusiveMaximum']
# The value of "exclusiveMaximum" MUST be number, representing an exclusive upper limit for a numeric instance.
if value.is_a?(Numeric)
Expand All @@ -78,7 +78,7 @@ def internal_validate_exclusiveMaximum(result_builder)

# @private
def internal_validate_minimum(result_builder)
if schema_content.key?('minimum')
if keyword?('minimum')
value = schema_content['minimum']
# The value of "minimum" MUST be a number, representing an inclusive lower limit for a numeric instance.
if value.is_a?(Numeric)
Expand All @@ -99,7 +99,7 @@ def internal_validate_minimum(result_builder)

# @private
def internal_validate_exclusiveMinimum(result_builder)
if schema_content.key?('exclusiveMinimum')
if keyword?('exclusiveMinimum')
value = schema_content['exclusiveMinimum']
# The value of "exclusiveMinimum" MUST be number, representing an exclusive lower limit for a numeric instance.
if value.is_a?(Numeric)
Expand Down
4 changes: 2 additions & 2 deletions lib/jsi/schema/validation/object.rb
Expand Up @@ -4,7 +4,7 @@ module JSI
module Schema::Validation::MinMaxProperties
# @private
def internal_validate_maxProperties(result_builder)
if schema_content.key?('maxProperties')
if keyword?('maxProperties')
value = schema_content['maxProperties']
# The value of this keyword MUST be a non-negative integer.
if internal_integer?(value) && value >= 0
Expand All @@ -24,7 +24,7 @@ def internal_validate_maxProperties(result_builder)

# @private
def internal_validate_minProperties(result_builder)
if schema_content.key?('minProperties')
if keyword?('minProperties')
value = schema_content['minProperties']
# The value of this keyword MUST be a non-negative integer.
if internal_integer?(value) && value >= 0
Expand Down
2 changes: 1 addition & 1 deletion lib/jsi/schema/validation/pattern.rb
Expand Up @@ -4,7 +4,7 @@ module JSI
module Schema::Validation::Pattern
# @private
def internal_validate_pattern(result_builder)
if schema_content.key?('pattern')
if keyword?('pattern')
value = schema_content['pattern']
# The value of this keyword MUST be a string.
if value.respond_to?(:to_str)
Expand Down
6 changes: 3 additions & 3 deletions lib/jsi/schema/validation/properties.rb
Expand Up @@ -6,7 +6,7 @@ module Schema::Validation::Properties
def internal_validate_properties(result_builder)
evaluated_property_names = Set[]

if schema_content.key?('properties')
if keyword?('properties')
value = schema_content['properties']
# The value of "properties" MUST be an object. Each value of this object MUST be a valid JSON Schema.
if value.respond_to?(:to_hash)
Expand Down Expand Up @@ -36,7 +36,7 @@ def internal_validate_properties(result_builder)
end
end

if schema_content.key?('patternProperties')
if keyword?('patternProperties')
value = schema_content['patternProperties']
# The value of "patternProperties" MUST be an object. Each property name of this object SHOULD be a
# valid regular expression, according to the ECMA 262 regular expression dialect. Each property value
Expand Down Expand Up @@ -75,7 +75,7 @@ def internal_validate_properties(result_builder)
end
end

if schema_content.key?('additionalProperties')
if keyword?('additionalProperties')
value = schema_content['additionalProperties']
# The value of "additionalProperties" MUST be a valid JSON Schema.
if result_builder.instance.respond_to?(:to_hash)
Expand Down
2 changes: 1 addition & 1 deletion lib/jsi/schema/validation/property_names.rb
Expand Up @@ -4,7 +4,7 @@ module JSI
module Schema::Validation::PropertyNames
# @private
def internal_validate_propertyNames(result_builder)
if schema_content.key?('propertyNames')
if keyword?('propertyNames')
# The value of "propertyNames" MUST be a valid JSON Schema.
#
# If the instance is an object, this keyword validates if every property name in the instance
Expand Down
2 changes: 1 addition & 1 deletion lib/jsi/schema/validation/ref.rb
Expand Up @@ -6,7 +6,7 @@ module Schema::Validation::Ref
# @param throw_result [Boolean] if a $ref is present, whether to throw the result being built after
# validating the $ref, bypassing subsequent keyword validation
def internal_validate_ref(result_builder, throw_result: false)
if schema_content.key?('$ref')
if keyword?('$ref')
value = schema_content['$ref']

if value.respond_to?(:to_str)
Expand Down

0 comments on commit d426090

Please sign in to comment.