JSONSchema::FluentObjectValidator
Inherits JSONSchema::FluentValidatorGenericProperties / Reference / Object
A fluent API for creating instances of JSONSchema::ObjectValidator.
Instance methods
Set the validator for any additional properties not in the properties definition. See Additional Properties.
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
Set the list of dependent required properties. See Dependent Required.
validator = JSONSchema.fluent.object do
dependent_required({
"creditCard" => ["billingAddress"],
})
end
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
Set the constraint for disabling additional properties. See Addiitonal Properties.
Set a validator for the minimum number of properties that must be on the object.
Set a validator for the minimum number of properties that must be on the object.
Set the validator for a given Regex. See Pattern Properties.
Set the validator for a property by name. This method is named prop to not conflict with the global property macro.
Set the list of required properties as any number of strings.
validator = JSONSchema.fluent.object do
required "name", "age"
end