cutelyst 5.0.0
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
10namespace Cutelyst {
11
12class ValidatorJsonPrivate;
13
36class CUTELYST_PLUGIN_UTILS_VALIDATOR_EXPORT ValidatorJson : public ValidatorRule
37{
38public:
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
69protected:
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
97private:
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
The Cutelyst Context.
Definition context.h:42
Checks if the inut data is valid JSON.
Base class for all validator rules.
std::function< void(ValidatorReturnType &&result)> ValidatorRtFn
Void callback function for validator rules that processes the ValidatorReturnType.
The Cutelyst namespace holds all public Cutelyst API.
Stores custom error messages and the input field label.
Contains the result of a single input parameter validation.