Skip to content

Commit

Permalink
upgrade by v2
Browse files Browse the repository at this point in the history
  • Loading branch information
page authored and peze committed Oct 11, 2024
1 parent e7e602b commit 1f1f6b7
Show file tree
Hide file tree
Showing 62 changed files with 8,624 additions and 1,365 deletions.
764 changes: 764 additions & 0 deletions lib/builtin.js

Large diffs are not rendered by default.

2,399 changes: 1,838 additions & 561 deletions lib/generator.js

Large diffs are not rendered by default.

318 changes: 264 additions & 54 deletions lib/helper.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"dependencies": {
"@darabonba/annotation-parser": "^1.0.0",
"@darabonba/parser": "^1.4.0"
"@darabonba/parser": "^2.0.5"
},
"author": "Alibaba Cloud OpenAPI Team",
"license": "Apache-2.0"
Expand Down
71 changes: 47 additions & 24 deletions test/fixtures/annotation/client.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,42 @@
// Description:
//
// top annotation
package client

import (
"github.com/alibabacloud-go/tea/tea"
dara "github.com/alibabacloud-go/tea/tea"

)

// Description:
//
// top annotation
type iTest interface {
dara.Model
String() string
GoString() string
SetTest(v string) *Test
GetTest() *string
}

// Description:
//
// TestModel
type Test struct {
dara.Model
// Alichange app id
Test *string `json:"test,omitempty" xml:"test,omitempty" require:"true"`
}

func (s Test) String() string {
return tea.Prettify(s)
return dara.Prettify(s)
}

func (s Test) GoString() string {
return s.String()
}

func (s *Test) GetTest() *string {
return s.Test
}

func (s *Test) SetTest(v string) *Test {
s.Test = &v
return s
Expand Down Expand Up @@ -50,30 +64,39 @@ func (client *Client)Init()(_err error) {
//
// testAPI
func (client *Client) TestAPI() (_err error) {
_runtime := map[string]interface{}{}
_runtime := dara.NewRuntimeObject(map[string]interface{}{})

var retryPolicyContext *dara.RetryPolicyContext
var request_ *dara.Request
var response_ *dara.Response
var _resultErr error
retriesAttempted := int(0)
retryPolicyContext = &dara.RetryPolicyContext{
RetriesAttempted: retriesAttempted,
}

for _retryTimes := 0; tea.BoolValue(tea.AllowRetry(_runtime["retry"], tea.Int(_retryTimes))); _retryTimes++ {
if _retryTimes > 0 {
_backoffTime := tea.GetBackoffTime(_runtime["backoff"], tea.Int(_retryTimes))
if tea.IntValue(_backoffTime) > 0 {
tea.Sleep(_backoffTime)
for dara.ShouldRetry(_runtime.RetryOptions, retryPolicyContext) {
_resultErr = nil
_backoffDelayTime := dara.GetBackoffDelay(_runtime.RetryOptions, retryPolicyContext)
dara.Sleep(_backoffDelayTime)

request_ = dara.NewRequest()
response_, _err := dara.DoRequest(request_, _runtime)
if _err != nil {
retriesAttempted++
retryPolicyContext = &dara.RetryPolicyContext{
RetriesAttempted: retriesAttempted,
HttpRequest: request_,
HttpResponse: response_,
Exception: _err,
}
_resultErr = _err
continue
}

_err = func() error {
request_ := tea.NewRequest()
response_, _err := tea.DoRequest(request_, _runtime)
if _err != nil {
return _err
}
return _err
}()
if !tea.BoolValue(tea.Retryable(_err)) {
break
}
return _err
}

return _err
return _result, _resultErr
}


Expand Down
222 changes: 177 additions & 45 deletions test/fixtures/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,40 @@
package client

import (
"github.com/alibabacloud-go/tea/tea"
dara "github.com/alibabacloud-go/tea/tea"

)

type iConfig interface {
dara.Model
String() string
GoString() string
}

type Config struct {
dara.Model
}

func (s Config) String() string {
return tea.Prettify(s)
return dara.Prettify(s)
}

func (s Config) GoString() string {
return s.String()
}

type iM interface {
dara.Model
String() string
GoString() string
}

type M struct {
dara.Model
}

func (s M) String() string {
return tea.Prettify(s)
return dara.Prettify(s)
}

func (s M) GoString() string {
Expand All @@ -42,71 +57,188 @@ func (client *Client)Init(config *Config)(_err error) {


func (client *Client) Hello() (_err error) {
request_ := tea.NewRequest()
request_.Method = tea.String("GET")
request_.Pathname = tea.String("/")
request_ := dara.NewRequest()
request_.Method = dara.String("GET")
request_.Pathname = dara.String("/")
request_.Headers = map[string]*string{
"host": tea.String("www.test.com"),
"host": dara.String("www.test.com"),
}
response_, _err := tea.DoRequest(request_, nil)
response_, _err := dara.DoRequest(request_, nil)
if _err != nil {
return _err
}
return _err

return
}

func (client *Client) HelloRuntime() (_err error) {
_runtime := map[string]interface{}{}
_runtime := dara.NewRuntimeObject(map[string]interface{}{})

var retryPolicyContext *dara.RetryPolicyContext
var request_ *dara.Request
var response_ *dara.Response
var _resultErr error
retriesAttempted := int(0)
retryPolicyContext = &dara.RetryPolicyContext{
RetriesAttempted: retriesAttempted,
}

for _retryTimes := 0; tea.BoolValue(tea.AllowRetry(_runtime["retry"], tea.Int(_retryTimes))); _retryTimes++ {
if _retryTimes > 0 {
_backoffTime := tea.GetBackoffTime(_runtime["backoff"], tea.Int(_retryTimes))
if tea.IntValue(_backoffTime) > 0 {
tea.Sleep(_backoffTime)
for dara.ShouldRetry(_runtime.RetryOptions, retryPolicyContext) {
_resultErr = nil
_backoffDelayTime := dara.GetBackoffDelay(_runtime.RetryOptions, retryPolicyContext)
dara.Sleep(_backoffDelayTime)

request_ = dara.NewRequest()
request_.Method = dara.String("GET")
request_.Pathname = dara.String("/")
request_.Headers = map[string]*string{
"host": dara.String("www.test.com"),
}
var test map[string]interface{}
test = map[string]interface{}{
"key": "value",
}
response_, _err := dara.DoRequest(request_, _runtime)
if _err != nil {
retriesAttempted++
retryPolicyContext = &dara.RetryPolicyContext{
RetriesAttempted: retriesAttempted,
HttpRequest: request_,
HttpResponse: response_,
Exception: _err,
}
_resultErr = _err
continue
}

_err = func() error {
request_ := tea.NewRequest()
request_.Method = tea.String("GET")
request_.Pathname = tea.String("/")
request_.Headers = map[string]*string{
"host": tea.String("www.test.com"),
}
var test map[string]interface{}
test = map[string]interface{}{
"key": "value",
}
response_, _err := tea.DoRequest(request_, _runtime)
if _err != nil {
return _err
testStrTmp, _err := client.GetHost()
testStr := dara.StringValue(testStrTmp)
if _err != nil {
retriesAttempted++
retryPolicyContext = &dara.RetryPolicyContext{
RetriesAttempted: retriesAttempted,
HttpRequest: request_,
HttpResponse: response_,
Exception: _err,
}
return _err
}()
if !tea.BoolValue(tea.Retryable(_err)) {
break
_resultErr = _err
continue
}
}

return _err
return _err
}
return _result, _resultErr
}

func (client *Client) HelloVirtualCall(m *M) (_err error) {
_err = tea.Validate(m)
if _err != nil {
return _err
}
request_ := tea.NewRequest()
request_.Method = tea.String("GET")
request_.Pathname = tea.String("/")
request_ := dara.NewRequest()
request_.Method = dara.String("GET")
request_.Pathname = dara.String("/")
request_.Headers = map[string]*string{
"key": tea.String(""),
"key": dara.String(""),
}
response_, _err := tea.DoRequest(request_, nil)
response_, _err := dara.DoRequest(request_, nil)
if _err != nil {
return _err
}
return _err

return
}

func (client *Client) HelloComplex() (_result interface{}, _err error) {
_runtime := dara.NewRuntimeObject(map[string]interface{}{})

var retryPolicyContext *dara.RetryPolicyContext
var request_ *dara.Request
var response_ *dara.Response
var _resultErr error
retriesAttempted := int(0)
retryPolicyContext = &dara.RetryPolicyContext{
RetriesAttempted: retriesAttempted,
}

_result = interface{}(nil)
for dara.ShouldRetry(_runtime.RetryOptions, retryPolicyContext) {
_resultErr = nil
_backoffDelayTime := dara.GetBackoffDelay(_runtime.RetryOptions, retryPolicyContext)
dara.Sleep(_backoffDelayTime)

request_ = dara.NewRequest()
hostTmp, _err := client.GetHost()
host := dara.StringValue(hostTmp)
if _err != nil {
retriesAttempted++
retryPolicyContext = &dara.RetryPolicyContext{
RetriesAttempted: retriesAttempted,
HttpRequest: request_,
HttpResponse: response_,
Exception: _err,
}
_resultErr = _err
continue
}

request_.Method = dara.String("GET")
request_.Pathname = dara.String("/")
request_.Headers = map[string]*string{
"host": dara.String(host),
}
var test map[string]interface{}
test = map[string]interface{}{
"key": "value",
}
response_, _err := dara.DoRequest(request_, _runtime)
if _err != nil {
retriesAttempted++
retryPolicyContext = &dara.RetryPolicyContext{
RetriesAttempted: retriesAttempted,
HttpRequest: request_,
HttpResponse: response_,
Exception: _err,
}
_resultErr = _err
continue
}

_result, _err = helloComplex_opResponse(response_)
if _err != nil {
retriesAttempted++
retryPolicyContext = &dara.RetryPolicyContext{
RetriesAttempted: retriesAttempted,
HttpRequest: request_,
HttpResponse: response_,
Exception: _err,
}
_resultErr = _err
continue
}

return _result, _err
}
return _result, _resultErr
}


func (client *Client) GetHost () (_result *string, _err error) {
_result = dara.String("www.test.com")
return _result, _err
}

func helloComplex_opResponse (response_ *dara.Response)( _result interface{}, _err error) {
if dara.IntValue(response_.StatusCode) != 200 {
_err = dara.NewSDKError(map[string]interface{}{
"code": dara.ToString(dara.IntValue(response_.StatusCode)),
"message": "httpCode: " + dara.ToString(dara.IntValue(response_.StatusCode)) + " ",
})
return _result, _err
}

obj, _err := dara.ReadAsJSON(response_.Body)
if _err != nil {
return _result, _err
}

_result = obj
return _result , _err
}

Loading

0 comments on commit 1f1f6b7

Please sign in to comment.