diff --git a/docs/generators/cpp-qt-client.md b/docs/generators/cpp-qt-client.md
index ad64db7463b..0cac6f6e4f7 100644
--- a/docs/generators/cpp-qt-client.md
+++ b/docs/generators/cpp-qt-client.md
@@ -26,6 +26,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true|
|enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|
- **false**
- No changes to the enum's are made, this is the default option.
- **true**
- With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.
|false|
|legacyDiscriminatorBehavior|Set to false for generators with better support for discriminators. (Python, Java, Go, PowerShell, C# have this enabled by default).|- **true**
- The mapping in the discriminator includes descendent schemas that allOf inherit from self and the discriminator mapping schemas in the OAS document.
- **false**
- The mapping in the discriminator includes any descendent schemas that allOf inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values, and the discriminator mapping schemas in the OAS document AND Codegen validates that oneOf and anyOf schemas contain the required discriminator and throws an error if the discriminator is missing.
|true|
+|makeOperationsVirtual|Make all operations methods virtual. This makes it easy to mock the generated API class for testing purposes.| |true|
|modelNamePrefix|Prefix that will be prepended to all model names.| |OAI|
|optionalProjectFile|Generate client.pri.| |true|
|packageName|C++ package (library) name.| |QtOpenAPIClient|
diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQtClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQtClientCodegen.java
index 49fe90d08ad..e03d8cfb0fd 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQtClientCodegen.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQtClientCodegen.java
@@ -36,11 +36,16 @@ import static org.openapitools.codegen.utils.StringUtils.*;
public class CppQtClientCodegen extends CppQtAbstractCodegen implements CodegenConfig {
public static final String OPTIONAL_PROJECT_FILE_DESC = "Generate client.pri.";
public static final String DEFAULT_PACKAGE_NAME = "QtOpenAPIClient";
+ public static final String MAKE_OPERATIONS_VIRTUAL_NAME = "makeOperationsVirtual";
+ public static final String MAKE_OPERATIONS_VIRTUAL_DESC =
+ "Make all operations methods virtual. " +
+ "This makes it easy to mock the generated API class for testing purposes.";
protected String packageName = "";
// source folder where to write the files
protected String sourceFolder = "client";
@Setter protected boolean optionalProjectFileFlag = true;
@Setter protected boolean addDownloadProgress = false;
+ @Setter protected boolean makeOperationsVirtual = true;
public CppQtClientCodegen() {
super();
@@ -100,6 +105,7 @@ public class CppQtClientCodegen extends CppQtAbstractCodegen implements CodegenC
addOption(CodegenConstants.PACKAGE_NAME, "C++ package (library) name.", DEFAULT_PACKAGE_NAME);
addSwitch(CodegenConstants.OPTIONAL_PROJECT_FILE, OPTIONAL_PROJECT_FILE_DESC, this.optionalProjectFileFlag);
addSwitch("addDownloadProgress", "Add support for Qt download progress", this.addDownloadProgress);
+ addSwitch(MAKE_OPERATIONS_VIRTUAL_NAME, MAKE_OPERATIONS_VIRTUAL_DESC, this.makeOperationsVirtual);
supportingFiles.add(new SupportingFile("helpers-header.mustache", sourceFolder, PREFIX + "Helpers.h"));
supportingFiles.add(new SupportingFile("helpers-body.mustache", sourceFolder, PREFIX + "Helpers.cpp"));
@@ -140,6 +146,12 @@ public class CppQtClientCodegen extends CppQtAbstractCodegen implements CodegenC
additionalProperties.put(CodegenConstants.OPTIONAL_PROJECT_FILE, optionalProjectFileFlag);
}
+ if (additionalProperties.containsKey(MAKE_OPERATIONS_VIRTUAL_NAME)) {
+ setMakeOperationsVirtual(convertPropertyToBooleanAndWriteBack(MAKE_OPERATIONS_VIRTUAL_NAME));
+ } else {
+ additionalProperties.put(MAKE_OPERATIONS_VIRTUAL_NAME, makeOperationsVirtual);
+ }
+
additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);
if (additionalProperties.containsKey("modelNamePrefix")) {
diff --git a/modules/openapi-generator/src/main/resources/cpp-qt-client/api-header.mustache b/modules/openapi-generator/src/main/resources/cpp-qt-client/api-header.mustache
index 5391f6a6b05..c23076286fb 100644
--- a/modules/openapi-generator/src/main/resources/cpp-qt-client/api-header.mustache
+++ b/modules/openapi-generator/src/main/resources/cpp-qt-client/api-header.mustache
@@ -58,7 +58,7 @@ public:
{{/required}}
{{/allParams}}
*/{{/hasParams}}
- {{#isDeprecated}}Q_DECL_DEPRECATED {{/isDeprecated}}void {{nickname}}({{#allParams}}{{#required}}const {{{dataType}}} &{{/required}}{{^required}}const ::{{cppNamespace}}::OptionalParam<{{{dataType}}}> &{{/required}}{{paramName}}{{^required}} = ::{{cppNamespace}}::OptionalParam<{{{dataType}}}>(){{/required}}{{^-last}}, {{/-last}}{{/allParams}});
+ {{#isDeprecated}}Q_DECL_DEPRECATED {{/isDeprecated}}{{#makeOperationsVirtual}}virtual {{/makeOperationsVirtual}}void {{nickname}}({{#allParams}}{{#required}}const {{{dataType}}} &{{/required}}{{^required}}const ::{{cppNamespace}}::OptionalParam<{{{dataType}}}> &{{/required}}{{paramName}}{{^required}} = ::{{cppNamespace}}::OptionalParam<{{{dataType}}}>(){{/required}}{{^-last}}, {{/-last}}{{/allParams}});
{{/operation}}{{/operations}}
private:
diff --git a/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXPetApi.h b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXPetApi.h
index e2688c5b9d3..5d69d20d872 100644
--- a/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXPetApi.h
+++ b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXPetApi.h
@@ -62,50 +62,50 @@ public:
/**
* @param[in] pfx_pet PFXPet [required]
*/
- void addPet(const PFXPet &pfx_pet);
+ virtual void addPet(const PFXPet &pfx_pet);
- void allPets();
+ virtual void allPets();
/**
* @param[in] pet_id qint64 [required]
* @param[in] api_key QString [optional]
*/
- void deletePet(const qint64 &pet_id, const ::test_namespace::OptionalParam &api_key = ::test_namespace::OptionalParam());
+ virtual void deletePet(const qint64 &pet_id, const ::test_namespace::OptionalParam &api_key = ::test_namespace::OptionalParam());
/**
* @param[in] status QList [required]
*/
- void findPetsByStatus(const QList &status);
+ virtual void findPetsByStatus(const QList &status);
/**
* @param[in] tags QList [required]
*/
- Q_DECL_DEPRECATED void findPetsByTags(const QList &tags);
+ Q_DECL_DEPRECATED virtual void findPetsByTags(const QList &tags);
/**
* @param[in] pet_id qint64 [required]
*/
- void getPetById(const qint64 &pet_id);
+ virtual void getPetById(const qint64 &pet_id);
/**
* @param[in] pfx_pet PFXPet [required]
*/
- void updatePet(const PFXPet &pfx_pet);
+ virtual void updatePet(const PFXPet &pfx_pet);
/**
* @param[in] pet_id qint64 [required]
* @param[in] name QString [optional]
* @param[in] status QString [optional]
*/
- void updatePetWithForm(const qint64 &pet_id, const ::test_namespace::OptionalParam &name = ::test_namespace::OptionalParam(), const ::test_namespace::OptionalParam &status = ::test_namespace::OptionalParam());
+ virtual void updatePetWithForm(const qint64 &pet_id, const ::test_namespace::OptionalParam &name = ::test_namespace::OptionalParam(), const ::test_namespace::OptionalParam &status = ::test_namespace::OptionalParam());
/**
* @param[in] pet_id qint64 [required]
* @param[in] additional_metadata QString [optional]
* @param[in] file PFXHttpFileElement [optional]
*/
- void uploadFile(const qint64 &pet_id, const ::test_namespace::OptionalParam &additional_metadata = ::test_namespace::OptionalParam(), const ::test_namespace::OptionalParam &file = ::test_namespace::OptionalParam());
+ virtual void uploadFile(const qint64 &pet_id, const ::test_namespace::OptionalParam &additional_metadata = ::test_namespace::OptionalParam(), const ::test_namespace::OptionalParam &file = ::test_namespace::OptionalParam());
private:
diff --git a/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXPrimitivesApi.h b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXPrimitivesApi.h
index 722ef1746b5..f3a447e2d94 100644
--- a/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXPrimitivesApi.h
+++ b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXPrimitivesApi.h
@@ -58,12 +58,12 @@ public:
/**
* @param[in] body qint32 [optional]
*/
- void primitivesIntegerPost(const ::test_namespace::OptionalParam &body = ::test_namespace::OptionalParam());
+ virtual void primitivesIntegerPost(const ::test_namespace::OptionalParam &body = ::test_namespace::OptionalParam());
/**
* @param[in] body double [optional]
*/
- void primitivesNumberPut(const ::test_namespace::OptionalParam &body = ::test_namespace::OptionalParam());
+ virtual void primitivesNumberPut(const ::test_namespace::OptionalParam &body = ::test_namespace::OptionalParam());
private:
diff --git a/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXStoreApi.h b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXStoreApi.h
index e5ff6fd32b7..a9998a0e55c 100644
--- a/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXStoreApi.h
+++ b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXStoreApi.h
@@ -60,20 +60,20 @@ public:
/**
* @param[in] order_id QString [required]
*/
- void deleteOrder(const QString &order_id);
+ virtual void deleteOrder(const QString &order_id);
- void getInventory();
+ virtual void getInventory();
/**
* @param[in] order_id qint64 [required]
*/
- void getOrderById(const qint64 &order_id);
+ virtual void getOrderById(const qint64 &order_id);
/**
* @param[in] pfx_order PFXOrder [required]
*/
- void placeOrder(const PFXOrder &pfx_order);
+ virtual void placeOrder(const PFXOrder &pfx_order);
private:
diff --git a/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXUserApi.h b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXUserApi.h
index 8356df7c53e..39821909a15 100644
--- a/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXUserApi.h
+++ b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXUserApi.h
@@ -59,42 +59,42 @@ public:
/**
* @param[in] pfx_user PFXUser [required]
*/
- void createUser(const PFXUser &pfx_user);
+ virtual void createUser(const PFXUser &pfx_user);
/**
* @param[in] pfx_user QList [required]
*/
- void createUsersWithArrayInput(const QList &pfx_user);
+ virtual void createUsersWithArrayInput(const QList &pfx_user);
/**
* @param[in] pfx_user QList [required]
*/
- void createUsersWithListInput(const QList &pfx_user);
+ virtual void createUsersWithListInput(const QList &pfx_user);
/**
* @param[in] username QString [required]
*/
- void deleteUser(const QString &username);
+ virtual void deleteUser(const QString &username);
/**
* @param[in] username QString [required]
*/
- void getUserByName(const QString &username);
+ virtual void getUserByName(const QString &username);
/**
* @param[in] username QString [required]
* @param[in] password QString [required]
*/
- void loginUser(const QString &username, const QString &password);
+ virtual void loginUser(const QString &username, const QString &password);
- void logoutUser();
+ virtual void logoutUser();
/**
* @param[in] username QString [required]
* @param[in] pfx_user PFXUser [required]
*/
- void updateUser(const QString &username, const PFXUser &pfx_user);
+ virtual void updateUser(const QString &username, const PFXUser &pfx_user);
private:
diff --git a/samples/client/petstore/cpp-qt/client/PFXPetApi.h b/samples/client/petstore/cpp-qt/client/PFXPetApi.h
index 42d40f1735f..4e86ad47e1f 100644
--- a/samples/client/petstore/cpp-qt/client/PFXPetApi.h
+++ b/samples/client/petstore/cpp-qt/client/PFXPetApi.h
@@ -62,50 +62,50 @@ public:
/**
* @param[in] pfx_pet PFXPet [required]
*/
- void addPet(const PFXPet &pfx_pet);
+ virtual void addPet(const PFXPet &pfx_pet);
- void allPets();
+ virtual void allPets();
/**
* @param[in] pet_id qint64 [required]
* @param[in] api_key QString [optional]
*/
- void deletePet(const qint64 &pet_id, const ::test_namespace::OptionalParam &api_key = ::test_namespace::OptionalParam());
+ virtual void deletePet(const qint64 &pet_id, const ::test_namespace::OptionalParam &api_key = ::test_namespace::OptionalParam());
/**
* @param[in] status QList [required]
*/
- void findPetsByStatus(const QList &status);
+ virtual void findPetsByStatus(const QList &status);
/**
* @param[in] tags QList [required]
*/
- Q_DECL_DEPRECATED void findPetsByTags(const QList &tags);
+ Q_DECL_DEPRECATED virtual void findPetsByTags(const QList &tags);
/**
* @param[in] pet_id qint64 [required]
*/
- void getPetById(const qint64 &pet_id);
+ virtual void getPetById(const qint64 &pet_id);
/**
* @param[in] pfx_pet PFXPet [required]
*/
- void updatePet(const PFXPet &pfx_pet);
+ virtual void updatePet(const PFXPet &pfx_pet);
/**
* @param[in] pet_id qint64 [required]
* @param[in] name QString [optional]
* @param[in] status QString [optional]
*/
- void updatePetWithForm(const qint64 &pet_id, const ::test_namespace::OptionalParam &name = ::test_namespace::OptionalParam(), const ::test_namespace::OptionalParam &status = ::test_namespace::OptionalParam());
+ virtual void updatePetWithForm(const qint64 &pet_id, const ::test_namespace::OptionalParam &name = ::test_namespace::OptionalParam(), const ::test_namespace::OptionalParam &status = ::test_namespace::OptionalParam());
/**
* @param[in] pet_id qint64 [required]
* @param[in] additional_metadata QString [optional]
* @param[in] file PFXHttpFileElement [optional]
*/
- void uploadFile(const qint64 &pet_id, const ::test_namespace::OptionalParam &additional_metadata = ::test_namespace::OptionalParam(), const ::test_namespace::OptionalParam &file = ::test_namespace::OptionalParam());
+ virtual void uploadFile(const qint64 &pet_id, const ::test_namespace::OptionalParam &additional_metadata = ::test_namespace::OptionalParam(), const ::test_namespace::OptionalParam &file = ::test_namespace::OptionalParam());
private:
diff --git a/samples/client/petstore/cpp-qt/client/PFXPrimitivesApi.h b/samples/client/petstore/cpp-qt/client/PFXPrimitivesApi.h
index 64de9e41430..00851c1f27e 100644
--- a/samples/client/petstore/cpp-qt/client/PFXPrimitivesApi.h
+++ b/samples/client/petstore/cpp-qt/client/PFXPrimitivesApi.h
@@ -58,12 +58,12 @@ public:
/**
* @param[in] body qint32 [optional]
*/
- void primitivesIntegerPost(const ::test_namespace::OptionalParam &body = ::test_namespace::OptionalParam());
+ virtual void primitivesIntegerPost(const ::test_namespace::OptionalParam &body = ::test_namespace::OptionalParam());
/**
* @param[in] body double [optional]
*/
- void primitivesNumberPut(const ::test_namespace::OptionalParam &body = ::test_namespace::OptionalParam());
+ virtual void primitivesNumberPut(const ::test_namespace::OptionalParam &body = ::test_namespace::OptionalParam());
private:
diff --git a/samples/client/petstore/cpp-qt/client/PFXStoreApi.h b/samples/client/petstore/cpp-qt/client/PFXStoreApi.h
index 0966e3f00d6..d401bdfa337 100644
--- a/samples/client/petstore/cpp-qt/client/PFXStoreApi.h
+++ b/samples/client/petstore/cpp-qt/client/PFXStoreApi.h
@@ -60,20 +60,20 @@ public:
/**
* @param[in] order_id QString [required]
*/
- void deleteOrder(const QString &order_id);
+ virtual void deleteOrder(const QString &order_id);
- void getInventory();
+ virtual void getInventory();
/**
* @param[in] order_id qint64 [required]
*/
- void getOrderById(const qint64 &order_id);
+ virtual void getOrderById(const qint64 &order_id);
/**
* @param[in] pfx_order PFXOrder [required]
*/
- void placeOrder(const PFXOrder &pfx_order);
+ virtual void placeOrder(const PFXOrder &pfx_order);
private:
diff --git a/samples/client/petstore/cpp-qt/client/PFXUserApi.h b/samples/client/petstore/cpp-qt/client/PFXUserApi.h
index 29bfe715971..3344f95783a 100644
--- a/samples/client/petstore/cpp-qt/client/PFXUserApi.h
+++ b/samples/client/petstore/cpp-qt/client/PFXUserApi.h
@@ -59,42 +59,42 @@ public:
/**
* @param[in] pfx_user PFXUser [required]
*/
- void createUser(const PFXUser &pfx_user);
+ virtual void createUser(const PFXUser &pfx_user);
/**
* @param[in] pfx_user QList [required]
*/
- void createUsersWithArrayInput(const QList &pfx_user);
+ virtual void createUsersWithArrayInput(const QList &pfx_user);
/**
* @param[in] pfx_user QList [required]
*/
- void createUsersWithListInput(const QList &pfx_user);
+ virtual void createUsersWithListInput(const QList &pfx_user);
/**
* @param[in] username QString [required]
*/
- void deleteUser(const QString &username);
+ virtual void deleteUser(const QString &username);
/**
* @param[in] username QString [required]
*/
- void getUserByName(const QString &username);
+ virtual void getUserByName(const QString &username);
/**
* @param[in] username QString [required]
* @param[in] password QString [required]
*/
- void loginUser(const QString &username, const QString &password);
+ virtual void loginUser(const QString &username, const QString &password);
- void logoutUser();
+ virtual void logoutUser();
/**
* @param[in] username QString [required]
* @param[in] pfx_user PFXUser [required]
*/
- void updateUser(const QString &username, const PFXUser &pfx_user);
+ virtual void updateUser(const QString &username, const PFXUser &pfx_user);
private: