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

Method string

src/json-validator.cpp:817–881  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

815
816public:
817 string(json &sch, root_schema *root)
818 : schema(root)
819 {
820 auto attr = sch.find("maxLength");
821 if (attr != sch.end()) {
822 maxLength_ = {true, attr.value().get<size_t>()};
823 sch.erase(attr);
824 }
825
826 attr = sch.find("minLength");
827 if (attr != sch.end()) {
828 minLength_ = {true, attr.value().get<size_t>()};
829 sch.erase(attr);
830 }
831
832 attr = sch.find("contentEncoding");
833 if (attr != sch.end()) {
834 std::get<0>(content_) = true;
835 std::get<1>(content_) = attr.value().get<std::string>();
836
837 // special case for nlohmann::json-binary-types
838 //
839 // https://github.com/pboettch/json-schema-validator/pull/114
840 //
841 // We cannot use explicitly in a schema: {"type": "binary"} or
842 // "type": ["binary", "number"] we have to be implicit. For a
843 // schema where "contentEncoding" is set to "binary", an instance
844 // of type json::value_t::binary is accepted. If a
845 // contentEncoding-callback has to be provided and is called
846 // accordingly. For encoding=binary, no other type validations are done
847
848 sch.erase(attr);
849 }
850
851 attr = sch.find("contentMediaType");
852 if (attr != sch.end()) {
853 std::get<0>(content_) = true;
854 std::get<2>(content_) = attr.value().get<std::string>();
855
856 sch.erase(attr);
857 }
858
859 if (std::get<0>(content_) == true && root_->content_check() == nullptr) {
860 throw std::invalid_argument{"schema contains contentEncoding/contentMediaType but content checker was not set"};
861 }
862
863#ifndef NO_STD_REGEX
864 attr = sch.find("pattern");
865 if (attr != sch.end()) {
866 patternString_ = attr.value().get<std::string>();
867 pattern_ = {true, REGEX_NAMESPACE::regex(attr.value().get<std::string>(),
868 REGEX_NAMESPACE::regex::ECMAScript)};
869 sch.erase(attr);
870 }
871#endif
872
873 attr = sch.find("format");
874 if (attr != sch.end()) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected