mirror of
https://github.com/tristanpenman/valijson.git
synced 2024-12-13 10:32:58 +01:00
Basic structure for format constraint
This commit is contained in:
parent
a6a4fbb580
commit
5f49d77b1e
@ -427,6 +427,33 @@ private:
|
||||
EnumValues m_enumValues;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Represent a 'format' constraint
|
||||
*
|
||||
* A format constraint restricts the content of string values, as defined by a set of commonly used formats.
|
||||
*
|
||||
* As this is an optional feature in JSON Schema, unrecognised formats will be treated as valid for any string value.
|
||||
*/
|
||||
class FormatConstraint: public BasicConstraint<FormatConstraint>
|
||||
{
|
||||
public:
|
||||
FormatConstraint()
|
||||
: m_format() { }
|
||||
|
||||
const std::string & getFormat() const
|
||||
{
|
||||
return m_format;
|
||||
}
|
||||
|
||||
void setFormat(const std::string & format)
|
||||
{
|
||||
m_format = format;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_format;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Represents non-singular 'items' and 'additionalItems' constraints
|
||||
*
|
||||
|
@ -10,6 +10,7 @@ class ConstConstraint;
|
||||
class ContainsConstraint;
|
||||
class DependenciesConstraint;
|
||||
class EnumConstraint;
|
||||
class FormatConstraint;
|
||||
class LinearItemsConstraint;
|
||||
class MaxItemsConstraint;
|
||||
class MaximumConstraint;
|
||||
@ -46,6 +47,7 @@ protected:
|
||||
typedef constraints::ContainsConstraint ContainsConstraint;
|
||||
typedef constraints::DependenciesConstraint DependenciesConstraint;
|
||||
typedef constraints::EnumConstraint EnumConstraint;
|
||||
typedef constraints::FormatConstraint FormatConstraint;
|
||||
typedef constraints::LinearItemsConstraint LinearItemsConstraint;
|
||||
typedef constraints::MaximumConstraint MaximumConstraint;
|
||||
typedef constraints::MaxItemsConstraint MaxItemsConstraint;
|
||||
@ -77,6 +79,7 @@ public:
|
||||
virtual bool visit(const ContainsConstraint &) = 0;
|
||||
virtual bool visit(const DependenciesConstraint &) = 0;
|
||||
virtual bool visit(const EnumConstraint &) = 0;
|
||||
virtual bool visit(const FormatConstraint &) = 0;
|
||||
virtual bool visit(const LinearItemsConstraint &) = 0;
|
||||
virtual bool visit(const MaximumConstraint &) = 0;
|
||||
virtual bool visit(const MaxItemsConstraint &) = 0;
|
||||
|
@ -694,6 +694,10 @@ private:
|
||||
rootSchema.addConstraintToSubschema(makeEnumConstraint(itr->second), &subschema);
|
||||
}
|
||||
|
||||
if ((itr = object.find("format")) != object.end()) {
|
||||
rootSchema.addConstraintToSubschema(makeFormatConstraint(itr->second), &subschema);
|
||||
}
|
||||
|
||||
{
|
||||
const typename AdapterType::Object::const_iterator itemsItr =
|
||||
object.find("items");
|
||||
@ -1421,6 +1425,24 @@ private:
|
||||
return constraint;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Make a new FormatConstraint object
|
||||
*
|
||||
* @param node JSON node containing the configuration for this constraint
|
||||
*
|
||||
* @return pointer to a new FormatConstraint that belongs to the caller
|
||||
*/
|
||||
template<typename AdapterType>
|
||||
constraints::FormatConstraint makeFormatConstraint(
|
||||
const AdapterType &node)
|
||||
{
|
||||
constraints::FormatConstraint constraint;
|
||||
|
||||
// TODO
|
||||
|
||||
return constraint;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Make a new ItemsConstraint object.
|
||||
*
|
||||
|
@ -347,6 +347,20 @@ public:
|
||||
return numValidated > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Validate current node against a FormatConstraint
|
||||
*
|
||||
* @param constraint Constraint that the target must validate against
|
||||
*
|
||||
* @return \c true if validation succeeds; \c false otherwise
|
||||
*/
|
||||
bool visit(const FormatConstraint &constraint) override
|
||||
{
|
||||
// TODO
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Validate a value against a LinearItemsConstraint
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user