Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cpp-restsdk] Generate mockable APIs #595

Merged
merged 9 commits into from
Jul 24, 2018

Conversation

Peaches491
Copy link
Contributor

@Peaches491 Peaches491 commented Jul 18, 2018

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\.
  • Filed the PR against the correct branch: master, 3.1.x, 4.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

Port of NativeInstruments/swagger-codegen#9 to openapi-generator project.

Description of the original PR

We want to able to unit test our code that uses the generated API code.
In order to do that we need a virtual interface to mock away the
generated API code.

This PR introduces two new config options for the cpprest generator:

"generateInterfacesForApis" will generate an abstract base class
(interface) for all APIs.
"generateGMocksForApis" will additionally generate Google Mock classes
for the APIs. This config option of course implies the first one.
If the options are not set only minor white space changes will result
(see the changes in the petstore example).

@@ -22,11 +22,24 @@ namespace {{this}} {

using namespace {{modelNamespace}};

class {{declspec}} {{classname}}
class {{declspec}} I{{classname}}
Copy link
Contributor

@etherealjoy etherealjoy Jul 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this part should be encapsulated with the new mustache variable, so that current users are not impacted

{
public:
{{classname}}( std::shared_ptr<ApiClient> apiClient );
virtual ~{{classname}}();
~{{classname}}() override;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here as well

@@ -41,7 +54,7 @@ public:
{{#allParams}}
{{^required}}boost::optional<{{/required}}{{#isFile}}std::shared_ptr<{{/isFile}}{{{dataType}}}{{#isFile}}>{{/isFile}}{{^required}}>{{/required}} {{paramName}}{{#hasMore}},{{/hasMore}}
{{/allParams}}
);
) override;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here.

@Peaches491
Copy link
Contributor Author

@etherealjoy Addressed all your comments!

@wing328 wing328 added this to the 3.1.2 milestone Jul 24, 2018
@wing328 wing328 merged commit 5300651 into OpenAPITools:master Jul 24, 2018
@wing328
Copy link
Member

wing328 commented Jul 24, 2018

@Peaches491 thanks for the PR, which has been merged into master

@etherealjoy thanks for reviewing the change.

A-Joshi pushed a commit to ihsmarkitoss/openapi-generator that referenced this pull request Feb 27, 2019
* Port GMock feature from NativeInstruments

swagger-codegen fork:
NativeInstruments/swagger-codegen#9

* Update petstore for Mockable APIs

* Fix shared_ptr in templates for File params

* Add guards in templates for GMock APIs

* Regenerate samples without GMocks

* Add useful constructors for GMock APIs

* Add constructors to API header interface

* Update samples with explicit monadic constructors

* Add default implementations for destructors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants