class JSONSchema::FluentObjectValidator

Overview

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

Included Modules

Defined in:

fluent.cr

Instance Method Summary

Instance methods inherited from module JSONSchema::FluentValidatorGenericProperties

all_of(*children) all_of, any_of(*children) any_of, enum_list(*values) enum_list, not(*children) not, one_of(*children) one_of

Instance Method Detail

def additional_properties(v : Validator) #

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


[View source]
def 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

[View source]
def 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

[View source]
def 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

[View source]
def disable_additional_properties #

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


[View source]
def max_properties(value : Int32) #

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


[View source]
def min_properties(value : Int32) #

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


[View source]
def pattern_prop(pattern : Regex, v : Validator) #

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


[View source]
def 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.


[View source]
def property_names(v : Validator) #

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


[View source]
def required(*properties) #

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

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

[View source]
def validator : JSONSchema::ObjectValidator #

[View source]