Skip to content

Commit

Permalink
Update CPPREST client with OAS2 (#128)
Browse files Browse the repository at this point in the history
* restore cpprest from codegen 2x

* fix cpprest by modifying the template

* better naming for array of models

* updtae cpprest samples with oas2
  • Loading branch information
wing328 committed Apr 18, 2018
1 parent 05f5c57 commit 52af29f
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3595,7 +3595,7 @@ public void setParameterBooleanFlagWithCodegenProperty(CodegenParameter paramete
parameter.isByteArray = true;
parameter.isPrimitiveType = true;
} else if (Boolean.TRUE.equals(property.isBinary)) {
parameter.isByteArray = true;
parameter.isBinary = true;
parameter.isPrimitiveType = true;
} else if (Boolean.TRUE.equals(property.isString)) {
parameter.isString = true;
Expand Down Expand Up @@ -4171,7 +4171,7 @@ public CodegenParameter fromRequestBody(RequestBody body, Map<String, Schema> sc
codegenParameter.baseName = codegenModel.classname;
codegenParameter.paramName = toParamName(codegenModel.classname);
codegenParameter.baseType = codegenModel.classname;
codegenParameter.dataType = codegenModel.classname;
codegenParameter.dataType = getTypeDeclaration(codegenModel.classname);
codegenParameter.description = codegenModel.description;
imports.add(codegenParameter.baseType);
} else {
Expand Down Expand Up @@ -4209,14 +4209,18 @@ public CodegenParameter fromRequestBody(RequestBody body, Map<String, Schema> sc
CodegenProperty codegenProperty = fromProperty("property", schema);
imports.add(codegenProperty.baseType);
CodegenProperty innerCp = codegenProperty;
CodegenProperty mostInnerItem = innerCp;
// loop through multidimensional array to add proper import
// also find the most inner item
while (innerCp != null) {
if (innerCp.complexType != null) {
imports.add(innerCp.complexType);
}
mostInnerItem = innerCp;
innerCp = innerCp.items;
}
codegenParameter.baseName = codegenProperty.baseType;
codegenParameter.paramName = toParamName(codegenProperty.baseType);
codegenParameter.baseName = mostInnerItem.complexType;
codegenParameter.paramName = toParamName(mostInnerItem.complexType);
codegenParameter.items = codegenProperty.items;
codegenParameter.dataType = getTypeDeclaration(arraySchema);
codegenParameter.baseType = getSchemaType(arraySchema);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ using namespace {{modelNamespace}};
}

{{#operation}}
pplx::task<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}> {{classname}}::{{operationId}}({{#allParams}}{{^required}}boost::optional<{{/required}}{{{dataType}}}{{^required}}>{{/required}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}})
pplx::task<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}> {{classname}}::{{operationId}}({{#allParams}}{{^required}}boost::optional<{{/required}}{{#isFile}}std::shared_ptr<{{/isFile}}{{{dataType}}}{{#isFile}}>{{/isFile}}{{^required}}>{{/required}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}})
{
{{#allParams}}{{#required}}{{^isPrimitiveType}}{{^isContainer}}
// verify the required parameter '{{paramName}}' is set
Expand Down Expand Up @@ -118,7 +118,12 @@ pplx::task<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/r
{{/isContainer}}
{{/isPrimitiveType}}
{{#isPrimitiveType}}
{{#isFile}}
if ({{paramName}} && *{{paramName}} != nullptr)
{{/isFile}}
{{^isFile}}
if ({{paramName}})
{{/isFile}}
{{/isPrimitiveType}}
{{#isContainer}}
if ({{paramName}})
Expand Down
4 changes: 2 additions & 2 deletions samples/client/petstore/cpprest/api/PetApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ pplx::task<void> PetApi::updatePetWithForm(int64_t petId, boost::optional<utilit
return void();
});
}
pplx::task<std::shared_ptr<ApiResponse>> PetApi::uploadFile(int64_t petId, boost::optional<utility::string_t> additionalMetadata, boost::optional<HttpContent> file)
pplx::task<std::shared_ptr<ApiResponse>> PetApi::uploadFile(int64_t petId, boost::optional<utility::string_t> additionalMetadata, boost::optional<std::shared_ptr<HttpContent>> file)
{


Expand Down Expand Up @@ -903,7 +903,7 @@ pplx::task<std::shared_ptr<ApiResponse>> PetApi::uploadFile(int64_t petId, boost
{
formParams[ utility::conversions::to_string_t("additionalMetadata") ] = ApiClient::parameterToString(*additionalMetadata);
}
if (file)
if (file && *file != nullptr)
{
fileParams[ utility::conversions::to_string_t("file") ] = *file;
}
Expand Down
1 change: 0 additions & 1 deletion samples/client/petstore/cpprest/api/StoreApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@ pplx::task<std::shared_ptr<Order>> StoreApi::placeOrder(std::shared_ptr<Order> o
headerParams[utility::conversions::to_string_t("Accept")] = responseHttpContentType;

std::unordered_set<utility::string_t> consumeHttpContentTypes;
consumeHttpContentTypes.insert( utility::conversions::to_string_t("*/*") );


std::shared_ptr<IHttpBody> httpBody;
Expand Down
4 changes: 0 additions & 4 deletions samples/client/petstore/cpprest/api/UserApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ pplx::task<void> UserApi::createUser(std::shared_ptr<User> user)
headerParams[utility::conversions::to_string_t("Accept")] = responseHttpContentType;

std::unordered_set<utility::string_t> consumeHttpContentTypes;
consumeHttpContentTypes.insert( utility::conversions::to_string_t("*/*") );


std::shared_ptr<IHttpBody> httpBody;
Expand Down Expand Up @@ -191,7 +190,6 @@ pplx::task<void> UserApi::createUsersWithArrayInput(std::vector<std::shared_ptr<
headerParams[utility::conversions::to_string_t("Accept")] = responseHttpContentType;

std::unordered_set<utility::string_t> consumeHttpContentTypes;
consumeHttpContentTypes.insert( utility::conversions::to_string_t("*/*") );


std::shared_ptr<IHttpBody> httpBody;
Expand Down Expand Up @@ -312,7 +310,6 @@ pplx::task<void> UserApi::createUsersWithListInput(std::vector<std::shared_ptr<U
headerParams[utility::conversions::to_string_t("Accept")] = responseHttpContentType;

std::unordered_set<utility::string_t> consumeHttpContentTypes;
consumeHttpContentTypes.insert( utility::conversions::to_string_t("*/*") );


std::shared_ptr<IHttpBody> httpBody;
Expand Down Expand Up @@ -874,7 +871,6 @@ pplx::task<void> UserApi::updateUser(utility::string_t username, std::shared_ptr
headerParams[utility::conversions::to_string_t("Accept")] = responseHttpContentType;

std::unordered_set<utility::string_t> consumeHttpContentTypes;
consumeHttpContentTypes.insert( utility::conversions::to_string_t("*/*") );


std::shared_ptr<IHttpBody> httpBody;
Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore/cpprest/api/UserApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "../ApiClient.h"

#include "User.h"
#include <vector>
#include <cpprest/details/basic_types.h>

#include <boost/optional.hpp>
Expand Down

0 comments on commit 52af29f

Please sign in to comment.