Skip to content

Validating Resources

Jim Amsden edited this page Feb 21, 2018 · 2 revisions

Here's some rough pseudocode for validating resources against shapes:

resource.validate()
  result = {}
  constraints = getConstraintsFor(resource) // shape.describes === resource
  for each constraint in constraints
    result += constraint.validate(resource)
  end
  return result
end
constraint.validate(resource)
  result = {}
  propertyConstraints = getPropertiesFor(constraint)
  for each propertyConstraint in propertyConstraints
    result += propertyConstraint.validate(resource)
  end
end
propertyConstraint.validate(resource)
  result = {}

  // get the properties of the resource applicable to this constraint
  properties = resource.getProperties(propertyConstraint.propertyDefinition)

  // does the resource have a property with the correct values
  result += validateAllowedValues(properties)

  // does the resource have a property with the right number of instances
  result += validateCardinality(properties) 

  // are the resource property values of acceptable size
  result += validateMaxSize(properties)

  // does the resource have a property with the right type (includes range and valueType)
  result += validateType(properties)

  // is the property represented properly in the resource
  result += validateRepresentation(properties)

  return result
end
Clone this wiki locally