class

JSONSchema::FluentObjectValidator

Inherits JSONSchema::FluentValidatorGenericProperties / Reference / Object

A fluent API for creating instances of JSONSchema::ObjectValidator.

Instance methods

additional_properties(v : Validator)

Set the validator for any additional properties not in the properties definition. See Additional Properties.

Source
dependent_required(name : String, values : Array(String))

Set a single dependent required property by name. See Dependent Required.

validator = JSONSchema.fluent.object do
  dependent_required "creditCard", ["billingAddress"]
  dependent_required "couponCode", ["source"]
end
Source
dependent_required(value : Hash(String, Array(String)))

Set the list of dependent required properties. See Dependent Required.

validator = JSONSchema.fluent.object do
  dependent_required({
    "creditCard" => ["billingAddress"],
  })
end
Source
dependent_schema(name : String, &)

Set a single dependent schema property by name. See Dependent Schemas. This method accepts a block, unlike many fluent methods. Since we know an dependent_schema value must be a JSONSchema::ObjectValidator, we accept a block and use JSONSchema::FluentObjectValidator as the receiver.

# Validates that "prop1" is both present and a number, given "prop1" is present
validator = JSONSchema.fluent.object do
  dependent_schema "prop1" do
    prop "prop2", JSONSchema.fluent.number
    required "prop2"
  end
end
Source
disable_additional_properties

Set the constraint for disabling additional properties. See Addiitonal Properties.

Source
max_properties(value : Int32)

Set a validator for the minimum number of properties that must be on the object.

Source
min_properties(value : Int32)

Set a validator for the minimum number of properties that must be on the object.

Source
pattern_prop(pattern : Regex, v : Validator)

Set the validator for a given Regex. See Pattern Properties.

Source
prop(name : String, v : Validator)

Set the validator for a property by name. This method is named prop to not conflict with the global property macro.

Source
property_names(v : Validator)

Set a validator for all property names. See Property names.

Source
required(*properties)

Set the list of required properties as any number of strings.

validator = JSONSchema.fluent.object do
  required "name", "age"
end
Source
validator
Source