Revision control

+ /**
+ * Operation Parameters Test
+ *
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
+ * Do not edit the class manually.
+ */
+
+ /**
+ * Representing a Server configuration.
+ */
+ #ifndef OAI_SERVERVCONFIGURATION_H
+ #define OAI_SERVERVCONFIGURATION_H
+
+ #include "OAIServerVariable.h"
+
+ #include <QtCore/qstring.h>
+ #include <QtCore/qmap.h>
+ #include <QtCore/qregularexpression.h>
+ #include <QtCore/qurl.h>
+
+ #include <stdexcept>
+
+ 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)
+ : m_description(description),
+ m_variables(variables),
+ m_url(url) {}
+ OAIServerConfiguration() {}
+ ~OAIServerConfiguration() {}
+
+ /**
+ * 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;
+ OAIServerVariable 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;
+ }
+
+ OAIServerVariable::ServerError setDefaultValue(const QString &variable, const QString &value) {
+ if (m_variables.contains(variable))
+ return m_variables[variable].setDefaultValue(value);
+ return OAIServerVariable::ServerError::ServerVariableNotFound;
+ }
+
+ QString m_description;
+ QMap<QString, OAIServerVariable> m_variables;
+ QUrl m_url;
+ };
+
+ } // namespace OpenAPI
+
+ #endif // OAI_SERVERVCONFIGURATION_H