Skip to content

Commit

Permalink
Implementation of new makeOperationsVirtual option
Browse files Browse the repository at this point in the history
  • Loading branch information
limentas committed Sep 18, 2024
1 parent 34aeb16 commit dab92a0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
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.| |false|
|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,15 @@
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_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 = false;

public CppQtClientCodegen() {
super();
Expand Down Expand Up @@ -100,6 +104,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("makeOperationsVirtual", 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
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

0 comments on commit dab92a0

Please sign in to comment.