Skip to content
New issue

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

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

Already on GitHub? # to your account

[cpp-restsdk] Generate mockable APIs #595

Merged
merged 9 commits into from
Jul 24, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {

public static final String DECLSPEC = "declspec";
public static final String DEFAULT_INCLUDE = "defaultInclude";
public static final String GENERATE_GMOCKS_FOR_APIS = "generateGMocksForApis";

protected String packageVersion = "1.0.0";
protected String declspec = "";
Expand Down Expand Up @@ -114,6 +115,9 @@ public CppRestSdkClientCodegen() {
addOption(DEFAULT_INCLUDE,
"The default include statement that should be placed in all headers for including things like the declspec (convention: #include \"Commons.h\" ",
this.defaultInclude);
addOption(GENERATE_GMOCKS_FOR_APIS,
"Generate Google Mock classes for APIs.",
null);

supportingFiles.add(new SupportingFile("modelbase-header.mustache", "", "ModelBase.h"));
supportingFiles.add(new SupportingFile("modelbase-source.mustache", "", "ModelBase.cpp"));
Expand Down Expand Up @@ -176,6 +180,11 @@ public void processOpts() {
defaultInclude = additionalProperties.get(DEFAULT_INCLUDE).toString();
}

if (convertPropertyToBoolean(GENERATE_GMOCKS_FOR_APIS)) {
apiTemplateFiles.put("api-gmock.mustache", "GMock.h");
additionalProperties.put("gmockApis", "true");
}

additionalProperties.put("modelNamespaceDeclarations", modelPackage.split("\\."));
additionalProperties.put("modelNamespace", modelPackage.replaceAll("\\.", "::"));
additionalProperties.put("modelHeaderGuardPrefix", modelPackage.replaceAll("\\.", "_").toUpperCase());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{{>licenseInfo}}
{{#operations}}
#ifndef {{apiHeaderGuardPrefix}}_{{classname}}GMock_H_
#define {{apiHeaderGuardPrefix}}_{{classname}}GMock_H_

#include <gmock/gmock.h>

#include "{{classname}}.h"

{{#apiNamespaceDeclarations}}
namespace {{this}} {
{{/apiNamespaceDeclarations}}

using namespace {{modelNamespace}};


class {{declspec}} {{classname}}Mock {{#gmockApis}} : public I{{classname}} {{/gmockApis}}
{
public:
{{#operation}}
MOCK_METHOD{{allParams.size}}( {{operationId}}, pplx::task<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}> (
{{#allParams}}
{{^required}}boost::optional<{{/required}}{{#isFile}}std::shared_ptr<{{/isFile}}{{{dataType}}}{{#isFile}}>{{/isFile}}{{^required}}>{{/required}} {{paramName}}{{#hasMore}},{{/hasMore}}
{{/allParams}}
) );
{{/operation}}
};

{{#apiNamespaceDeclarations}}
}
{{/apiNamespaceDeclarations}}

#endif /* {{apiHeaderGuardPrefix}}_{{classname}}GMock_H_ */

{{/operations}}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,36 @@ namespace {{this}} {

using namespace {{modelNamespace}};

class {{declspec}} {{classname}}
{{#gmockApis}}
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:
virtual ~I{{classname}}() = default;
{{#operation}}
virtual pplx::task<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}> {{operationId}}(
{{#allParams}}
{{^required}}boost::optional<{{/required}}{{#isFile}}std::shared_ptr<{{/isFile}}{{{dataType}}}{{#isFile}}>{{/isFile}}{{^required}}>{{/required}} {{paramName}}{{#hasMore}},{{/hasMore}}
{{/allParams}}
) = 0;
{{/operation}}
};{{/gmockApis}}

class {{declspec}} {{classname}} {{#gmockApis}} : public I{{classname}} {{/gmockApis}}
{
public:
{{#gmockApis}}
using Base = I{{classname}};
{{/gmockApis}}

{{classname}}( std::shared_ptr<ApiClient> apiClient );

{{#gmockApis}}
~{{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

{{/gmockApis}}
{{^gmockApis}}
virtual ~{{classname}}();
{{/gmockApis}}

{{#operation}}
/// <summary>
/// {{summary}}
Expand All @@ -41,7 +66,7 @@ public:
{{#allParams}}
{{^required}}boost::optional<{{/required}}{{#isFile}}std::shared_ptr<{{/isFile}}{{{dataType}}}{{#isFile}}>{{/isFile}}{{^required}}>{{/required}} {{paramName}}{{#hasMore}},{{/hasMore}}
{{/allParams}}
);
){{#gmockApis}} override{{/gmockApis}};
{{/operation}}

protected:
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.0-SNAPSHOT
3.1.1-SNAPSHOT
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ApiClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ApiClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ApiConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ApiConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ApiException.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ApiException.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/HttpContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/HttpContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/IHttpBody.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/JsonBody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/JsonBody.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ModelBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ModelBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/MultipartFormData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
4 changes: 2 additions & 2 deletions samples/client/petstore/cpp-restsdk/MultipartFormData.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

/*
* MultipartFormData.h
*
* This class represents a container for building a application/x-multipart-formdata requests.
* This class represents a container for building application/x-multipart-formdata requests.
*/

#ifndef ORG_OPENAPITOOLS_CLIENT_MODEL_MultipartFormData_H_
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/api/PetApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
9 changes: 7 additions & 2 deletions samples/client/petstore/cpp-restsdk/api/PetApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down Expand Up @@ -35,11 +35,16 @@ namespace api {

using namespace org::openapitools::client::model;

class PetApi


class PetApi
{
public:

PetApi( std::shared_ptr<ApiClient> apiClient );

virtual ~PetApi();

/// <summary>
/// Add a new pet to the store
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/api/StoreApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
9 changes: 7 additions & 2 deletions samples/client/petstore/cpp-restsdk/api/StoreApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down Expand Up @@ -34,11 +34,16 @@ namespace api {

using namespace org::openapitools::client::model;

class StoreApi


class StoreApi
{
public:

StoreApi( std::shared_ptr<ApiClient> apiClient );

virtual ~StoreApi();

/// <summary>
/// Delete purchase order by ID
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/api/UserApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
9 changes: 7 additions & 2 deletions samples/client/petstore/cpp-restsdk/api/UserApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down Expand Up @@ -34,11 +34,16 @@ namespace api {

using namespace org::openapitools::client::model;

class UserApi


class UserApi
{
public:

UserApi( std::shared_ptr<ApiClient> apiClient );

virtual ~UserApi();

/// <summary>
/// Create user
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/model/ApiResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
Loading