Skip to content
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.
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
@@ -1 +1 @@
3.0.0-SNAPSHOT
3.0.1-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,14 @@ public Map<String, Object> postProcessOperations(Map<String, Object> objs) {

//TODO: This changes the info about the real type but it is needed to parse the header params
if (param.isHeaderParam) {
param.dataType = "Optional<Net::Http::Header::Raw>";
param.baseType = "Optional<Net::Http::Header::Raw>";
param.dataType = "Pistache::Optional<Pistache::Http::Header::Raw>";
param.baseType = "Pistache::Optional<Pistache::Http::Header::Raw>";
} else if (param.isQueryParam) {
if (param.isPrimitiveType) {
param.dataType = "Optional<" + param.dataType + ">";
param.dataType = "Pistache::Optional<" + param.dataType + ">";
} else {
param.dataType = "Optional<" + param.baseType + ">";
param.baseType = "Optional<" + param.baseType + ">";
param.dataType = "Pistache::Optional<" + param.baseType + ">";
param.baseType = "Pistache::Optional<" + param.baseType + ">";
}
}
}
Expand Down Expand Up @@ -299,7 +299,7 @@ public String getTypeDeclaration(Schema p) {
return toModelName(openAPIType);
}

return "std::shared_ptr<" + openAPIType + ">";
return openAPIType;
}

@Override
Expand All @@ -326,30 +326,14 @@ public String toDefaultValue(Schema p) {
} else if (ModelUtils.isArraySchema(p)) {
ArraySchema ap = (ArraySchema) p;
String inner = getSchemaType(ap.getItems());
if (!languageSpecificPrimitives.contains(inner)) {
inner = "std::shared_ptr<" + inner + ">";
}
return "std::vector<" + inner + ">()";
} else if (!StringUtils.isEmpty(p.get$ref())) { // model
return "new " + toModelName(ModelUtils.getSimpleRef(p.get$ref())) + "()";
return toModelName(ModelUtils.getSimpleRef(p.get$ref())) + "()";
} else if (ModelUtils.isStringSchema(p)) {
return "\"\"";
}

return "nullptr";
}

@Override
public void postProcessParameter(CodegenParameter parameter) {
super.postProcessParameter(parameter);

boolean isPrimitiveType = parameter.isPrimitiveType == Boolean.TRUE;
boolean isListContainer = parameter.isListContainer == Boolean.TRUE;
boolean isString = parameter.isString == Boolean.TRUE;

if (!isPrimitiveType && !isListContainer && !isString && !parameter.dataType.startsWith("std::shared_ptr")) {
parameter.dataType = "std::shared_ptr<" + parameter.dataType + ">";
}
return "";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <pistache/router.h>
#include <pistache/http_headers.h>

#include <pistache/optional.h>

{{#imports}}{{{import}}}
{{/imports}}

Expand Down Expand Up @@ -41,7 +43,7 @@ private:
{{/operation}}
void {{classnameSnakeLowerCase}}_default_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);

std::shared_ptr<Pistache::Http::Endpoint> httpEndpoint;
Pistache::Http::Endpoint httpEndpoint;
Pistache::Rest::Router router;

{{#operation}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#include <{{classname}}.h>

#include <pistache/optional.h>

{{#imports}}{{{import}}}
{{/imports}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ namespace {{this}} {
using namespace {{modelNamespace}};

{{classname}}::{{classname}}(Pistache::Address addr)
: httpEndpoint(std::make_shared<Pistache::Http::Endpoint>(addr))
: httpEndpoint(addr)
{ };

void {{classname}}::init(size_t thr = 2) {
auto opts = Pistache::Http::Endpoint::options()
.threads(thr)
.flags(Pistache::Tcp::Options::InstallSignalHandler);
httpEndpoint->init(opts);
httpEndpoint.init(opts);
setupRoutes();
}

void {{classname}}::start() {
httpEndpoint->setHandler(router.handler());
httpEndpoint->serve();
httpEndpoint.setHandler(router.handler());
httpEndpoint.serve();
}

void {{classname}}::shutdown() {
httpEndpoint->shutdown();
httpEndpoint.shutdown();
}

void {{classname}}::setupRoutes() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public:
/// </summary>
{{^isNotContainer}}{{{dataType}}}& {{getter}}();
{{/isNotContainer}}{{#isNotContainer}}{{{dataType}}} {{getter}}() const;
void {{setter}}({{{dataType}}} value);
void {{setter}}({{{dataType}}} const{{^isPrimitiveType}}&{{/isPrimitiveType}} value);
{{/isNotContainer}}{{^required}}bool {{nameInCamelCase}}IsSet() const;
void unset{{name}}();
{{/required}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void {{classname}}::fromJson(nlohmann::json& val)
else
{
{{{items.datatype}}} newItem({{{items.defaultValue}}});
newItem->fromJson(item);
newItem.fromJson(item);
m_{{name}}.push_back( newItem );
}
{{/items.isDateTime}}{{/items.isString}}{{/isPrimitiveType}}
Expand All @@ -100,7 +100,7 @@ void {{classname}}::fromJson(nlohmann::json& val)
{{/isDateTime}}{{^isDateTime}}if(!val["{{baseName}}"].is_null())
{
{{{dataType}}} newItem({{{defaultValue}}});
newItem->fromJson(val["{{baseName}}"]);
newItem.fromJson(val["{{baseName}}"]);
{{setter}}( newItem );
}
{{/isDateTime}}{{/isString}}
Expand All @@ -119,7 +119,7 @@ void {{classname}}::fromJson(nlohmann::json& val)
{
return m_{{name}};
}
void {{classname}}::{{setter}}({{{dataType}}} value)
void {{classname}}::{{setter}}({{{dataType}}} const{{^isPrimitiveType}}&{{/isPrimitiveType}} value)
{
m_{{name}} = value;
{{^required}}m_{{name}}IsSet = true;{{/required}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public:
virtual nlohmann::json toJson() const = 0;
virtual void fromJson(nlohmann::json& json) = 0;

static std::string toJson( const std::string& value );
static std::string toJson( const std::time_t& value );
static int32_t toJson( int32_t value );
static int64_t toJson( int64_t value );
static double toJson( double value );
static bool toJson( bool value );
static nlohmann::json toJson( std::shared_ptr<ModelBase> content );
static std::string toJson( std::string const& value );
static std::string toJson( std::time_t const& value );
static int32_t toJson( int32_t const value );
static int64_t toJson( int64_t const value );
static double toJson( double const value );
static bool toJson( bool const value );
static nlohmann::json toJson(ModelBase const& content );

};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,41 @@ ModelBase::~ModelBase()
{
}

std::string ModelBase::toJson( const std::string& value )
std::string ModelBase::toJson( std::string const& value )
{
return value;
}

std::string ModelBase::toJson( const std::time_t& value )
std::string ModelBase::toJson( std::time_t const& value )
{
char buf[sizeof "2011-10-08T07:07:09Z"];
strftime(buf, sizeof buf, "%FT%TZ", gmtime(&value));
return buf;
}

int32_t ModelBase::toJson( int32_t value )
int32_t ModelBase::toJson( int32_t const value )
{
return value;
}

int64_t ModelBase::toJson( int64_t value )
int64_t ModelBase::toJson( int64_t const value )
{
return value;
}

double ModelBase::toJson( double value )
double ModelBase::toJson( double const value )
{
return value;
}

bool ModelBase::toJson( bool value )
bool ModelBase::toJson( bool const value )
{
return value;
}

nlohmann::json ModelBase::toJson( std::shared_ptr<ModelBase> content )
nlohmann::json ModelBase::toJson(ModelBase content )
{
return content.get() ? content->toJson() : nlohmann::json();
return content.toJson();
}

{{#modelNamespaceDeclarations}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.0-SNAPSHOT
3.0.2-SNAPSHOT
10 changes: 5 additions & 5 deletions samples/server/petstore/cpp-pistache/api/PetApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@ namespace api {
using namespace org::openapitools::server::model;

PetApi::PetApi(Pistache::Address addr)
: httpEndpoint(std::make_shared<Pistache::Http::Endpoint>(addr))
: httpEndpoint(addr)
{ };

void PetApi::init(size_t thr = 2) {
auto opts = Pistache::Http::Endpoint::options()
.threads(thr)
.flags(Pistache::Tcp::Options::InstallSignalHandler);
httpEndpoint->init(opts);
httpEndpoint.init(opts);
setupRoutes();
}

void PetApi::start() {
httpEndpoint->setHandler(router.handler());
httpEndpoint->serve();
httpEndpoint.setHandler(router.handler());
httpEndpoint.serve();
}

void PetApi::shutdown() {
httpEndpoint->shutdown();
httpEndpoint.shutdown();
}

void PetApi::setupRoutes() {
Expand Down
10 changes: 6 additions & 4 deletions samples/server/petstore/cpp-pistache/api/PetApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <pistache/router.h>
#include <pistache/http_headers.h>

#include <pistache/optional.h>

#include "ApiResponse.h"
#include "Pet.h"
#include <string>
Expand Down Expand Up @@ -58,7 +60,7 @@ class PetApi {
void upload_file_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
void pet_api_default_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);

std::shared_ptr<Pistache::Http::Endpoint> httpEndpoint;
Pistache::Http::Endpoint httpEndpoint;
Pistache::Rest::Router router;


Expand All @@ -79,7 +81,7 @@ class PetApi {
/// </remarks>
/// <param name="petId">Pet id to delete</param>
/// <param name="apiKey"> (optional)</param>
virtual void delete_pet(const int64_t &petId, const Optional<Net::Http::Header::Raw> &apiKey, Pistache::Http::ResponseWriter &response) = 0;
virtual void delete_pet(const int64_t &petId, const Pistache::Optional<Pistache::Http::Header::Raw> &apiKey, Pistache::Http::ResponseWriter &response) = 0;

/// <summary>
/// Finds Pets by status
Expand All @@ -88,7 +90,7 @@ class PetApi {
/// Multiple status values can be provided with comma separated strings
/// </remarks>
/// <param name="status">Status values that need to be considered for filter</param>
virtual void find_pets_by_status(const Optional<std::string> &status, Pistache::Http::ResponseWriter &response) = 0;
virtual void find_pets_by_status(const Pistache::Optional<std::string> &status, Pistache::Http::ResponseWriter &response) = 0;

/// <summary>
/// Finds Pets by tags
Expand All @@ -97,7 +99,7 @@ class PetApi {
/// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
/// </remarks>
/// <param name="tags">Tags to filter by</param>
virtual void find_pets_by_tags(const Optional<std::string> &tags, Pistache::Http::ResponseWriter &response) = 0;
virtual void find_pets_by_tags(const Pistache::Optional<std::string> &tags, Pistache::Http::ResponseWriter &response) = 0;

/// <summary>
/// Find pet by ID
Expand Down
10 changes: 5 additions & 5 deletions samples/server/petstore/cpp-pistache/api/StoreApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@ namespace api {
using namespace org::openapitools::server::model;

StoreApi::StoreApi(Pistache::Address addr)
: httpEndpoint(std::make_shared<Pistache::Http::Endpoint>(addr))
: httpEndpoint(addr)
{ };

void StoreApi::init(size_t thr = 2) {
auto opts = Pistache::Http::Endpoint::options()
.threads(thr)
.flags(Pistache::Tcp::Options::InstallSignalHandler);
httpEndpoint->init(opts);
httpEndpoint.init(opts);
setupRoutes();
}

void StoreApi::start() {
httpEndpoint->setHandler(router.handler());
httpEndpoint->serve();
httpEndpoint.setHandler(router.handler());
httpEndpoint.serve();
}

void StoreApi::shutdown() {
httpEndpoint->shutdown();
httpEndpoint.shutdown();
}

void StoreApi::setupRoutes() {
Expand Down
4 changes: 3 additions & 1 deletion samples/server/petstore/cpp-pistache/api/StoreApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <pistache/router.h>
#include <pistache/http_headers.h>

#include <pistache/optional.h>

#include "Order.h"
#include <map>
#include <string>
Expand Down Expand Up @@ -54,7 +56,7 @@ class StoreApi {
void place_order_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
void store_api_default_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);

std::shared_ptr<Pistache::Http::Endpoint> httpEndpoint;
Pistache::Http::Endpoint httpEndpoint;
Pistache::Rest::Router router;


Expand Down
10 changes: 5 additions & 5 deletions samples/server/petstore/cpp-pistache/api/UserApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@ namespace api {
using namespace org::openapitools::server::model;

UserApi::UserApi(Pistache::Address addr)
: httpEndpoint(std::make_shared<Pistache::Http::Endpoint>(addr))
: httpEndpoint(addr)
{ };

void UserApi::init(size_t thr = 2) {
auto opts = Pistache::Http::Endpoint::options()
.threads(thr)
.flags(Pistache::Tcp::Options::InstallSignalHandler);
httpEndpoint->init(opts);
httpEndpoint.init(opts);
setupRoutes();
}

void UserApi::start() {
httpEndpoint->setHandler(router.handler());
httpEndpoint->serve();
httpEndpoint.setHandler(router.handler());
httpEndpoint.serve();
}

void UserApi::shutdown() {
httpEndpoint->shutdown();
httpEndpoint.shutdown();
}

void UserApi::setupRoutes() {
Expand Down
Loading