string_constraint.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #pragma once
  2. #include <string>
  3. #include <jvalidate/detail/string.h>
  4. #include <jvalidate/enum.h>
  5. #include <jvalidate/forward.h>
  6. namespace jvalidate::constraint {
  7. /**
  8. * @brief A constraint on the String type with the following characteristic(s):
  9. * @code{.cpp}
  10. * arg.size() >= value
  11. * @endcode
  12. *
  13. * https://json-schema.org/draft/2020-12/json-schema-validation#section-6.3.2
  14. */
  15. struct MinLengthConstraint {
  16. int64_t value;
  17. };
  18. /**
  19. * @brief A constraint on the String type with the following characteristic(s):
  20. * @code{.cpp}
  21. * arg.size() <= value
  22. * @endcode
  23. *
  24. * https://json-schema.org/draft/2020-12/json-schema-validation#section-6.3.1
  25. */
  26. struct MaxLengthConstraint {
  27. int64_t value;
  28. };
  29. /**
  30. * @brief A constraint on the String type with the following characteristic(s):
  31. * @code{.py}
  32. * re.match(regex, arg)
  33. * @endcode
  34. *
  35. * https://json-schema.org/draft/2020-12/json-schema-validation#section-6.3.3
  36. */
  37. struct PatternConstraint {
  38. std::string regex;
  39. };
  40. /**
  41. * @brief A constraint on the String type that describes a string format using
  42. * a human friendly name. The implementation of the regular expression, ABNF
  43. * grammer, or state-machine parser that checks the validity of the string
  44. * (for the standard list of formats respected by the JSON schema RPC) is
  45. * implemented in {@see include/jvalidate/format.h}.
  46. *
  47. * https://json-schema.org/draft/2020-12/json-schema-validation#section-7
  48. */
  49. struct FormatConstraint {
  50. std::string format;
  51. schema::Version for_version;
  52. bool is_assertion;
  53. };
  54. }