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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm run ci
- run: npm run test
2 changes: 1 addition & 1 deletion lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -1812,7 +1812,7 @@ class Visitor {

visitIncludeModelFunc(ast, modelName, level) {
// empty method
this.emit(`virtual bool empty() const override { ${ast.nodes.map((node, index) => { return 'return this->' + _name(node.fieldName) + '_ == nullptr' + (index % 5 === 0 && index !== ast.nodes.length - 1 ? '\n ' : ''); }).join(' && ')}; };\n`, level);
this.emit(`virtual bool empty() const override { return ${ast.nodes.map((node, index) => { return 'this->' + _name(node.fieldName) + '_ == nullptr' + (index % 5 === 0 && index !== ast.nodes.length - 1 ? '\n ' : ''); }).join(' && ')}; };\n`, level);

for (let i = 0; i < ast.nodes.length; i++) {
const node = ast.nodes[i];
Expand Down
7 changes: 7 additions & 0 deletions tests/fixtures/alias/Darafile
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,12 @@
"author": "Alibaba",
"email": "[email protected]"
}
},
"cpp": {
"namespace": "Darabonba",
"header": "darabonba/test.hpp"
},
"releases": {
"cpp": "darabonba/test:1.0.0"
}
}
15 changes: 15 additions & 0 deletions tests/fixtures/alias/include/darabonba/test.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// This file is auto-generated, don't edit it. Thanks.
#ifndef DARABONBA_TEST_HPP_
#define DARABONBA_TEST_HPP_
#include <darabonba/Core.hpp>
using namespace std;
using json = nlohmann::json;
namespace Darabonba
{
class Client {
public:
Client() {}
static void emptyModel();
};
} // namespace Darabonba
#endif
27 changes: 27 additions & 0 deletions tests/fixtures/alias/src/Client.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <darabonba/Core.hpp>
#include <darabonba/test.hpp>
#include <darabonba/import.hpp>
#include <darabonba/srouce.hpp>
#include <darabonba/alias.hpp>
#include <darabonba/alias/source.hpp>
#include <darabonba/alias/symbol.hpp>
using namespace std;
using namespace Alias;
using json = nlohmann::json;
using ImportClient = Import::Client;
using SourceClient = Source::Client;
using namespace AliasSymbol::Models;
using AliasSymbolClient = AliasSymbol::Client;
using AliasSourceSourceClient = AliasSource::SourceClient;
namespace Darabonba
{

void Client::emptyModel() {
ImportClient::test();
SourceClient::test();
AliasClient::test();
AliasSourceSourceClient::test();
AliasSymbolClient::test();
TestModel model = TestModel();
}
} // namespace Darabonba
10 changes: 9 additions & 1 deletion tests/fixtures/annotation/Darafile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,13 @@
"scope": "darabonba",
"name": "main",
"version": "0.0.1",
"main": "./main.dara"
"main": "./main.dara",
"libraries": {},
"cpp": {
"namespace": "Darabonba",
"header": "darabonba/test.hpp"
},
"releases": {
"cpp": "darabonba/test:1.0.0"
}
}
49 changes: 49 additions & 0 deletions tests/fixtures/annotation/include/darabonba/models/Test.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// This file is auto-generated, don't edit it. Thanks.
#ifndef DARABONBA_MODELS_TEST_HPP_
#define DARABONBA_MODELS_TEST_HPP_
#include <darabonba/Core.hpp>
using namespace std;
using json = nlohmann::json;
namespace Darabonba
{
namespace Models
{
/**
TestModel
*/
class Test : public Darabonba::Model {
public:
friend void to_json(Darabonba::Json& j, const Test& obj) {
DARABONBA_PTR_TO_JSON(test, test_);
};
friend void from_json(const Darabonba::Json& j, Test& obj) {
DARABONBA_PTR_FROM_JSON(test, test_);
};
Test() = default ;
Test(const Test &) = default ;
Test(Test &&) = default ;
Test(const Darabonba::Json & obj) { from_json(obj, *this); };
virtual ~Test() = default ;
Test& operator=(const Test &) = default ;
Test& operator=(Test &&) = default ;
virtual void validate() const override {
DARABONBA_VALIDATE_REQUIRED(test_);
};
virtual void fromMap(const Darabonba::Json &obj) override { from_json(obj, *this); validate(); };
virtual Darabonba::Json toMap() const override { Darabonba::Json obj; to_json(obj, *this); return obj; };
virtual bool empty() const override { return this->test_ == nullptr; };
// test Field Functions
bool hasTest() const { return this->test_ != nullptr;};
void deleteTest() { this->test_ = nullptr;};
inline string test() const { DARABONBA_PTR_GET_DEFAULT(test_, "") };
inline Test& setTest(string test) { DARABONBA_PTR_SET_VALUE(test_, test) };


protected:
// Alichange app id
std::shared_ptr<string> test_ = nullptr;
};

} // namespace Models
} // namespace Darabonba
#endif
27 changes: 27 additions & 0 deletions tests/fixtures/annotation/include/darabonba/test.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// This file is auto-generated, don't edit it. Thanks.
#ifndef DARABONBA_TEST_HPP_
#define DARABONBA_TEST_HPP_
#include <darabonba/Core.hpp>
#include <darabonba/testModel.hpp>
using namespace std;
using json = nlohmann::json;
namespace Darabonba
{
class Client {
public:

/**
Init Func
*/
Client();

void testAPI();
/**
testFunc
*/
static void testFunc();
protected:
string _a;
};
} // namespace Darabonba
#endif
7 changes: 7 additions & 0 deletions tests/fixtures/annotation/include/darabonba/testModel.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// This file is auto-generated, don't edit it. Thanks.
#ifndef DARABONBA_TESTMODEL_HPP_
#define DARABONBA_TESTMODEL_HPP_
#include <darabonba/Core.hpp>
#include <darabonba/models/Test.hpp>

#endif
64 changes: 64 additions & 0 deletions tests/fixtures/annotation/src/Client.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include <darabonba/Core.hpp>
#include <darabonba/test.hpp>
#include <darabonba/policy/Retry.hpp>
#include <darabonba/Runtime.hpp>
#include <darabonba/Exception.hpp>
using namespace std;
using json = nlohmann::json;
namespace Darabonba
{

/**
Init Func
*/
Darabonba::Client::Client(){
}


void Client::testAPI() {
Darabonba::RuntimeOptions runtime_(json({
}));

shared_ptr<Darabonba::Http::Request> _lastRequest = nullptr;
shared_ptr<Darabonba::Http::MCurlResponse> _lastResponse = nullptr;
Darabonba::Exception _lastException;
int _retriesAttempted = 0;
Darabonba::Policy::RetryPolicyContext _context = json({
{"retriesAttempted" , _retriesAttempted}
});
while (Darabonba::allowRetry(runtime_.retryOptions(), _context)) {
if (_retriesAttempted > 0) {
int _backoffTime = Darabonba::getBackoffTime(runtime_.retryOptions(), _context);
if (_backoffTime > 0) {
Darabonba::sleep(_backoffTime);
}
}
_retriesAttempted++;
try {
Darabonba::Http::Request request_ = Darabonba::Http::Request();
_lastRequest = make_shared<Darabonba::Http::Request>(request_);
auto futureResp_ = Darabonba::Core::doAction(request_, runtime_);
shared_ptr<Darabonba::Http::MCurlResponse> response_ = futureResp_.get();
_lastResponse = response_;

return ;
} catch (const Darabonba::Exception& ex) {
_context = Darabonba::Policy::RetryPolicyContext(json({
{"retriesAttempted" , _retriesAttempted},
{"lastRequest" , _lastRequest},
{"lastResponse" , _lastResponse},
{"exception" , ex},
}));
continue;
}
}

throw *_context.exception();
}

/**
testFunc
*/
void Client::testFunc() {
}
} // namespace Darabonba
10 changes: 9 additions & 1 deletion tests/fixtures/api/Darafile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,13 @@
"scope": "alibabacloud",
"name": "main",
"version": "0.0.1",
"main": "./main.dara"
"main": "./main.dara",
"libraries": {},
"cpp": {
"namespace": "Darabonba",
"header": "darabonba/test.hpp"
},
"releases": {
"cpp": "darabonba/test:1.0.0"
}
}
19 changes: 19 additions & 0 deletions tests/fixtures/api/include/darabonba/test.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// This file is auto-generated, don't edit it. Thanks.
#ifndef DARABONBA_TEST_HPP_
#define DARABONBA_TEST_HPP_
#include <darabonba/Core.hpp>
using namespace std;
using json = nlohmann::json;
namespace Darabonba
{
class Client {
public:

Client();

void hello();

void helloRuntime();
};
} // namespace Darabonba
#endif
79 changes: 79 additions & 0 deletions tests/fixtures/api/src/Client.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#include <darabonba/Core.hpp>
#include <darabonba/test.hpp>
#include <map>
#include <darabonba/policy/Retry.hpp>
#include <darabonba/Runtime.hpp>
#include <darabonba/Exception.hpp>
using namespace std;
using json = nlohmann::json;
namespace Darabonba
{

Darabonba::Client::Client(){
}


void Client::hello() {
Darabonba::RuntimeOptions runtime_(json({}));

Darabonba::Http::Request request_ = Darabonba::Http::Request();
request_.setMethod("GET");
request_.setPathname("/");
request_.setHeaders(json({
{"host" , "www.test.com"},
{"Cookie" , "test"}
}).get<map<string, string>>());
auto futureResp_ = Darabonba::Core::doAction(request_, runtime_);
shared_ptr<Darabonba::Http::MCurlResponse> response_ = futureResp_.get();

return ;
}

void Client::helloRuntime() {
Darabonba::RuntimeOptions runtime_(json({
}));

shared_ptr<Darabonba::Http::Request> _lastRequest = nullptr;
shared_ptr<Darabonba::Http::MCurlResponse> _lastResponse = nullptr;
Darabonba::Exception _lastException;
int _retriesAttempted = 0;
Darabonba::Policy::RetryPolicyContext _context = json({
{"retriesAttempted" , _retriesAttempted}
});
while (Darabonba::allowRetry(runtime_.retryOptions(), _context)) {
if (_retriesAttempted > 0) {
int _backoffTime = Darabonba::getBackoffTime(runtime_.retryOptions(), _context);
if (_backoffTime > 0) {
Darabonba::sleep(_backoffTime);
}
}
_retriesAttempted++;
try {
Darabonba::Http::Request request_ = Darabonba::Http::Request();
request_.setMethod("GET");
request_.setPathname("/");
request_.setHeaders(json({
{"host" , "www.test.com"},
{"Cookie" , "test"}
}).get<map<string, string>>());
_lastRequest = make_shared<Darabonba::Http::Request>(request_);
auto futureResp_ = Darabonba::Core::doAction(request_, runtime_);
shared_ptr<Darabonba::Http::MCurlResponse> response_ = futureResp_.get();
_lastResponse = response_;

return ;
} catch (const Darabonba::Exception& ex) {
_context = Darabonba::Policy::RetryPolicyContext(json({
{"retriesAttempted" , _retriesAttempted},
{"lastRequest" , _lastRequest},
{"lastResponse" , _lastResponse},
{"exception" , ex},
}));
continue;
}
}

throw *_context.exception();
}

} // namespace Darabonba
10 changes: 9 additions & 1 deletion tests/fixtures/builtin/Darafile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,13 @@
"scope": "alibabacloud",
"name": "main",
"version": "0.0.1",
"main": "./main.dara"
"main": "./main.dara",
"libraries": {},
"cpp": {
"namespace": "Darabonba",
"header": "darabonba/test.hpp"
},
"releases": {
"cpp": "darabonba/test:1.0.0"
}
}
Loading
Loading