1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
// ServerConfiguration.mustache
// licenseInfo.mustache
/**
* Libre Graph API
* Libre Graph is a free API for cloud collaboration inspired by the MS Graph API.
*
* The version of the OpenAPI document: v1.0.4
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/**
* Representing a Server configuration.
*/
#ifndef OAI_SERVERVCONFIGURATION_H
#define OAI_SERVERVCONFIGURATION_H
#include <QString>
#include <QMap>
#include <QRegularExpression>
#include <QUrl>
#include <stdexcept>
#include "OAIServerVariable.h"
namespace OpenAPI {
class OAIServerConfiguration {
public:
/**
* @param url A URL to the target host.
* @param description A description of the host designated by the URL.
* @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template.
*/
OAIServerConfiguration(const QUrl &url, const QString &description, const QMap<QString, OAIServerVariable> &variables)
: _description(description),
_variables(variables),
_url(url){}
OAIServerConfiguration(){}
~OAIServerConfiguration(){}
/**
* Format URL template using given variables.
*
* @param variables A map between a variable name and its value.
* @return Formatted URL.
*/
QString URL() {
QString url = _url.toString();
if(!_variables.empty()){
// go through variables and replace placeholders
for (auto const& v : _variables.keys()) {
QString name = v;
OAIServerVariable serverVariable = _variables.value(v);
QString value = serverVariable._defaultValue;
if (!serverVariable._enumValues.empty() && !serverVariable._enumValues.contains(value)) {
qFatal("The variable %s in the server URL has invalid value %s.", qPrintable(name), qPrintable(value));
}
QRegularExpression regex(QString("\\{" + name + "\\}"));
url = url.replace(regex, value);
}
return url;
}
return url;
}
int setDefaultValue(const QString &variable,const QString &value){
if(_variables.contains(variable))
return _variables[variable].setDefaultValue(value);
return -1;
}
QString _description;
QMap<QString, OAIServerVariable> _variables;
QUrl _url;
};
} // namespace OpenAPI
#endif // OAI_SERVERVCONFIGURATION_H
|