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

[[BUG][C][cpp-restsdk] fix missing Set.h #18631

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions bin/configs/cpp-restsdk-client-everything.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
generatorName: cpp-restsdk
outputDir: samples/client/petstore/cpp-restsdk/client-everything
inputSpec: modules/openapi-generator/src/test/resources/3_0/issues-anytype-object-set-petstore-everything.yaml
templateDir: modules/openapi-generator/src/main/resources/cpp-rest-sdk-client
additionalProperties:
packageName: CppRestPetstoreClient
1 change: 1 addition & 0 deletions docs/generators/cpp-pistache-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
| ---------- | ------- |
|nlohmann::json|#include <nlohmann/json.hpp>|
|std::map|#include <map>|
|std::set|#include <set>|
|std::string|#include <string>|
|std::vector|#include <vector>|

Expand Down
1 change: 1 addition & 0 deletions docs/generators/cpp-restsdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|HttpContent|#include "HttpContent.h"|
|Object|#include "Object.h"|
|std::map|#include <map>|
|std::set|#include <set>|
|std::string|#include <string>|
|std::vector|#include <vector>|
|utility::datetime|#include <cpprest/details/basic_types.h>|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
/** std:map (for map) */
private static final String STD_MAP = "std::map";

/** std:vector (for array, set) */
/** std:set (for set) */
private static final String STD_SET = "std::set";

/** std:vector (for array) */
private static final String STD_VECTOR = "std::vector";

@Override
Expand Down Expand Up @@ -148,7 +151,7 @@ public CppPistacheServerCodegen() {
typeMapping.put("boolean", "bool");
typeMapping.put("array", STD_VECTOR);
typeMapping.put("map", STD_MAP);
typeMapping.put("set", STD_VECTOR);
typeMapping.put("set", STD_SET);
typeMapping.put("file", STD_STRING);
typeMapping.put("object", NLOHMANN_JSON);
typeMapping.put("binary", STD_STRING);
Expand All @@ -161,6 +164,7 @@ public CppPistacheServerCodegen() {
super.importMapping = new HashMap<>();
importMapping.put(STD_VECTOR, "#include <vector>");
importMapping.put(STD_MAP, "#include <map>");
importMapping.put(STD_SET, "#include <set>");
importMapping.put(STD_STRING, "#include <string>");
importMapping.put(NLOHMANN_JSON, "#include <nlohmann/json.hpp>");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.media.ArraySchema;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.responses.ApiResponse;
import io.swagger.v3.oas.models.servers.Server;
Expand Down Expand Up @@ -161,6 +160,7 @@ public CppRestSdkClientCodegen() {
typeMapping.put("long", "int64_t");
typeMapping.put("boolean", "bool");
typeMapping.put("array", "std::vector");
typeMapping.put("set", "std::set");
typeMapping.put("map", "std::map");
typeMapping.put("file", "HttpContent");
typeMapping.put("object", "Object");
Expand All @@ -173,6 +173,7 @@ public CppRestSdkClientCodegen() {
super.importMapping = new HashMap<>();
importMapping.put("std::vector", "#include <vector>");
importMapping.put("std::map", "#include <map>");
importMapping.put("std::set", "#include <set>");
importMapping.put("std::string", "#include <string>");
importMapping.put("HttpContent", "#include \"HttpContent.h\"");
importMapping.put("Object", "#include \"Object.h\"");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <sstream>
#include <vector>
#include <map>
#include <set>

namespace {{helpersNamespace}}
{
Expand Down Expand Up @@ -82,6 +83,15 @@ namespace {{helpersNamespace}}
return true;
}

/// <summary>
/// Determine if the given vector<T> only has unique elements. T must provide the == operator.
/// </summary>
template <typename T>
bool hasOnlyUniqueItems(const std::set<T>& set)
{
return true;
}

std::string toStringValue(const std::string &value);
std::string toStringValue(const int32_t value);
std::string toStringValue(const int64_t value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <cpprest/json.h>

#include <map>
#include <set>
#include <vector>

{{#modelNamespaceDeclarations}}
Expand Down Expand Up @@ -52,6 +53,8 @@ public:
static utility::string_t toString( const std::shared_ptr<T>& val );
template <typename T>
static utility::string_t toString( const std::vector<T> & val );
template <typename T>
static utility::string_t toString( const std::set<T> & val );

static web::json::value toJson( bool val );
static web::json::value toJson( float val );
Expand All @@ -68,6 +71,8 @@ public:
template<typename T>
static web::json::value toJson( const std::vector<T>& val );
template<typename T>
static web::json::value toJson( const std::set<T>& val );
template<typename T>
static web::json::value toJson( const std::map<utility::string_t, T>& val );

static bool fromString( const utility::string_t& val, bool & );
Expand All @@ -85,6 +90,8 @@ public:
template<typename T>
static bool fromString( const utility::string_t& val, std::vector<T> & );
template<typename T>
static bool fromString( const utility::string_t& val, std::set<T> & );
template<typename T>
static bool fromString( const utility::string_t& val, std::map<utility::string_t, T> & );

static bool fromJson( const web::json::value& val, bool & );
Expand All @@ -102,6 +109,8 @@ public:
template<typename T>
static bool fromJson( const web::json::value& val, std::vector<T> & );
template<typename T>
static bool fromJson( const web::json::value& val, std::set<T> & );
template<typename T>
static bool fromJson( const web::json::value& val, std::map<utility::string_t, T> & );


Expand All @@ -120,6 +129,8 @@ public:
template <typename T>
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const std::vector<T>& value, const utility::string_t& contentType = utility::conversions::to_string_t("") );
template <typename T>
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const std::set<T>& value, const utility::string_t& contentType = utility::conversions::to_string_t("") );
template <typename T>
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const std::map<utility::string_t, T>& value, const utility::string_t& contentType = utility::conversions::to_string_t("") );

static bool fromHttpContent( std::shared_ptr<HttpContent> val, bool & );
Expand All @@ -136,6 +147,8 @@ public:
template <typename T>
static bool fromHttpContent( std::shared_ptr<HttpContent> val, std::vector<T> & );
template <typename T>
static bool fromHttpContent( std::shared_ptr<HttpContent> val, std::set<T> & );
template <typename T>
static bool fromHttpContent( std::shared_ptr<HttpContent> val, std::map<utility::string_t, T> & );

static utility::string_t toBase64( utility::string_t value );
Expand All @@ -155,6 +168,8 @@ utility::string_t ModelBase::toString( const std::shared_ptr<T>& val )
}
return utility::string_t(ss.str());
}

// std::vector to string
template<typename T>
utility::string_t ModelBase::toString( const std::vector<T> & val )
{
Expand All @@ -169,6 +184,24 @@ utility::string_t ModelBase::toString( const std::vector<T> & val )
}
return strArray;
}

// std::set to string
template<typename T>
utility::string_t ModelBase::toString( const std::set<T> & val )
{
utility::string_t strArray;
for ( const auto &item : val )
{
strArray.append( toString(item) + "," );
}
if (val.count() > 0)
{
strArray.pop_back();
}
return strArray;
}


template<typename T>
web::json::value ModelBase::toJson( const std::shared_ptr<T>& val )
{
Expand All @@ -179,6 +212,8 @@ web::json::value ModelBase::toJson( const std::shared_ptr<T>& val )
}
return retVal;
}

// std::vector to json
template<typename T>
web::json::value ModelBase::toJson( const std::vector<T>& value )
{
Expand All @@ -189,6 +224,21 @@ web::json::value ModelBase::toJson( const std::vector<T>& value )
}
return web::json::value::array(ret);
}

// std::set to json
template<typename T>
web::json::value ModelBase::toJson( const std::set<T>& value )
{
// There's no protoype web::json::value::array(...) taking a std::set parameter. Converting to std::vector to get an array.
std::vector<web::json::value> ret;
for ( const auto& x : value )
{
ret.push_back( toJson(x) );
}
return web::json::value::array(ret);
}


template<typename T>
web::json::value ModelBase::toJson( const std::map<utility::string_t, T>& val )
{
Expand Down Expand Up @@ -279,6 +329,7 @@ std::shared_ptr<HttpContent> ModelBase::toHttpContent(const utility::string_t& n
}
return content;
}

template <typename T>
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const std::vector<T>& value, const utility::string_t& contentType )
{
Expand All @@ -290,6 +341,7 @@ std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t&
content->setData( std::shared_ptr<std::istream>( new std::stringstream( utility::conversions::to_utf8string(json_array.serialize()) ) ) );
return content;
}

template <typename T>
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const std::map<utility::string_t, T>& value, const utility::string_t& contentType )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,44 @@ components:
- available
- pending
- sold

certificates:
description: pedigree and other certificates
type: array
uniqueItems: true

items:
type: string

vaccinationBook:
description: Vaccination book of the pet
type: object

required:
- vaccines

properties:
vaccines:
type: array
uniqueItems: true

items:
title: vaccine
type: object

required:
- date
- boosterRequired

properties:
date:
format: date
description: vaccination date

boosterRequired:
type: boolean
description: true if a booster is still needed to complete the vaccination

xml:
name: Pet
ApiResponse:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -763,9 +763,9 @@ components:
- pending
- sold

# ---------------------------------------------------------
# Properties that dedicate this configuration to this issue
# ---------------------------------------------------------
# -----------------------------------------------------------------------
# Properties that dedicate this configuration to some issues or checkings
# -----------------------------------------------------------------------

# https://github.com/OpenAPITools/openapi-generator/issues/2769
# object property (leading to Object.h)
Expand All @@ -782,21 +782,44 @@ components:
description: to help you installing your pet at home

# Leading to Set.h
certificates:
description: pedigree and other certificates
type: array
uniqueItems: true

items:
type: string

# https://github.com/OpenAPITools/openapi-generator/issues/14234
bestFriends:
description: Pet best friends!
vaccinationBook:
description: Vaccination book of the pet
type: object

required:
- bestFriends
- vaccines

properties:
bestFriends:
vaccines:
type: array
uniqueItems: true

items:
type: string
title: vaccine
type: object

required:
- date
- boosterRequired

properties:
date:
format: date
description: vaccination date

boosterRequired:
type: boolean
description: true if a booster is still needed to complete the vaccination


xml:
name: Pet
Expand Down
29 changes: 29 additions & 0 deletions samples/client/petstore/cpp-restsdk/client-everything/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app