/*
- * Copyright 2015 Facebook, Inc.
+ * Copyright 2016 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
explicit SchemaValidatorContext(const dynamic& s) : schema(s) {}
const dynamic& schema;
- std::unordered_map<fbstring, IValidator*> refs;
+ std::unordered_map<std::string, IValidator*> refs;
};
/**
if (type_ == Type::MIN) {
if (exclusive_) {
if (v <= s) {
- return makeError("greater than", schema_, value);
+ return makeError("greater than ", schema_, value);
}
} else {
if (v < s) {
- return makeError("greater than or equal to", schema_, value);
+ return makeError("greater than or equal to ", schema_, value);
}
}
} else if (type_ == Type::MAX) {
if (exclusive_) {
if (v >= s) {
- return makeError("less than", schema_, value);
+ return makeError("less than ", schema_, value);
}
} else {
if (v > s) {
- return makeError("less than or equal to", schema_, value);
+ return makeError("less than or equal to ", schema_, value);
}
}
}
struct StringPatternValidator final : IValidator {
explicit StringPatternValidator(const dynamic& schema) {
if (schema.isString()) {
- regex_ = boost::regex(schema.getString().toStdString());
+ regex_ = boost::regex(schema.getString());
}
}
if (!value.isString() || regex_.empty()) {
return none;
}
- if (!boost::regex_search(value.getString().toStdString(), regex_)) {
+ if (!boost::regex_search(value.getString(), regex_)) {
return makeError("string matching regex", value);
}
return none;
if (value.isObject()) {
for (const auto& prop : properties_) {
if (!value.get_ptr(prop)) {
- return makeError("to have property", prop, value);
+ return makeError("property ", prop, value);
}
}
}
}
private:
- std::vector<fbstring> properties_;
+ std::vector<std::string> properties_;
};
struct PropertiesValidator final : IValidator {
for (const auto& pair : patternProperties->items()) {
if (pair.first.isString()) {
patternPropertyValidators_.emplace_back(
- boost::regex(pair.first.getString().toStdString()),
+ boost::regex(pair.first.getString()),
SchemaValidator::make(context, pair.second));
}
}
if (!pair.first.isString()) {
continue;
}
- const fbstring& key = pair.first.getString();
+ const std::string& key = pair.first.getString();
auto it = propertyValidators_.find(key);
bool matched = false;
if (it != propertyValidators_.end()) {
matched = true;
}
- const std::string& strkey = key.toStdString();
+ const std::string& strkey = key;
for (const auto& ppv : patternPropertyValidators_) {
if (boost::regex_search(strkey, ppv.first)) {
if (auto se = vc.validate(ppv.second.get(), pair.second)) {
return none;
}
- std::unordered_map<fbstring, std::unique_ptr<IValidator>> propertyValidators_;
+ std::unordered_map<std::string, std::unique_ptr<IValidator>>
+ propertyValidators_;
std::vector<std::pair<boost::regex, std::unique_ptr<IValidator>>>
patternPropertyValidators_;
std::unique_ptr<IValidator> additionalPropertyValidator_;
continue;
}
if (pair.second.isArray()) {
- auto p = make_pair(pair.first.getString(), std::vector<fbstring>());
+ auto p = make_pair(pair.first.getString(), std::vector<std::string>());
for (const auto& item : pair.second) {
if (item.isString()) {
p.second.push_back(item.getString());
if (value.count(pair.first)) {
for (const auto& prop : pair.second) {
if (!value.count(prop)) {
- return makeError("property", prop, value);
+ return makeError("property ", prop, value);
}
}
}
return none;
}
- std::vector<std::pair<fbstring, std::vector<fbstring>>> propertyDep_;
- std::vector<std::pair<fbstring, std::unique_ptr<IValidator>>> schemaDep_;
+ std::vector<std::pair<std::string, std::vector<std::string>>> propertyDep_;
+ std::vector<std::pair<std::string, std::unique_ptr<IValidator>>> schemaDep_;
};
struct EnumValidator final : IValidator {
return std::move(v);
}
-Validator* makeSchemaValidator() { return schemaValidator.get(); }
+std::shared_ptr<Validator> makeSchemaValidator() {
+ return schemaValidator.try_get();
+}
}
}