cutelyst  5.0.1
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
validatorjson.h
1 /*
2  * SPDX-FileCopyrightText: (C) 2017-2025 Matthias Fehring <mf@huessenbergnetz.de>
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 #ifndef CUTELYSTVALIDATORJSON_H
6 #define CUTELYSTVALIDATORJSON_H
7 
8 #include "validatorrule.h"
9 
10 namespace Cutelyst {
11 
12 class ValidatorJsonPrivate;
13 
36 class CUTELYST_PLUGIN_UTILS_VALIDATOR_EXPORT ValidatorJson : public ValidatorRule
37 {
38 public:
42  enum class ExpectedType {
43  All,
45  Array,
47  Object
49  };
50 
59  explicit ValidatorJson(const QString &field,
60  ExpectedType expectedType = ExpectedType::All,
61  const ValidatorMessages &messages = {},
62  const QString &defValKey = {});
63 
67  ~ValidatorJson() override;
68 
69 protected:
77  ValidatorReturnType validate(Context *c, const ParamsMultiMap &params) const override;
78 
89  void validateCb(Context *c, const ParamsMultiMap &params, ValidatorRtFn cb) const override;
90 
94  QString genericValidationError(Context *c,
95  const QVariant &errorData = QVariant()) const override;
96 
97 private:
98  Q_DECLARE_PRIVATE(ValidatorJson) // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
99  Q_DISABLE_COPY(ValidatorJson)
100 };
101 
102 } // namespace Cutelyst
103 
104 #endif // CUTELYSTVALIDATORJSON_H
Stores custom error messages and the input field label.
The Cutelyst namespace holds all public Cutelyst API.
Base class for all validator rules.
QMultiMap< QString, QString > ParamsMultiMap
Checks if the inut data is valid JSON.
Definition: validatorjson.h:36