MCPcopy Create free account
hub / github.com/pboettch/json-schema-validator / validate

Method validate

src/json-validator.cpp:761–814  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

759 }
760
761 void validate(const json::json_pointer &ptr, const json &instance, json_patch &, error_handler &e) const override
762 {
763 if (minLength_.first) {
764 if (utf8_length(instance.get<std::string>()) < minLength_.second) {
765 std::ostringstream s;
766 s << "instance is too short as per minLength:" << minLength_.second;
767 e.error(ptr, instance, s.str());
768 }
769 }
770
771 if (maxLength_.first) {
772 if (utf8_length(instance.get<std::string>()) > maxLength_.second) {
773 std::ostringstream s;
774 s << "instance is too long as per maxLength: " << maxLength_.second;
775 e.error(ptr, instance, s.str());
776 }
777 }
778
779 if (std::get<0>(content_)) {
780 if (root_->content_check() == nullptr)
781 e.error(ptr, instance, std::string("a content checker was not provided but a contentEncoding or contentMediaType for this string have been present: '") + std::get<1>(content_) + "' '" + std::get<2>(content_) + "'");
782 else {
783 try {
784 root_->content_check()(std::get<1>(content_), std::get<2>(content_), instance);
785 } catch (const std::exception &ex) {
786 e.error(ptr, instance, std::string("content-checking failed: ") + ex.what());
787 }
788 }
789 } else if (instance.type() == json::value_t::binary) {
790 e.error(ptr, instance, "expected string, but get binary data");
791 }
792
793 if (instance.type() != json::value_t::string) {
794 return; // next checks only for strings
795 }
796
797#ifndef NO_STD_REGEX
798 if (pattern_.first &&
799 !REGEX_NAMESPACE::regex_search(instance.get<std::string>(), pattern_.second))
800 e.error(ptr, instance, "instance does not match regex pattern: " + patternString_);
801#endif
802
803 if (format_.first) {
804 if (root_->format_check() == nullptr)
805 e.error(ptr, instance, std::string("a format checker was not provided but a format keyword for this string is present: ") + format_.second);
806 else {
807 try {
808 root_->format_check()(format_.second, instance.get<std::string>());
809 } catch (const std::exception &ex) {
810 e.error(ptr, instance, std::string("format-checking failed: ") + ex.what());
811 }
812 }
813 }
814 }
815
816public:
817 string(json &sch, root_schema *root)

Callers

nothing calls this directly

Calls 3

stringClass · 0.85
whatMethod · 0.80
errorMethod · 0.45

Tested by

no test coverage detected