Skip to content

Commit

Permalink
[cpp-qt-client] New makeOperationsVirtual option (#19613)
Browse files Browse the repository at this point in the history
* Implementation of new `makeOperationsVirtual` option

* Make new parameter `true` by default

* Fix default value set and regenerate samples
  • Loading branch information
limentas authored Sep 23, 2024
1 parent 78f2f70 commit 7d8eacc
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 47 deletions.
1 change: 1 addition & 0 deletions docs/generators/cpp-qt-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.|<dl><dt>**false**</dt><dd>No changes to the enum's are made, this is the default option.</dd><dt>**true**</dt><dd>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.</dd></dl>|false|
|legacyDiscriminatorBehavior|Set to false for generators with better support for discriminators. (Python, Java, Go, PowerShell, C# have this enabled by default).|<dl><dt>**true**</dt><dd>The mapping in the discriminator includes descendent schemas that allOf inherit from self and the discriminator mapping schemas in the OAS document.</dd><dt>**false**</dt><dd>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.</dd></dl>|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|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,16 @@
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();
Expand Down Expand Up @@ -100,6 +105,7 @@ public CppQtClientCodegen() {
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"));
Expand Down Expand Up @@ -140,6 +146,12 @@ public void processOpts() {
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")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,50 +62,50 @@ class PFXPetApi : public QObject {
/**
* @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<QString> &api_key = ::test_namespace::OptionalParam<QString>());
virtual void deletePet(const qint64 &pet_id, const ::test_namespace::OptionalParam<QString> &api_key = ::test_namespace::OptionalParam<QString>());

/**
* @param[in] status QList<QString> [required]
*/
void findPetsByStatus(const QList<QString> &status);
virtual void findPetsByStatus(const QList<QString> &status);

/**
* @param[in] tags QList<QString> [required]
*/
Q_DECL_DEPRECATED void findPetsByTags(const QList<QString> &tags);
Q_DECL_DEPRECATED virtual void findPetsByTags(const QList<QString> &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<QString> &name = ::test_namespace::OptionalParam<QString>(), const ::test_namespace::OptionalParam<QString> &status = ::test_namespace::OptionalParam<QString>());
virtual void updatePetWithForm(const qint64 &pet_id, const ::test_namespace::OptionalParam<QString> &name = ::test_namespace::OptionalParam<QString>(), const ::test_namespace::OptionalParam<QString> &status = ::test_namespace::OptionalParam<QString>());

/**
* @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<QString> &additional_metadata = ::test_namespace::OptionalParam<QString>(), const ::test_namespace::OptionalParam<PFXHttpFileElement> &file = ::test_namespace::OptionalParam<PFXHttpFileElement>());
virtual void uploadFile(const qint64 &pet_id, const ::test_namespace::OptionalParam<QString> &additional_metadata = ::test_namespace::OptionalParam<QString>(), const ::test_namespace::OptionalParam<PFXHttpFileElement> &file = ::test_namespace::OptionalParam<PFXHttpFileElement>());


private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ class PFXPrimitivesApi : public QObject {
/**
* @param[in] body qint32 [optional]
*/
void primitivesIntegerPost(const ::test_namespace::OptionalParam<qint32> &body = ::test_namespace::OptionalParam<qint32>());
virtual void primitivesIntegerPost(const ::test_namespace::OptionalParam<qint32> &body = ::test_namespace::OptionalParam<qint32>());

/**
* @param[in] body double [optional]
*/
void primitivesNumberPut(const ::test_namespace::OptionalParam<double> &body = ::test_namespace::OptionalParam<double>());
virtual void primitivesNumberPut(const ::test_namespace::OptionalParam<double> &body = ::test_namespace::OptionalParam<double>());


private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,20 @@ class PFXStoreApi : public QObject {
/**
* @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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,42 +59,42 @@ class PFXUserApi : public QObject {
/**
* @param[in] pfx_user PFXUser [required]
*/
void createUser(const PFXUser &pfx_user);
virtual void createUser(const PFXUser &pfx_user);

/**
* @param[in] pfx_user QList<PFXUser> [required]
*/
void createUsersWithArrayInput(const QList<PFXUser> &pfx_user);
virtual void createUsersWithArrayInput(const QList<PFXUser> &pfx_user);

/**
* @param[in] pfx_user QList<PFXUser> [required]
*/
void createUsersWithListInput(const QList<PFXUser> &pfx_user);
virtual void createUsersWithListInput(const QList<PFXUser> &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:
Expand Down
18 changes: 9 additions & 9 deletions samples/client/petstore/cpp-qt/client/PFXPetApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,50 +62,50 @@ class PFXPetApi : public QObject {
/**
* @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<QString> &api_key = ::test_namespace::OptionalParam<QString>());
virtual void deletePet(const qint64 &pet_id, const ::test_namespace::OptionalParam<QString> &api_key = ::test_namespace::OptionalParam<QString>());

/**
* @param[in] status QList<QString> [required]
*/
void findPetsByStatus(const QList<QString> &status);
virtual void findPetsByStatus(const QList<QString> &status);

/**
* @param[in] tags QList<QString> [required]
*/
Q_DECL_DEPRECATED void findPetsByTags(const QList<QString> &tags);
Q_DECL_DEPRECATED virtual void findPetsByTags(const QList<QString> &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<QString> &name = ::test_namespace::OptionalParam<QString>(), const ::test_namespace::OptionalParam<QString> &status = ::test_namespace::OptionalParam<QString>());
virtual void updatePetWithForm(const qint64 &pet_id, const ::test_namespace::OptionalParam<QString> &name = ::test_namespace::OptionalParam<QString>(), const ::test_namespace::OptionalParam<QString> &status = ::test_namespace::OptionalParam<QString>());

/**
* @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<QString> &additional_metadata = ::test_namespace::OptionalParam<QString>(), const ::test_namespace::OptionalParam<PFXHttpFileElement> &file = ::test_namespace::OptionalParam<PFXHttpFileElement>());
virtual void uploadFile(const qint64 &pet_id, const ::test_namespace::OptionalParam<QString> &additional_metadata = ::test_namespace::OptionalParam<QString>(), const ::test_namespace::OptionalParam<PFXHttpFileElement> &file = ::test_namespace::OptionalParam<PFXHttpFileElement>());


private:
Expand Down
4 changes: 2 additions & 2 deletions samples/client/petstore/cpp-qt/client/PFXPrimitivesApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ class PFXPrimitivesApi : public QObject {
/**
* @param[in] body qint32 [optional]
*/
void primitivesIntegerPost(const ::test_namespace::OptionalParam<qint32> &body = ::test_namespace::OptionalParam<qint32>());
virtual void primitivesIntegerPost(const ::test_namespace::OptionalParam<qint32> &body = ::test_namespace::OptionalParam<qint32>());

/**
* @param[in] body double [optional]
*/
void primitivesNumberPut(const ::test_namespace::OptionalParam<double> &body = ::test_namespace::OptionalParam<double>());
virtual void primitivesNumberPut(const ::test_namespace::OptionalParam<double> &body = ::test_namespace::OptionalParam<double>());


private:
Expand Down
8 changes: 4 additions & 4 deletions samples/client/petstore/cpp-qt/client/PFXStoreApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,20 @@ class PFXStoreApi : public QObject {
/**
* @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:
Expand Down
16 changes: 8 additions & 8 deletions samples/client/petstore/cpp-qt/client/PFXUserApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,42 +59,42 @@ class PFXUserApi : public QObject {
/**
* @param[in] pfx_user PFXUser [required]
*/
void createUser(const PFXUser &pfx_user);
virtual void createUser(const PFXUser &pfx_user);

/**
* @param[in] pfx_user QList<PFXUser> [required]
*/
void createUsersWithArrayInput(const QList<PFXUser> &pfx_user);
virtual void createUsersWithArrayInput(const QList<PFXUser> &pfx_user);

/**
* @param[in] pfx_user QList<PFXUser> [required]
*/
void createUsersWithListInput(const QList<PFXUser> &pfx_user);
virtual void createUsersWithListInput(const QList<PFXUser> &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:
Expand Down

0 comments on commit 7d8eacc

Please sign in to comment.