18#include "moc_qgsserverquerystringparameter.cpp"
21#include "nlohmann/json.hpp"
26 const QString &description,
27 const QVariant &defaultValue ):
29 mRequired( required ),
31 mDescription( description ),
32 mDefaultValue( defaultValue )
45 if ( mRequired && !QUrlQuery( context.
request()->
url() ).hasQueryItem( mName ) )
52 if ( QUrlQuery( context.
request()->
url() ).hasQueryItem( mName ) )
54 value = QUrlQuery( context.
request()->
url() ).queryItemValue( mName, QUrl::FullyDecoded );
56 else if ( mDefaultValue.isValid() )
58 value = mDefaultValue;
61 if (
value.isValid() )
65 const QMetaType::Type targetType {
static_cast< QMetaType::Type
>( mType )};
71 if (
value.userType() != targetType )
74 if (
value.canConvert(
static_cast<int>( targetType ) ) )
104 if ( mCustomValidator && ! mCustomValidator( context,
value ) )
114 mCustomValidator = customValidator;
119 const auto nameString {
name().toStdString() };
120 auto dataType {
typeName( mType ).toLower().toStdString() };
122 if ( dataType ==
"list" )
126 else if ( dataType ==
"double" )
132 {
"name", nameString },
134 {
"required", mRequired },
137 {
"explode",
false },
138 {
"schema", {{
"type", dataType }}},
150 static const QMetaEnum metaEnum = QMetaEnum::fromType<Type>();
151 return metaEnum.valueToKey(
static_cast<int>( type ) );
Bad request error API exception.
The QgsServerApiContext class encapsulates the resources for a particular client request: the request...
const QgsServerRequest * request() const
Returns the server request object.
QString description() const
Returns parameter description.
virtual QVariant value(const QgsServerApiContext &context) const
Extracts the value from the request context by validating the parameter value and converting it to it...
QgsServerQueryStringParameter(const QString name, bool required=false, Type type=QgsServerQueryStringParameter::Type::String, const QString &description=QString(), const QVariant &defaultValue=QVariant())
Constructs a QgsServerQueryStringParameter object.
void setHidden(bool hidden)
Set the parameter's hidden status, parameters are not hidden by default.
QString name() const
Returns the name of the parameter.
Type
The Type enum represents the parameter type.
@ String
Parameter is a string.
@ Boolean
Parameter is a boolean.
@ List
Parameter is a (comma separated) list of strings, the handler will perform any further required conve...
@ Integer
Parameter is an integer.
@ Double
Parameter is a double.
json data() const
Returns the handler information as a JSON object.
virtual ~QgsServerQueryStringParameter()
static QString typeName(const Type type)
Returns the name of the type.
void setDescription(const QString &description)
Sets validator description.
void setCustomValidator(const customValidator &customValidator)
Sets the custom validation function to customValidator.
bool hidden() const
Returns true if the parameter is hidden from the schema.