Revision control
- /**
- * Compression Test
- *
- * 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 QtOAI_SERVERVCONFIGURATION_H
- #define QtOAI_SERVERVCONFIGURATION_H
-
- #include "QtOAIServerVariable.h"
-
- #include <QtCore/qstring.h>
- #include <QtCore/qmap.h>
- #include <QtCore/qregularexpression.h>
- #include <QtCore/qurl.h>
-
- #include <stdexcept>
-
- namespace QtOpenAPI {
-
- class QtOAIServerConfiguration {
- 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.
- */
- QtOAIServerConfiguration(const QUrl &url, const QString &description, const QMap<QString, QtOAIServerVariable> &variables)
- : m_description(description),
- m_variables(variables),
- m_url(url) {}
- QtOAIServerConfiguration() {}
- ~QtOAIServerConfiguration() {}
-
- /**
- * Original URL
- *
- * @return Original URL.
- */
- const QUrl serverUrl() const { return m_url; }
-
- /**
- * Format URL template using server's variables.
- *
- * @return Formatted URL.
- */
- QString URL() {
- QString url = m_url.toString();
- if (!m_variables.empty()) {
- // go through variables and replace placeholders
- for (auto const& v : m_variables.keys()) {
- QString name = v;
- QtOAIServerVariable serverVariable = m_variables.value(v);
- QString value = serverVariable.m_defaultValue;
-
- if (!serverVariable.m_enumValues.empty() && !serverVariable.m_enumValues.contains(value)) {
- throw std::runtime_error(QString("The variable " + name + " in the server URL has invalid value " + value + ".").toUtf8().toStdString());
- }
- QRegularExpression regex(QString("\\{" + name + "\\}"));
- url = url.replace(regex, value);
-
- }
- return url;
- }
- return url;
- }
-
- QtOAIServerVariable::ServerError setDefaultValue(const QString &variable, const QString &value) {
- if (m_variables.contains(variable))
- return m_variables[variable].setDefaultValue(value);
- return QtOAIServerVariable::ServerError::ServerVariableNotFound;
- }
-
- QString m_description;
- QMap<QString, QtOAIServerVariable> m_variables;
- QUrl m_url;
- };
-
- } // namespace QtOpenAPI
-
- #endif // QtOAI_SERVERVCONFIGURATION_H