From e5c282021b89d77a18006792d54121fa990b7d9a Mon Sep 17 00:00:00 2001 From: yndu13 Date: Fri, 10 Nov 2023 17:39:22 +0800 Subject: [PATCH] fix memory leak bug --- .github/workflows/python.yml | 2 +- csharp/core/Client.cs | 4 + csharp/core/Properties/AssemblyInfo.cs | 4 +- csharp/core/client.csproj | 4 +- golang/client/client.go | 9 +- java/pom.xml | 2 +- .../java/com/aliyun/teaopenapi/Client.java | 108 ++- .../com/aliyun/teaopenapi/models/Config.java | 178 +++-- .../com/aliyun/teaopenapi/ClientTest.java | 16 +- main.tea | 2 + php/composer.json | 2 +- php/phpunit.xml | 31 + php/src/OpenApiClient.php | 2 + php/tests/OpenApiClientTest.php | 328 +++++++++ php/tests/bootstrap.php | 3 + python/alibabacloud_tea_openapi/client.py | 4 + python/setup.py | 4 +- python/tests/test_client.py | 6 +- python2/alibabacloud_tea_openapi/client.py | 2 + python2/setup.py | 4 +- python2/tests/__init__.py | 0 python2/tests/test_client.py | 684 ++++++++++++++++++ swift/AlibabacloudOpenApi.podspec | 2 +- swift/Cartfile | 2 +- swift/Package.swift | 2 +- .../Sources/AlibabacloudOpenApi/Client.swift | 2 + .../Sources/AlibabacloudOpenApi/Models.swift | 92 +-- ts/package.json | 4 +- ts/src/client.ts | 2 + 29 files changed, 1332 insertions(+), 173 deletions(-) create mode 100644 php/phpunit.xml create mode 100644 php/tests/OpenApiClientTest.php create mode 100644 php/tests/bootstrap.php create mode 100644 python2/tests/__init__.py create mode 100644 python2/tests/test_client.py diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 9a4e377..8b36b68 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.7, 3.8, 3.9] + python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] steps: - uses: actions/checkout@v2 diff --git a/csharp/core/Client.cs b/csharp/core/Client.cs index 09a7bf3..6edc44b 100644 --- a/csharp/core/Client.cs +++ b/csharp/core/Client.cs @@ -1723,8 +1723,10 @@ public Dictionary DoRequest(Params params_, OpenApiRequest reque } else { + string anything = AlibabaCloud.TeaUtil.Common.ReadAsString(response_.Body); return new Dictionary { + {"body", anything}, {"headers", response_.Headers}, {"statusCode", response_.StatusCode}, }; @@ -1987,8 +1989,10 @@ public async Task> DoRequestAsync(Params params_, Ope } else { + string anything = AlibabaCloud.TeaUtil.Common.ReadAsString(response_.Body); return new Dictionary { + {"body", anything}, {"headers", response_.Headers}, {"statusCode", response_.StatusCode}, }; diff --git a/csharp/core/Properties/AssemblyInfo.cs b/csharp/core/Properties/AssemblyInfo.cs index 705f199..bc7b354 100644 --- a/csharp/core/Properties/AssemblyInfo.cs +++ b/csharp/core/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ // Build Number // Revision // -[assembly : AssemblyVersion("0.1.6.0")] -[assembly : AssemblyFileVersion("0.1.6.0")] +[assembly : AssemblyVersion("0.1.7.0")] +[assembly : AssemblyFileVersion("0.1.7.0")] diff --git a/csharp/core/client.csproj b/csharp/core/client.csproj index 0faa85a..d68000f 100644 --- a/csharp/core/client.csproj +++ b/csharp/core/client.csproj @@ -40,11 +40,11 @@ all runtime; build; native; contentfiles; analyzers - + - + \ No newline at end of file diff --git a/golang/client/client.go b/golang/client/client.go index 2f6c606..e00d1da 100644 --- a/golang/client/client.go +++ b/golang/client/client.go @@ -5,14 +5,13 @@ package client import ( - "io" - spi "github.com/alibabacloud-go/alibabacloud-gateway-spi/client" openapiutil "github.com/alibabacloud-go/openapi-util/service" util "github.com/alibabacloud-go/tea-utils/v2/service" xml "github.com/alibabacloud-go/tea-xml/service" "github.com/alibabacloud-go/tea/tea" credential "github.com/aliyun/credentials-go/credentials" + "io" ) type GlobalParameters struct { @@ -1476,8 +1475,14 @@ func (client *Client) DoRequest(params *Params, request *OpenApiRequest, runtime }, &_result) return _result, _err } else { + anything, _err := util.ReadAsString(response_.Body) + if _err != nil { + return _result, _err + } + _result = make(map[string]interface{}) _err = tea.Convert(map[string]interface{}{ + "body": tea.StringValue(anything), "headers": response_.Headers, "statusCode": tea.IntValue(response_.StatusCode), }, &_result) diff --git a/java/pom.xml b/java/pom.xml index d2bac6f..f2e685a 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -50,7 +50,7 @@ com.aliyun tea-util - 0.2.16 + 0.2.21 com.aliyun diff --git a/java/src/main/java/com/aliyun/teaopenapi/Client.java b/java/src/main/java/com/aliyun/teaopenapi/Client.java index 1e372d9..ee04806 100644 --- a/java/src/main/java/com/aliyun/teaopenapi/Client.java +++ b/java/src/main/java/com/aliyun/teaopenapi/Client.java @@ -20,9 +20,6 @@ public class Client { public String _endpointRule; public java.util.Map _endpointMap; public String _suffix; - public String _key; - public String _cert; - public String _ca; public Integer _readTimeout; public Integer _connectTimeout; public String _httpProxy; @@ -41,6 +38,9 @@ public class Client { public java.util.Map _headers; public com.aliyun.gateway.spi.Client _spi; public GlobalParameters _globalParameters; + public String _key; + public String _cert; + public String _ca; /** * Init client with Config * @param config config contains the necessary information to create a client @@ -79,9 +79,6 @@ public Client(com.aliyun.teaopenapi.models.Config config) throws Exception { this._method = config.method; this._regionId = config.regionId; this._userAgent = config.userAgent; - this._key = config.key; - this._cert = config.cert; - this._ca = config.ca; this._readTimeout = config.readTimeout; this._connectTimeout = config.connectTimeout; this._httpProxy = config.httpProxy; @@ -93,8 +90,23 @@ public Client(com.aliyun.teaopenapi.models.Config config) throws Exception { this._signatureVersion = config.signatureVersion; this._signatureAlgorithm = config.signatureAlgorithm; this._globalParameters = config.globalParameters; + this._key = config.key; + this._cert = config.cert; + this._ca = config.ca; } + /** + * Encapsulate the request and invoke the network + * @param action api name + * @param version product version + * @param protocol http or https + * @param method e.g. GET + * @param authType authorization type e.g. AK + * @param bodyType response body type e.g. String + * @param request object of OpenApiRequest + * @param runtime which controls some details of call api, such as retry times + * @return the response + */ public java.util.Map doRPCRequest(String action, String version, String protocol, String method, String authType, String bodyType, OpenApiRequest request, com.aliyun.teautil.models.RuntimeOptions runtime) throws Exception { TeaModel.validateParams(request, "request"); java.util.Map runtime_ = TeaConverter.buildMap( @@ -123,7 +135,6 @@ public Client(com.aliyun.teaopenapi.models.Config config) throws Exception { TeaRequest _lastRequest = null; Exception _lastException = null; - TeaResponse _lastResponse = null; long _now = System.currentTimeMillis(); int _retryTimes = 0; while (Tea.allowRetry((java.util.Map) runtime_.get("retry"), _retryTimes, _now)) { @@ -221,7 +232,6 @@ public Client(com.aliyun.teaopenapi.models.Config config) throws Exception { _lastRequest = request_; TeaResponse response_ = Tea.doAction(request_, runtime_, interceptorChain); - _lastResponse = response_; if (com.aliyun.teautil.Common.is4xx(response_.statusCode) || com.aliyun.teautil.Common.is5xx(response_.statusCode)) { Object _res = com.aliyun.teautil.Common.readAsJSON(response_.body); @@ -286,17 +296,24 @@ public Client(com.aliyun.teaopenapi.models.Config config) throws Exception { continue; } throw e; - } finally { - if (!com.aliyun.teautil.Common.isUnset(_lastResponse) - && !com.aliyun.teautil.Common.isUnset(_lastResponse.response) - && !com.aliyun.teautil.Common.isUnset(_lastResponse.response.body())){ - _lastResponse.response.close(); - } } } throw new TeaUnretryableException(_lastRequest, _lastException); } + /** + * Encapsulate the request and invoke the network + * @param action api name + * @param version product version + * @param protocol http or https + * @param method e.g. GET + * @param authType authorization type e.g. AK + * @param pathname pathname of every api + * @param bodyType response body type e.g. String + * @param request object of OpenApiRequest + * @param runtime which controls some details of call api, such as retry times + * @return the response + */ public java.util.Map doROARequest(String action, String version, String protocol, String method, String authType, String pathname, String bodyType, OpenApiRequest request, com.aliyun.teautil.models.RuntimeOptions runtime) throws Exception { TeaModel.validateParams(request, "request"); java.util.Map runtime_ = TeaConverter.buildMap( @@ -325,7 +342,6 @@ public Client(com.aliyun.teaopenapi.models.Config config) throws Exception { TeaRequest _lastRequest = null; Exception _lastException = null; - TeaResponse _lastResponse = null; long _now = System.currentTimeMillis(); int _retryTimes = 0; while (Tea.allowRetry((java.util.Map) runtime_.get("retry"), _retryTimes, _now)) { @@ -398,7 +414,6 @@ public Client(com.aliyun.teaopenapi.models.Config config) throws Exception { _lastRequest = request_; TeaResponse response_ = Tea.doAction(request_, runtime_, interceptorChain); - _lastResponse = response_; if (com.aliyun.teautil.Common.equalNumber(response_.statusCode, 204)) { return TeaConverter.buildMap( @@ -470,17 +485,24 @@ public Client(com.aliyun.teaopenapi.models.Config config) throws Exception { continue; } throw e; - } finally { - if (!com.aliyun.teautil.Common.isUnset(_lastResponse) - && !com.aliyun.teautil.Common.isUnset(_lastResponse.response) - && !com.aliyun.teautil.Common.isUnset(_lastResponse.response.body())){ - _lastResponse.response.close(); - } } } throw new TeaUnretryableException(_lastRequest, _lastException); } + /** + * Encapsulate the request and invoke the network with form body + * @param action api name + * @param version product version + * @param protocol http or https + * @param method e.g. GET + * @param authType authorization type e.g. AK + * @param pathname pathname of every api + * @param bodyType response body type e.g. String + * @param request object of OpenApiRequest + * @param runtime which controls some details of call api, such as retry times + * @return the response + */ public java.util.Map doROARequestWithForm(String action, String version, String protocol, String method, String authType, String pathname, String bodyType, OpenApiRequest request, com.aliyun.teautil.models.RuntimeOptions runtime) throws Exception { TeaModel.validateParams(request, "request"); java.util.Map runtime_ = TeaConverter.buildMap( @@ -509,7 +531,6 @@ public Client(com.aliyun.teaopenapi.models.Config config) throws Exception { TeaRequest _lastRequest = null; Exception _lastException = null; - TeaResponse _lastResponse = null; long _now = System.currentTimeMillis(); int _retryTimes = 0; while (Tea.allowRetry((java.util.Map) runtime_.get("retry"), _retryTimes, _now)) { @@ -583,7 +604,6 @@ public Client(com.aliyun.teaopenapi.models.Config config) throws Exception { _lastRequest = request_; TeaResponse response_ = Tea.doAction(request_, runtime_, interceptorChain); - _lastResponse = response_; if (com.aliyun.teautil.Common.equalNumber(response_.statusCode, 204)) { return TeaConverter.buildMap( @@ -653,17 +673,23 @@ public Client(com.aliyun.teaopenapi.models.Config config) throws Exception { continue; } throw e; - } finally { - if (!com.aliyun.teautil.Common.isUnset(_lastResponse) - && !com.aliyun.teautil.Common.isUnset(_lastResponse.response) - && !com.aliyun.teautil.Common.isUnset(_lastResponse.response.body())){ - _lastResponse.response.close(); - } } } throw new TeaUnretryableException(_lastRequest, _lastException); } + /** + * Encapsulate the request and invoke the network + * @param action api name + * @param version product version + * @param protocol http or https + * @param method e.g. GET + * @param authType authorization type e.g. AK + * @param bodyType response body type e.g. String + * @param request object of OpenApiRequest + * @param runtime which controls some details of call api, such as retry times + * @return the response + */ public java.util.Map doRequest(Params params, OpenApiRequest request, com.aliyun.teautil.models.RuntimeOptions runtime) throws Exception { TeaModel.validateParams(params, "params"); TeaModel.validateParams(request, "request"); @@ -693,7 +719,6 @@ public Client(com.aliyun.teaopenapi.models.Config config) throws Exception { TeaRequest _lastRequest = null; Exception _lastException = null; - TeaResponse _lastResponse = null; long _now = System.currentTimeMillis(); int _retryTimes = 0; while (Tea.allowRetry((java.util.Map) runtime_.get("retry"), _retryTimes, _now)) { @@ -801,7 +826,6 @@ public Client(com.aliyun.teaopenapi.models.Config config) throws Exception { _lastRequest = request_; TeaResponse response_ = Tea.doAction(request_, runtime_, interceptorChain); - _lastResponse = response_; if (com.aliyun.teautil.Common.is4xx(response_.statusCode) || com.aliyun.teautil.Common.is5xx(response_.statusCode)) { java.util.Map err = new java.util.HashMap<>(); @@ -861,7 +885,9 @@ public Client(com.aliyun.teaopenapi.models.Config config) throws Exception { new TeaPair("statusCode", response_.statusCode) ); } else { + String anything = com.aliyun.teautil.Common.readAsString(response_.body); return TeaConverter.buildMap( + new TeaPair("body", anything), new TeaPair("headers", response_.headers), new TeaPair("statusCode", response_.statusCode) ); @@ -873,17 +899,23 @@ public Client(com.aliyun.teaopenapi.models.Config config) throws Exception { continue; } throw e; - } finally { - if (!com.aliyun.teautil.Common.isUnset(_lastResponse) - && !com.aliyun.teautil.Common.isUnset(_lastResponse.response) - && !com.aliyun.teautil.Common.isUnset(_lastResponse.response.body())){ - _lastResponse.response.close(); - } } } throw new TeaUnretryableException(_lastRequest, _lastException); } + /** + * Encapsulate the request and invoke the network + * @param action api name + * @param version product version + * @param protocol http or https + * @param method e.g. GET + * @param authType authorization type e.g. AK + * @param bodyType response body type e.g. String + * @param request object of OpenApiRequest + * @param runtime which controls some details of call api, such as retry times + * @return the response + */ public java.util.Map execute(Params params, OpenApiRequest request, com.aliyun.teautil.models.RuntimeOptions runtime) throws Exception { TeaModel.validateParams(params, "params"); TeaModel.validateParams(request, "request"); diff --git a/java/src/main/java/com/aliyun/teaopenapi/models/Config.java b/java/src/main/java/com/aliyun/teaopenapi/models/Config.java index 6688dca..8cf3a59 100644 --- a/java/src/main/java/com/aliyun/teaopenapi/models/Config.java +++ b/java/src/main/java/com/aliyun/teaopenapi/models/Config.java @@ -7,119 +7,175 @@ * Model for initing client */ public class Config extends TeaModel { - // accesskey id + /** + *

accesskey id

+ */ @NameInMap("accessKeyId") public String accessKeyId; - // accesskey secret + /** + *

accesskey secret

+ */ @NameInMap("accessKeySecret") public String accessKeySecret; - // security token + /** + *

security token

+ */ @NameInMap("securityToken") public String securityToken; - // http protocol + /** + *

http protocol

+ */ @NameInMap("protocol") public String protocol; - // http method + /** + *

http method

+ */ @NameInMap("method") public String method; - // region id + /** + *

region id

+ */ @NameInMap("regionId") public String regionId; - // privite key for client certificate - @NameInMap("key") - public String key; - - // client certificate - @NameInMap("cert") - public String cert; - - // server certificate - @NameInMap("ca") - public String ca; - - // read timeout + /** + *

read timeout

+ */ @NameInMap("readTimeout") public Integer readTimeout; - // connect timeout + /** + *

connect timeout

+ */ @NameInMap("connectTimeout") public Integer connectTimeout; - // http proxy + /** + *

http proxy

+ */ @NameInMap("httpProxy") public String httpProxy; - // https proxy + /** + *

https proxy

+ */ @NameInMap("httpsProxy") public String httpsProxy; - // credential + /** + *

credential

+ */ @NameInMap("credential") public com.aliyun.credentials.Client credential; - // endpoint + /** + *

endpoint

+ */ @NameInMap("endpoint") public String endpoint; - // proxy white list + /** + *

proxy white list

+ */ @NameInMap("noProxy") public String noProxy; - // max idle conns + /** + *

max idle conns

+ */ @NameInMap("maxIdleConns") public Integer maxIdleConns; - // network for endpoint + /** + *

network for endpoint

+ */ @NameInMap("network") public String network; - // user agent + /** + *

user agent

+ */ @NameInMap("userAgent") public String userAgent; - // suffix for endpoint + /** + *

suffix for endpoint

+ */ @NameInMap("suffix") public String suffix; - // socks5 proxy + /** + *

socks5 proxy

+ */ @NameInMap("socks5Proxy") public String socks5Proxy; - // socks5 network + /** + *

socks5 network

+ */ @NameInMap("socks5NetWork") public String socks5NetWork; - // endpoint type + /** + *

endpoint type

+ */ @NameInMap("endpointType") public String endpointType; - // OpenPlatform endpoint + /** + *

OpenPlatform endpoint

+ */ @NameInMap("openPlatformEndpoint") public String openPlatformEndpoint; - // credential type + /** + *

credential type

+ */ @NameInMap("type") @Deprecated public String type; - // Signature Version + /** + *

Signature Version

+ */ @NameInMap("signatureVersion") public String signatureVersion; - // Signature Algorithm + /** + *

Signature Algorithm

+ */ @NameInMap("signatureAlgorithm") public String signatureAlgorithm; - // Global Parameters + /** + *

Global Parameters

+ */ @NameInMap("globalParameters") public GlobalParameters globalParameters; + /** + *

privite key for client certificate

+ */ + @NameInMap("key") + public String key; + + /** + *

client certificate

+ */ + @NameInMap("cert") + public String cert; + + /** + *

server certificate

+ */ + @NameInMap("ca") + public String ca; + public static Config build(java.util.Map map) throws Exception { Config self = new Config(); return TeaModel.build(map, self); @@ -173,30 +229,6 @@ public String getRegionId() { return this.regionId; } - public Config setKey(String key) { - this.key = key; - return this; - } - public String getKey() { - return this.key; - } - - public Config setCert(String cert) { - this.cert = cert; - return this; - } - public String getCert() { - return this.cert; - } - - public Config setCa(String ca) { - this.ca = ca; - return this; - } - public String getCa() { - return this.ca; - } - public Config setReadTimeout(Integer readTimeout) { this.readTimeout = readTimeout; return this; @@ -349,4 +381,28 @@ public GlobalParameters getGlobalParameters() { return this.globalParameters; } + public Config setKey(String key) { + this.key = key; + return this; + } + public String getKey() { + return this.key; + } + + public Config setCert(String cert) { + this.cert = cert; + return this; + } + public String getCert() { + return this.cert; + } + + public Config setCa(String ca) { + this.ca = ca; + return this; + } + public String getCa() { + return this.ca; + } + } diff --git a/java/src/test/java/com/aliyun/teaopenapi/ClientTest.java b/java/src/test/java/com/aliyun/teaopenapi/ClientTest.java index 729d810..10f2644 100644 --- a/java/src/test/java/com/aliyun/teaopenapi/ClientTest.java +++ b/java/src/test/java/com/aliyun/teaopenapi/ClientTest.java @@ -209,7 +209,7 @@ public void testCallApiForRPCWithV2Sign_AK_Form() throws Exception { .withHeader("host", matching("localhost:[0-9]+")) .withHeader("x-acs-version", equalTo("2022-06-01")) .withHeader("x-acs-action", equalTo("TestAPI")) - .withHeader("user-agent", matching("AlibabaCloud.+tea-util/0.2.6 TeaDSL/1 config.userAgent")) + .withHeader("user-agent", matching("AlibabaCloud.+tea-util/0.2.21 TeaDSL/1 config.userAgent")) .withHeader("content-type", equalTo("application/x-www-form-urlencoded")) .willReturn(aResponse().withStatus(200).withBody(responseBody) .withHeader("x-acs-request-id", "A45EE076-334D-5012-9746-A8F828D20FD4"))); @@ -261,7 +261,7 @@ public void testCallApiForRPCWithV2Sign_Anonymous_JSON() throws Exception { .withHeader("host", matching("localhost:[0-9]+")) .withHeader("x-acs-version", equalTo("2022-06-01")) .withHeader("x-acs-action", equalTo("TestAPI")) - .withHeader("user-agent", matching("AlibabaCloud.+tea-util/0.2.6 TeaDSL/1 config.userAgent")) + .withHeader("user-agent", matching("AlibabaCloud.+tea-util/0.2.21 TeaDSL/1 config.userAgent")) .withHeader("content-type", equalTo("application/x-www-form-urlencoded")) .willReturn(aResponse().withStatus(200).withBody(responseBody) .withHeader("x-acs-request-id", "A45EE076-334D-5012-9746-A8F828D20FD4"))); @@ -317,7 +317,7 @@ public void testCallApiForROAWithV2Sign_AK_Form() throws Exception { .withHeader("authorization", matching("acs ak:.+")) .withHeader("x-acs-version", equalTo("2022-06-01")) .withHeader("x-acs-action", equalTo("TestAPI")) - .withHeader("user-agent", matching("AlibabaCloud.+tea-util/0.2.6 TeaDSL/1 config.userAgent")) + .withHeader("user-agent", matching("AlibabaCloud.+tea-util/0.2.21 TeaDSL/1 config.userAgent")) .withHeader("content-type", equalTo("application/x-www-form-urlencoded")) .willReturn(aResponse().withStatus(200).withBody(responseBody) .withHeader("x-acs-request-id", "A45EE076-334D-5012-9746-A8F828D20FD4"))); @@ -366,7 +366,7 @@ public void testCallApiForROAWithV2Sign_Anonymous_JSON() throws Exception { .withHeader("x-acs-signature-version", equalTo("1.0")) .withHeader("x-acs-version", equalTo("2022-06-01")) .withHeader("x-acs-action", equalTo("TestAPI")) - .withHeader("user-agent", matching("AlibabaCloud.+tea-util/0.2.6 TeaDSL/1 config.userAgent")) + .withHeader("user-agent", matching("AlibabaCloud.+tea-util/0.2.21 TeaDSL/1 config.userAgent")) .withHeader("content-type", equalTo("application/json; charset=UTF-8")) .willReturn(aResponse().withStatus(200).withBody(responseBody) .withHeader("x-acs-request-id", "A45EE076-334D-5012-9746-A8F828D20FD4"))); @@ -422,7 +422,7 @@ public void testCallApiForRPCWithV3Sign_AK_Form() throws Exception { .withHeader("Authorization", matching("ACS3-HMAC-SHA256 Credential=ak,SignedHeaders=content-type;host;" + "x-acs-accesskey-id;x-acs-action;x-acs-content-sha256;x-acs-date;x-acs-security-token;" + "x-acs-signature-nonce;x-acs-version,Signature=.+")) - .withHeader("user-agent", matching("AlibabaCloud.+tea-util/0.2.6 TeaDSL/1 config.userAgent")) + .withHeader("user-agent", matching("AlibabaCloud.+tea-util/0.2.21 TeaDSL/1 config.userAgent")) .withHeader("content-type", equalTo("application/x-www-form-urlencoded")) .willReturn(aResponse().withStatus(200).withBody(responseBody) .withHeader("x-acs-request-id", "A45EE076-334D-5012-9746-A8F828D20FD4"))); @@ -469,7 +469,7 @@ public void testCallApiForRPCWithV3Sign_Anonymous_JSON() throws Exception { .withHeader("x-acs-signature-nonce", matching(".+")) .withHeader("x-acs-content-sha256", matching(".+")) .withHeader("accept", matching("application/json")) - .withHeader("user-agent", matching("AlibabaCloud.+tea-util/0.2.6 TeaDSL/1 config.userAgent")) + .withHeader("user-agent", matching("AlibabaCloud.+tea-util/0.2.21 TeaDSL/1 config.userAgent")) .withHeader("content-type", equalTo("application/json; charset=UTF-8")) .willReturn(aResponse().withStatus(200).withBody(responseBody) .withHeader("x-acs-request-id", "A45EE076-334D-5012-9746-A8F828D20FD4"))); @@ -525,7 +525,7 @@ public void testCallApiForROAWithV3Sign_AK_Form() throws Exception { .withHeader("Authorization", matching("ACS3-HMAC-SHA256 Credential=ak,SignedHeaders=content-type;host;" + "x-acs-accesskey-id;x-acs-action;x-acs-content-sha256;x-acs-date;x-acs-security-token;" + "x-acs-signature-nonce;x-acs-version,Signature=.+")) - .withHeader("user-agent", matching("AlibabaCloud.+tea-util/0.2.6 TeaDSL/1 config.userAgent")) + .withHeader("user-agent", matching("AlibabaCloud.+tea-util/0.2.21 TeaDSL/1 config.userAgent")) .withHeader("content-type", equalTo("application/x-www-form-urlencoded")) .willReturn(aResponse().withStatus(200).withBody(responseBody) .withHeader("x-acs-request-id", "A45EE076-334D-5012-9746-A8F828D20FD4"))); @@ -572,7 +572,7 @@ public void testCallApiForROAWithV3Sign_Anonymous_JSON() throws Exception { .withHeader("x-acs-signature-nonce", matching(".+")) .withHeader("x-acs-content-sha256", matching(".+")) .withHeader("accept", matching("application/json")) - .withHeader("user-agent", matching("AlibabaCloud.+tea-util/0.2.6 TeaDSL/1 config.userAgent")) + .withHeader("user-agent", matching("AlibabaCloud.+tea-util/0.2.21 TeaDSL/1 config.userAgent")) .withHeader("content-type", equalTo("application/json; charset=UTF-8")) .willReturn(aResponse().withStatus(200).withBody(responseBody) .withHeader("x-acs-request-id", "A45EE076-334D-5012-9746-A8F828D20FD4"))); diff --git a/main.tea b/main.tea index 445f722..609da96 100644 --- a/main.tea +++ b/main.tea @@ -799,7 +799,9 @@ api doRequest(params: Params, request: OpenApiRequest, runtime: Util.RuntimeOpti statusCode = __response.statusCode }; } else { + var anything = Util.readAsString(__response.body); return { + body = anything, headers = __response.headers, statusCode = __response.statusCode }; diff --git a/php/composer.json b/php/composer.json index be01579..5b3f7a2 100644 --- a/php/composer.json +++ b/php/composer.json @@ -11,7 +11,7 @@ ], "require": { "php": ">5.5", - "alibabacloud/tea-utils": "^0.2.17", + "alibabacloud/tea-utils": "^0.2.19", "alibabacloud/credentials": "^1.1", "alibabacloud/openapi-util": "^0.1.10|^0.2.1", "alibabacloud/gateway-spi": "^1", diff --git a/php/phpunit.xml b/php/phpunit.xml new file mode 100644 index 0000000..796384a --- /dev/null +++ b/php/phpunit.xml @@ -0,0 +1,31 @@ + + + + + + tests + + + ./tests/Unit + + + + + + integration + + + + + + + + + + + ./src + + + diff --git a/php/src/OpenApiClient.php b/php/src/OpenApiClient.php index 24eb57e..c0981b0 100644 --- a/php/src/OpenApiClient.php +++ b/php/src/OpenApiClient.php @@ -855,7 +855,9 @@ public function doRequest($params, $request, $runtime) "statusCode" => $_response->statusCode ]; } else { + $anything = Utils::readAsString($_response->body); return [ + "body" => $anything, "headers" => $_response->headers, "statusCode" => $_response->statusCode ]; diff --git a/php/tests/OpenApiClientTest.php b/php/tests/OpenApiClientTest.php new file mode 100644 index 0000000..9ce72e2 --- /dev/null +++ b/php/tests/OpenApiClientTest.php @@ -0,0 +1,328 @@ + [ + "global-key" => "global-value" + ], + "queries" => [ + "global-query" => "global-value" + ] + ]); + $config = new Config([ + "endpoint" => "config.endpoint", + "endpointType" => "regional", + "network" => "config.network", + "suffix" => "config.suffix", + "protocol" => "config.protocol", + "method" => "config.method", + "regionId" => "config.regionId", + "userAgent" => "config.userAgent", + "readTimeout" => 3000, + "connectTimeout" => 3000, + "httpProxy" => "config.httpProxy", + "httpsProxy" => "config.httpsProxy", + "noProxy" => "config.noProxy", + "socks5Proxy" => "config.socks5Proxy", + "socks5NetWork" => "config.socks5NetWork", + "maxIdleConns" => 128, + "signatureVersion" => "config.signatureVersion", + "signatureAlgorithm" => "config.signatureAlgorithm", + "globalParameters" => $globalParameters + ]); + $creConfig = new \AlibabaCloud\Credentials\Credential\Config([ + "accessKeyId" => "accessKeyId", + "accessKeySecret" => "accessKeySecret", + "securityToken" => "securityToken", + "type" => "sts" + ]); + $credential = new Credential($creConfig); + $config->credential = $credential; + $client = new OpenApiClient($config); + $config->accessKeyId = "ak"; + $config->accessKeySecret = "secret"; + $config->securityToken = "token"; + $config->type = "sts"; + $client = new OpenApiClient($config); + } + + /** + * @return Config + */ + public static function createConfig(){ + $globalParameters = new GlobalParameters([ + "headers" => [ + "global-key" => "global-value" + ], + "queries" => [ + "global-query" => "global-value" + ] + ]); + $config = new Config([ + "accessKeyId" => "ak", + "accessKeySecret" => "secret", + "securityToken" => "token", + "type" => "sts", + "userAgent" => "config.userAgent", + "readTimeout" => 3000, + "connectTimeout" => 3000, + "maxIdleConns" => 128, + "signatureVersion" => "config.signatureVersion", + "signatureAlgorithm" => "ACS3-HMAC-SHA256", + "globalParameters" => $globalParameters + ]); + return $config; + } + + /** + * @return RuntimeOptions + */ + public static function createRuntimeOptions(){ + $runtime = new RuntimeOptions([ + "readTimeout" => 4000, + "connectTimeout" => 4000, + "maxIdleConns" => 100, + "autoretry" => true, + "maxAttempts" => 1, + "backoffPolicy" => "no", + "backoffPeriod" => 1, + "ignoreSSL" => true + ]); + return $runtime; + } + + /** + * @return OpenApiRequest + */ + public static function createOpenApiRequest(){ + $query = []; + $query["key1"] = "value"; + $query["key2"] = 1; + $query["key3"] = true; + $body = []; + $body["key1"] = "value"; + $body["key2"] = 1; + $body["key3"] = true; + $headers = [ + "for-test" => "sdk" + ]; + $req = new OpenApiRequest([ + "headers" => $headers, + "query" => OpenApiUtilClient::query($query), + "body" => OpenApiUtilClient::parseToMap($body) + ]); + return $req; + } + + public function testCallApiForRPCWithV2Sign_AK_Form(){ + $config = self::createConfig(); + $runtime = self::createRuntimeOptions(); + $config->protocol = "HTTP"; + $config->signatureAlgorithm = "v2"; + $config->endpoint = "test.aliyuncs.com"; + $client = new OpenApiClient($config); + $request = self::createOpenApiRequest(); + $params = new Params([ + "action" => "TestAPI", + "version" => "2022-06-01", + "protocol" => "HTTPS", + "pathname" => "/", + "method" => "POST", + "authType" => "AK", + "style" => "RPC", + "reqBodyType" => "formData", + "bodyType" => "json" + ]); + $client->callApi($params, $request, $runtime); + } + + public function testCallApiForRPCWithV2Sign_Anonymous_JSON(){ + $config = self::createConfig(); + $runtime = self::createRuntimeOptions(); + $config->protocol = "HTTP"; + $config->signatureAlgorithm = "v2"; + $config->endpoint = "test.aliyuncs.com"; + $client = new OpenApiClient($config); + $request = self::createOpenApiRequest(); + $params = new Params([ + "action" => "TestAPI", + "version" => "2022-06-01", + "protocol" => "HTTPS", + "pathname" => "/", + "method" => "POST", + "authType" => "Anonymous", + "style" => "RPC", + "reqBodyType" => "json", + "bodyType" => "json" + ]); + $client->callApi($params, $request, $runtime); + } + + public function testCallApiForROAWithV2Sign_HTTPS_AK_Form(){ + $config = self::createConfig(); + $runtime = self::createRuntimeOptions(); + $config->signatureAlgorithm = "v2"; + $config->endpoint = "test.aliyuncs.com"; + $client = new OpenApiClient($config); + $request = self::createOpenApiRequest(); + $params = new Params([ + "action" => "TestAPI", + "version" => "2022-06-01", + "protocol" => "HTTPS", + "pathname" => "/test", + "method" => "POST", + "authType" => "AK", + "style" => "ROA", + "reqBodyType" => "formData", + "bodyType" => "json" + ]); + $client->callApi($params, $request, $runtime); + } + + public function testCallApiForROAWithV2Sign_Anonymous_JSON(){ + $config = self::createConfig(); + $runtime = self::createRuntimeOptions(); + $config->protocol = "HTTP"; + $config->signatureAlgorithm = "v2"; + $config->endpoint = "test.aliyuncs.com"; + $client = new OpenApiClient($config); + $request = self::createOpenApiRequest(); + $params = new Params([ + "action" => "TestAPI", + "version" => "2022-06-01", + "protocol" => "HTTPS", + "pathname" => "/test", + "method" => "POST", + "authType" => "Anonymous", + "style" => "ROA", + "reqBodyType" => "json", + "bodyType" => "json" + ]); + $client->callApi($params, $request, $runtime); + } + + public function testCallApiForRPCWithV3Sign_AK_Form(){ + $config = self::createConfig(); + $runtime = self::createRuntimeOptions(); + $config->protocol = "HTTP"; + $config->endpoint = "test.aliyuncs.com"; + $client = new OpenApiClient($config); + $request = self::createOpenApiRequest(); + $params = new Params([ + "action" => "TestAPI", + "version" => "2022-06-01", + "protocol" => "HTTPS", + "pathname" => "/", + "method" => "POST", + "authType" => "AK", + "style" => "RPC", + "reqBodyType" => "formData", + "bodyType" => "json" + ]); + $client->callApi($params, $request, $runtime); + } + + public function testCallApiForRPCWithV3Sign_Anonymous_JSON(){ + $config = self::createConfig(); + $runtime = self::createRuntimeOptions(); + $config->protocol = "HTTP"; + $config->endpoint = "test.aliyuncs.com"; + $client = new OpenApiClient($config); + $request = self::createOpenApiRequest(); + $params = new Params([ + "action" => "TestAPI", + "version" => "2022-06-01", + "protocol" => "HTTPS", + "pathname" => "/", + "method" => "POST", + "authType" => "Anonymous", + "style" => "RPC", + "reqBodyType" => "json", + "bodyType" => "json" + ]); + $client->callApi($params, $request, $runtime); + } + + public function testCallApiForROAWithV3Sign_AK_Form(){ + $config = self::createConfig(); + $runtime = self::createRuntimeOptions(); + $config->protocol = "HTTP"; + $config->endpoint = "test.aliyuncs.com"; + $client = new OpenApiClient($config); + $request = self::createOpenApiRequest(); + $params = new Params([ + "action" => "TestAPI", + "version" => "2022-06-01", + "protocol" => "HTTPS", + "pathname" => "/test", + "method" => "POST", + "authType" => "AK", + "style" => "ROA", + "reqBodyType" => "formData", + "bodyType" => "json" + ]); + $client->callApi($params, $request, $runtime); + } + + public function testCallApiForROAWithV3Sign_Anonymous_JSON(){ + $config = self::createConfig(); + $runtime = self::createRuntimeOptions(); + $config->protocol = "HTTP"; + $config->endpoint = "test.aliyuncs.com"; + $client = new OpenApiClient($config); + $request = self::createOpenApiRequest(); + $params = new Params([ + "action" => "TestAPI", + "version" => "2022-06-01", + "protocol" => "HTTPS", + "pathname" => "/test", + "method" => "POST", + "authType" => "Anonymous", + "style" => "ROA", + "reqBodyType" => "json", + "bodyType" => "json" + ]); + $client->callApi($params, $request, $runtime); + } + + public function testResponseBodyType(){ + $config = self::createConfig(); + $runtime = self::createRuntimeOptions(); + $config->protocol = "HTTP"; + $config->endpoint = "test.aliyuncs.com"; + $client = new OpenApiClient($config); + $request = self::createOpenApiRequest(); + $params = new Params([ + "action" => "TestAPI", + "version" => "2022-06-01", + "protocol" => "HTTPS", + "pathname" => "/test", + "method" => "POST", + "authType" => "AK", + "style" => "ROA", + "reqBodyType" => "formData", + "bodyType" => "json" + ]); + $client->callApi($params, $request, $runtime); + $params->bodyType = "array"; + $client->callApi($params, $request, $runtime); + $params->bodyType = "string"; + $client->callApi($params, $request, $runtime); + $params->bodyType = "byte"; + $client->callApi($params, $request, $runtime); + } +} diff --git a/php/tests/bootstrap.php b/php/tests/bootstrap.php new file mode 100644 index 0000000..c62c4e8 --- /dev/null +++ b/php/tests/bootstrap.php @@ -0,0 +1,3 @@ +=0.3.8, <1.0.0", + "alibabacloud_tea_util>=0.3.11, <1.0.0", "alibabacloud_credentials>=0.3.1, <1.0.0", "alibabacloud_openapi_util>=0.2.1, <1.0.0", "alibabacloud_gateway_spi>=0.0.1, <1.0.0", diff --git a/python/tests/test_client.py b/python/tests/test_client.py index 9bbf74c..7355fa0 100644 --- a/python/tests/test_client.py +++ b/python/tests/test_client.py @@ -334,7 +334,7 @@ def request_callback(request: HTTPrettyRequest, uri: str, headers: dict): @httpretty.activate(allow_net_connect=False) def test_call_api_for_roawith_v2sign_anonymous_json(self): - requestBody = '{"key1": "value", "key2": 1, "key3": true}' + requestBody = '{"key1":"value","key2":1,"key3":true}' responseBody = '{"AppId":"test", "ClassId":"test", "UserId":123}' config = self.create_config() runtime = self.create_runtime_options() @@ -451,7 +451,7 @@ def request_callback(request: HTTPrettyRequest, uri: str, headers: dict): @httpretty.activate(allow_net_connect=False) def test_call_api_for_rpcwith_v3sign_anonymous_json(self): - requestBody = '{"key1": "value", "key2": 1, "key3": true}' + requestBody = '{"key1":"value","key2":1,"key3":true}' responseBody = '{"AppId":"test", "ClassId":"test", "UserId":123}' config = self.create_config() runtime = self.create_runtime_options() @@ -567,7 +567,7 @@ def request_callback(request: HTTPrettyRequest, uri: str, headers: dict): @httpretty.activate(allow_net_connect=False) def test_call_api_for_roawith_v3sign_anonymous_json(self): - requestBody = '{"key1": "value", "key2": 1, "key3": true}' + requestBody = '{"key1":"value","key2":1,"key3":true}' responseBody = '{"AppId":"test", "ClassId":"test", "UserId":123}' config = self.create_config() runtime = self.create_runtime_options() diff --git a/python2/alibabacloud_tea_openapi/client.py b/python2/alibabacloud_tea_openapi/client.py index 66a2a0b..2976e6e 100644 --- a/python2/alibabacloud_tea_openapi/client.py +++ b/python2/alibabacloud_tea_openapi/client.py @@ -814,7 +814,9 @@ def do_request(self, params, request, runtime): 'statusCode': _response.status_code } else: + anything = UtilClient.read_as_string(_response.body) return { + 'body': anything, 'headers': _response.headers, 'statusCode': _response.status_code } diff --git a/python2/setup.py b/python2/setup.py index 8890ea2..a081774 100644 --- a/python2/setup.py +++ b/python2/setup.py @@ -25,7 +25,7 @@ """ setup module for alibabacloud_tea_openapi_py2. -Created on 06/02/2023 +Created on 13/11/2023 @author: Alibaba Cloud SDK """ @@ -38,7 +38,7 @@ URL = "https://github.com/aliyun/darabonba-openapi" VERSION = __import__(PACKAGE).__version__ REQUIRES = [ - "alibabacloud_tea_util_py2>=0.0.7, <1.0.0", + "alibabacloud_tea_util_py2>=0.0.9, <1.0.0", "alibabacloud_credentials_py2>=0.1.1, <1.0.0", "alibabacloud_openapi_util_py2>=0.1.1, <1.0.0", "alibabacloud_gateway_spi_py2>=0.0.1, <1.0.0", diff --git a/python2/tests/__init__.py b/python2/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/python2/tests/test_client.py b/python2/tests/test_client.py new file mode 100644 index 0000000..7d7766a --- /dev/null +++ b/python2/tests/test_client.py @@ -0,0 +1,684 @@ +# -*- coding: utf-8 -*- +import unittest +import re +import httpretty +from Tea.exceptions import TeaException +from httpretty.core import HTTPrettyRequest + +from alibabacloud_tea_openapi import models as open_api_models +from alibabacloud_credentials import models as credential_models +from alibabacloud_credentials.client import Client as CredentialClient +from alibabacloud_tea_openapi.client import Client as OpenApiClient +from alibabacloud_tea_util import models as util_models +from alibabacloud_openapi_util.client import Client as OpenApiUtilClient + + +class TestClient(unittest.TestCase): + + def test_config(self): + global_parameters = open_api_models.GlobalParameters( + headers={ + 'global-key': 'global-value' + }, + queries={ + 'global-query': 'global-value' + } + ) + config = open_api_models.Config( + endpoint='config.endpoint', + endpoint_type='regional', + network='config.network', + suffix='config.suffix', + protocol='config.protocol', + method='config.method', + region_id='config.regionId', + user_agent='config.userAgent', + read_timeout=3000, + connect_timeout=3000, + http_proxy='config.httpProxy', + https_proxy='config.httpsProxy', + no_proxy='config.noProxy', + socks_5proxy='config.socks5Proxy', + socks_5net_work='config.socks5NetWork', + max_idle_conns=128, + signature_version='config.signatureVersion', + signature_algorithm='config.signatureAlgorithm', + global_parameters=global_parameters + ) + cre_config = credential_models.Config( + access_key_id='accessKeyId', + access_key_secret='accessKeySecret', + security_token='securityToken', + type='sts' + ) + credential = CredentialClient(cre_config) + config.credential = credential + client = OpenApiClient(config) + self.assertEqual('accessKeyId', client.get_access_key_id()) + self.assertEqual('accessKeySecret', client.get_access_key_secret()) + self.assertEqual('securityToken', client.get_security_token()) + self.assertEqual('sts', client.get_type()) + config.access_key_id = 'ak' + config.access_key_secret = 'secret' + config.security_token = 'token' + config.type = 'sts' + client = OpenApiClient(config) + self.assertEqual('ak', client.get_access_key_id()) + self.assertEqual('secret', client.get_access_key_secret()) + self.assertEqual('token', client.get_security_token()) + self.assertEqual('sts', client.get_type()) + self.assertIsNone(client._spi) + self.assertIsNone(client._endpoint_rule) + self.assertIsNone(client._endpoint_map) + self.assertIsNone(client._product_id) + self.assertEqual("config.endpoint", client._endpoint) + self.assertEqual("regional", client._endpoint_type) + self.assertEqual("config.network", client._network) + self.assertEqual("config.suffix", client._suffix) + self.assertEqual("config.protocol", client._protocol) + self.assertEqual("config.method", client._method) + self.assertEqual("config.regionId", client._region_id) + self.assertEqual("config.userAgent", client._user_agent) + self.assertEqual(3000, client._read_timeout) + self.assertEqual(3000, client._connect_timeout) + self.assertEqual("config.httpProxy", client._http_proxy) + self.assertEqual("config.httpsProxy", client._https_proxy) + self.assertEqual("config.noProxy", client._no_proxy) + self.assertEqual("config.socks5Proxy", client._socks_5proxy) + self.assertEqual("config.socks5NetWork", client._socks_5net_work) + self.assertEqual(128, client._max_idle_conns) + self.assertEqual("config.signatureVersion", client._signature_version) + self.assertEqual("config.signatureAlgorithm", client._signature_algorithm) + self.assertEqual("global-value", client._global_parameters.headers.get("global-key")) + self.assertEqual("global-value", client._global_parameters.queries.get("global-query")) + + def create_config(self): + global_parameters = open_api_models.GlobalParameters( + headers={ + 'global-key': 'global-value' + }, + queries={ + 'global-query': 'global-value' + } + ) + config = open_api_models.Config( + access_key_id='ak', + access_key_secret='secret', + security_token='token', + type='sts', + user_agent='config.userAgent', + read_timeout=3000, + connect_timeout=3000, + max_idle_conns=128, + signature_version='config.signatureVersion', + signature_algorithm='ACS3-HMAC-SHA256', + global_parameters=global_parameters + ) + return config + + def create_runtime_options(self): + runtime = util_models.RuntimeOptions( + read_timeout=4000, + connect_timeout=4000, + max_idle_conns=100, + autoretry=True, + max_attempts=1, + backoff_policy='no', + backoff_period=1, + ignore_ssl=True + ) + return runtime + + def create_open_api_request(self): + query = {} + query['key1'] = 'value' + query['key2'] = 1 + query['key3'] = True + body = {} + body['key1'] = 'value' + body['key2'] = 1 + body['key3'] = True + headers = { + 'for-test': 'sdk' + } + req = open_api_models.OpenApiRequest( + headers=headers, + query=OpenApiUtilClient.query(query), + body=OpenApiUtilClient.parse_to_map(body) + ) + return req + + @httpretty.activate(allow_net_connect=False) + def test_call_api_for_rpcwith_v2sign_ak_form(self): + requestBody = 'key1=value&key2=1&key3=True' + responseBody = '{"AppId":"test", "ClassId":"test", "UserId":123}' + config = self.create_config() + runtime = self.create_runtime_options() + config.protocol = 'HTTP' + config.signature_algorithm = 'v2' + config.endpoint = 'test.aliyuncs.com' + client = OpenApiClient(config) + request = self.create_open_api_request() + params = open_api_models.Params( + action='TestAPI', + version='2022-06-01', + protocol='HTTPS', + pathname='/', + method='POST', + auth_type='AK', + style='RPC', + req_body_type='formData', + body_type='json' + ) + + def request_callback(request, uri, headers): + assert 'value' == request.querystring['key1'][0] + assert '1' == request.querystring['key2'][0] + assert 'True' == request.querystring['key3'][0] + assert 'TestAPI' == request.querystring['Action'][0] + assert '2022-06-01' == request.querystring['Version'][0] + assert 'ak' == request.querystring['AccessKeyId'][0] + assert 'token' == request.querystring['SecurityToken'][0] + assert '1.0' == request.querystring['SignatureVersion'][0] + assert 'HMAC-SHA1' == request.querystring['SignatureMethod'][0] + assert 'json' == request.querystring['Format'][0] + assert None is not request.querystring['Timestamp'][0] + assert None is not request.querystring['SignatureNonce'][0] + assert None is not request.querystring['Signature'][0] + assert 'test.aliyuncs.com' == request.headers.get('host') + assert '2022-06-01' == request.headers.get('x-acs-version') + assert 'TestAPI' == request.headers.get('x-acs-action') + assert None is not re.match('AlibabaCloud.+TeaDSL/1 config.userAgent', + request.headers.get('user-agent')) + content_type = request.headers.get('content-type') + assert request.body.decode('utf-8') == requestBody, 'unexpected body: {}'.format(request.body) + assert content_type == 'application/x-www-form-urlencoded', 'expected application/json but received Content-Type: {}'.format( + content_type) + headers['x-acs-request-id'] = 'A45EE076-334D-5012-9746-A8F828D20FD4' + return [200, headers, responseBody] + + httpretty.register_uri( + httpretty.POST, "http://test.aliyuncs.com", + body=request_callback) + result = client.call_api(params, request, runtime) + self.assertEqual('A45EE076-334D-5012-9746-A8F828D20FD4', result.get("headers").get("x-acs-request-id")) + self.assertEqual('test', result.get('body').get('AppId')) + self.assertEqual('test', result.get('body').get('ClassId')) + self.assertEqual(123, result.get('body').get('UserId')) + + @httpretty.activate(allow_net_connect=False) + def test_call_api_for_rpcwith_v2sign_anonymous_json(self): + requestBody = 'key1=value&key2=1&key3=True' + responseBody = '{"AppId":"test", "ClassId":"test", "UserId":123}' + config = self.create_config() + runtime = self.create_runtime_options() + config.protocol = 'HTTP' + config.signature_algorithm = 'v2' + config.endpoint = 'test.aliyuncs.com' + client = OpenApiClient(config) + request = self.create_open_api_request() + params = open_api_models.Params( + action='TestAPI', + version='2022-06-01', + protocol='HTTPS', + pathname='/', + method='POST', + auth_type='Anonymous', + style='RPC', + req_body_type='json', + body_type='json' + ) + + def request_callback(request, uri, headers): + assert 'value' == request.querystring['key1'][0] + assert '1' == request.querystring['key2'][0] + assert 'True' == request.querystring['key3'][0] + assert 'TestAPI' == request.querystring['Action'][0] + assert '2022-06-01' == request.querystring['Version'][0] + assert 'json' == request.querystring['Format'][0] + assert None is not request.querystring['Timestamp'][0] + assert None is not request.querystring['SignatureNonce'][0] + assert 'test.aliyuncs.com' == request.headers.get('host') + assert '2022-06-01' == request.headers.get('x-acs-version') + assert 'TestAPI' == request.headers.get('x-acs-action') + assert None is not re.match('AlibabaCloud.+TeaDSL/1 config.userAgent', + request.headers.get('user-agent')) + content_type = request.headers.get('content-type') + assert request.body.decode('utf-8') == requestBody, 'unexpected body: {}'.format(request.body) + assert content_type == 'application/x-www-form-urlencoded', 'expected application/json but received Content-Type: {}'.format( + content_type) + headers['x-acs-request-id'] = 'A45EE076-334D-5012-9746-A8F828D20FD4' + return [200, headers, responseBody] + + httpretty.register_uri( + httpretty.POST, "http://test.aliyuncs.com", + body=request_callback) + result = client.call_api(params, request, runtime) + self.assertEqual('A45EE076-334D-5012-9746-A8F828D20FD4', result.get("headers").get("x-acs-request-id")) + self.assertEqual('test', result.get('body').get('AppId')) + self.assertEqual('test', result.get('body').get('ClassId')) + self.assertEqual(123, result.get('body').get('UserId')) + + @httpretty.activate(allow_net_connect=False) + def test_call_api_for_roawith_v2sign_ak_form(self): + requestBody = 'key1=value&key2=1&key3=True' + responseBody = '{"AppId":"test", "ClassId":"test", "UserId":123}' + config = self.create_config() + runtime = self.create_runtime_options() + config.protocol = 'HTTP' + config.signature_algorithm = 'v2' + config.endpoint = 'test.aliyuncs.com' + client = OpenApiClient(config) + request = self.create_open_api_request() + params = open_api_models.Params( + action='TestAPI', + version='2022-06-01', + protocol='HTTPS', + pathname='/test', + method='POST', + auth_type='AK', + style='ROA', + req_body_type='formData', + body_type='json' + ) + + def request_callback(request, uri, headers): + assert 'value' == request.querystring['key1'][0] + assert '1' == request.querystring['key2'][0] + assert 'True' == request.querystring['key3'][0] + assert 'sdk' == request.headers.get('for-test') + assert 'test.aliyuncs.com' == request.headers.get('host') + assert '2022-06-01' == request.headers.get('x-acs-version') + assert 'TestAPI' == request.headers.get('x-acs-action') + assert 'application/json' == request.headers.get('accept') + assert 'HMAC-SHA1' == request.headers.get('x-acs-signature-method') + assert '1.0' == request.headers.get('x-acs-signature-version') + assert 'ak' == request.headers.get('x-acs-accesskey-id') + assert 'token' == request.headers.get('x-acs-security-token') + assert None is not request.headers.get('date') + assert None is not request.headers.get('x-acs-signature-nonce') + + assert None is not re.match('acs ak:.+', request.headers.get('authorization')) + assert None is not re.match('AlibabaCloud.+TeaDSL/1 config.userAgent', request.headers.get('user-agent')) + content_type = request.headers.get('content-type') + assert request.body.decode('utf-8') == requestBody, 'unexpected body: {}'.format(request.body) + assert content_type == 'application/x-www-form-urlencoded', 'expected application/json but received Content-Type: {}'.format( + content_type) + headers['x-acs-request-id'] = 'A45EE076-334D-5012-9746-A8F828D20FD4' + return [200, headers, responseBody] + + httpretty.register_uri( + httpretty.POST, "http://test.aliyuncs.com/test", + body=request_callback) + result = client.call_api(params, request, runtime) + self.assertEqual('A45EE076-334D-5012-9746-A8F828D20FD4', result.get("headers").get("x-acs-request-id")) + self.assertEqual('test', result.get('body').get('AppId')) + self.assertEqual('test', result.get('body').get('ClassId')) + self.assertEqual(123, result.get('body').get('UserId')) + + @httpretty.activate(allow_net_connect=False) + def test_call_api_for_roawith_v2sign_anonymous_json(self): + requestBody = '{"key1": "value", "key2": 1, "key3": true}' + responseBody = '{"AppId":"test", "ClassId":"test", "UserId":123}' + config = self.create_config() + runtime = self.create_runtime_options() + config.protocol = 'HTTP' + config.signature_algorithm = 'v2' + config.endpoint = 'test.aliyuncs.com' + client = OpenApiClient(config) + request = self.create_open_api_request() + params = open_api_models.Params( + action='TestAPI', + version='2022-06-01', + protocol='HTTPS', + pathname='/test', + method='POST', + auth_type='Anonymous', + style='ROA', + req_body_type='json', + body_type='json' + ) + + def request_callback(request, uri, headers): + assert 'value' == request.querystring['key1'][0] + assert '1' == request.querystring['key2'][0] + assert 'True' == request.querystring['key3'][0] + assert 'sdk' == request.headers.get('for-test') + assert 'test.aliyuncs.com' == request.headers.get('host') + assert '2022-06-01' == request.headers.get('x-acs-version') + assert 'TestAPI' == request.headers.get('x-acs-action') + assert 'application/json' == request.headers.get('accept') + assert 'HMAC-SHA1' == request.headers.get('x-acs-signature-method') + assert '1.0' == request.headers.get('x-acs-signature-version') + assert None is not request.headers.get('date') + assert None is not request.headers.get('x-acs-signature-nonce') + assert None is not re.match('AlibabaCloud.+TeaDSL/1 config.userAgent', request.headers.get('user-agent')) + content_type = request.headers.get('content-type') + assert request.body.decode('utf-8') == requestBody, 'unexpected body: {}'.format(request.body) + assert content_type == 'application/json; charset=utf-8', 'expected application/json but received Content-Type: {}'.format( + content_type) + headers['x-acs-request-id'] = 'A45EE076-334D-5012-9746-A8F828D20FD4' + return [200, headers, responseBody] + + httpretty.register_uri( + httpretty.POST, "http://test.aliyuncs.com/test", + body=request_callback) + result = client.call_api(params, request, runtime) + self.assertEqual('A45EE076-334D-5012-9746-A8F828D20FD4', result.get("headers").get("x-acs-request-id")) + self.assertEqual('test', result.get('body').get('AppId')) + self.assertEqual('test', result.get('body').get('ClassId')) + self.assertEqual(123, result.get('body').get('UserId')) + + @httpretty.activate(allow_net_connect=False) + def test_call_api_for_rpcwith_v3sign_ak_form(self): + requestBody = 'key1=value&key2=1&key3=True' + responseBody = '{"AppId":"test", "ClassId":"test", "UserId":123}' + config = self.create_config() + runtime = self.create_runtime_options() + config.protocol = 'HTTP' + config.endpoint = 'test.aliyuncs.com' + client = OpenApiClient(config) + request = self.create_open_api_request() + params = open_api_models.Params( + action='TestAPI', + version='2022-06-01', + protocol='HTTPS', + pathname='/', + method='POST', + auth_type='AK', + style='RPC', + req_body_type='formData', + body_type='json' + ) + + def request_callback(request, uri, headers): + assert 'value' == request.querystring['key1'][0] + assert '1' == request.querystring['key2'][0] + assert 'True' == request.querystring['key3'][0] + assert 'global-value' == request.querystring['global-query'][0] + assert 'sdk' == request.headers.get('for-test') + assert 'global-value' == request.headers.get('global-key') + assert 'test.aliyuncs.com' == request.headers.get('host') + assert '2022-06-01' == request.headers.get('x-acs-version') + assert 'TestAPI' == request.headers.get('x-acs-action') + assert 'application/json' == request.headers.get('accept') + assert 'ak' == request.headers.get('x-acs-accesskey-id') + assert 'token' == request.headers.get('x-acs-security-token') + assert None is not request.headers.get('x-acs-date') + assert None is not request.headers.get('x-acs-signature-nonce') + assert None is not request.headers.get('x-acs-content-sha256') + + assert None is not re.match( + 'ACS3-HMAC-SHA256 Credential=ak,SignedHeaders=accept;content-type;for-test;global-key;' + + 'host;user-agent;x-acs-accesskey-id;x-acs-action;x-acs-content-sha256;x-acs-date;x-acs-security-token;' + + 'x-acs-signature-nonce;x-acs-version,Signature=.+', request.headers.get('Authorization')) + assert None is not re.match('AlibabaCloud.+TeaDSL/1 config.userAgent', request.headers.get('user-agent')) + content_type = request.headers.get('content-type') + assert request.body.decode('utf-8') == requestBody, 'unexpected body: {}'.format(request.body) + assert content_type == 'application/x-www-form-urlencoded', 'expected application/json but received Content-Type: {}'.format( + content_type) + headers['x-acs-request-id'] = 'A45EE076-334D-5012-9746-A8F828D20FD4' + return [200, headers, responseBody] + + httpretty.register_uri( + httpretty.POST, "http://test.aliyuncs.com", + body=request_callback) + result = client.call_api(params, request, runtime) + self.assertEqual('A45EE076-334D-5012-9746-A8F828D20FD4', result.get("headers").get("x-acs-request-id")) + self.assertEqual('test', result.get('body').get('AppId')) + self.assertEqual('test', result.get('body').get('ClassId')) + self.assertEqual(123, result.get('body').get('UserId')) + + @httpretty.activate(allow_net_connect=False) + def test_call_api_for_rpcwith_v3sign_anonymous_json(self): + requestBody = '{"key1": "value", "key2": 1, "key3": true}' + responseBody = '{"AppId":"test", "ClassId":"test", "UserId":123}' + config = self.create_config() + runtime = self.create_runtime_options() + config.protocol = 'HTTP' + config.endpoint = 'test.aliyuncs.com' + client = OpenApiClient(config) + request = self.create_open_api_request() + params = open_api_models.Params( + action='TestAPI', + version='2022-06-01', + protocol='HTTPS', + pathname='/', + method='POST', + auth_type='Anonymous', + style='RPC', + req_body_type='json', + body_type='json' + ) + + def request_callback(request, uri, headers): + assert 'value' == request.querystring['key1'][0] + assert '1' == request.querystring['key2'][0] + assert 'True' == request.querystring['key3'][0] + assert 'global-value' == request.querystring['global-query'][0] + assert 'sdk' == request.headers.get('for-test') + assert 'global-value' == request.headers.get('global-key') + assert 'test.aliyuncs.com' == request.headers.get('host') + assert '2022-06-01' == request.headers.get('x-acs-version') + assert 'TestAPI' == request.headers.get('x-acs-action') + assert 'application/json' == request.headers.get('accept') + assert None is not request.headers.get('x-acs-date') + assert None is not request.headers.get('x-acs-signature-nonce') + assert None is not request.headers.get('x-acs-content-sha256') + + assert None is not re.match('AlibabaCloud.+TeaDSL/1 config.userAgent', request.headers.get('user-agent')) + content_type = request.headers.get('content-type') + assert request.body.decode('utf-8') == requestBody, 'unexpected body: {}'.format(request.body) + assert content_type == 'application/json; charset=utf-8', 'expected application/json but received Content-Type: {}'.format( + content_type) + headers['x-acs-request-id'] = 'A45EE076-334D-5012-9746-A8F828D20FD4' + return [200, headers, responseBody] + + httpretty.register_uri( + httpretty.POST, "http://test.aliyuncs.com", + body=request_callback) + result = client.call_api(params, request, runtime) + self.assertEqual('A45EE076-334D-5012-9746-A8F828D20FD4', result.get("headers").get("x-acs-request-id")) + self.assertEqual('test', result.get('body').get('AppId')) + self.assertEqual('test', result.get('body').get('ClassId')) + self.assertEqual(123, result.get('body').get('UserId')) + + @httpretty.activate(allow_net_connect=False) + def test_call_api_for_roawith_v3sign_ak_form(self): + requestBody = 'key1=value&key2=1&key3=True' + responseBody = '{"AppId":"test", "ClassId":"test", "UserId":123}' + config = self.create_config() + runtime = self.create_runtime_options() + config.protocol = 'HTTP' + config.endpoint = 'test.aliyuncs.com' + client = OpenApiClient(config) + request = self.create_open_api_request() + params = open_api_models.Params( + action='TestAPI', + version='2022-06-01', + protocol='HTTPS', + pathname='/test', + method='POST', + auth_type='AK', + style='ROA', + req_body_type='formData', + body_type='json' + ) + + def request_callback(request, uri, headers): + assert 'value' == request.querystring['key1'][0] + assert '1' == request.querystring['key2'][0] + assert 'True' == request.querystring['key3'][0] + assert 'global-value' == request.querystring['global-query'][0] + assert 'sdk' == request.headers.get('for-test') + assert 'global-value' == request.headers.get('global-key') + assert 'test.aliyuncs.com' == request.headers.get('host') + assert '2022-06-01' == request.headers.get('x-acs-version') + assert 'TestAPI' == request.headers.get('x-acs-action') + assert 'application/json' == request.headers.get('accept') + assert 'ak' == request.headers.get('x-acs-accesskey-id') + assert 'token' == request.headers.get('x-acs-security-token') + assert None is not request.headers.get('x-acs-date') + assert None is not request.headers.get('x-acs-signature-nonce') + assert None is not request.headers.get('x-acs-content-sha256') + + assert None is not re.match( + 'ACS3-HMAC-SHA256 Credential=ak,SignedHeaders=accept;content-type;for-test;global-key;' + + 'host;user-agent;x-acs-accesskey-id;x-acs-action;x-acs-content-sha256;x-acs-date;x-acs-security-token;' + + 'x-acs-signature-nonce;x-acs-version,Signature=.+', request.headers.get('Authorization')) + assert None is not re.match('AlibabaCloud.+TeaDSL/1 config.userAgent', request.headers.get('user-agent')) + content_type = request.headers.get('content-type') + assert request.body.decode('utf-8') == requestBody, 'unexpected body: {}'.format(request.body) + assert content_type == 'application/x-www-form-urlencoded', 'expected application/json but received Content-Type: {}'.format( + content_type) + headers['x-acs-request-id'] = 'A45EE076-334D-5012-9746-A8F828D20FD4' + return [200, headers, responseBody] + + httpretty.register_uri( + httpretty.POST, "http://test.aliyuncs.com/test", + body=request_callback) + result = client.call_api(params, request, runtime) + self.assertEqual('A45EE076-334D-5012-9746-A8F828D20FD4', result.get("headers").get("x-acs-request-id")) + self.assertEqual('test', result.get('body').get('AppId')) + self.assertEqual('test', result.get('body').get('ClassId')) + self.assertEqual(123, result.get('body').get('UserId')) + + @httpretty.activate(allow_net_connect=False) + def test_call_api_for_roawith_v3sign_anonymous_json(self): + requestBody = '{"key1": "value", "key2": 1, "key3": true}' + responseBody = '{"AppId":"test", "ClassId":"test", "UserId":123}' + config = self.create_config() + runtime = self.create_runtime_options() + config.protocol = 'HTTP' + config.endpoint = 'test.aliyuncs.com' + client = OpenApiClient(config) + request = self.create_open_api_request() + params = open_api_models.Params( + action='TestAPI', + version='2022-06-01', + protocol='HTTPS', + pathname='/test', + method='POST', + auth_type='Anonymous', + style='ROA', + req_body_type='json', + body_type='json' + ) + + def request_callback(request, uri, headers): + assert 'value' == request.querystring['key1'][0] + assert '1' == request.querystring['key2'][0] + assert 'True' == request.querystring['key3'][0] + assert 'global-value' == request.querystring['global-query'][0] + assert 'sdk' == request.headers.get('for-test') + assert 'global-value' == request.headers.get('global-key') + assert 'test.aliyuncs.com' == request.headers.get('host') + assert '2022-06-01' == request.headers.get('x-acs-version') + assert 'TestAPI' == request.headers.get('x-acs-action') + assert 'application/json' == request.headers.get('accept') + assert None is not request.headers.get('x-acs-date') + assert None is not request.headers.get('x-acs-signature-nonce') + assert None is not request.headers.get('x-acs-content-sha256') + + assert None is not re.match('AlibabaCloud.+TeaDSL/1 config.userAgent', request.headers.get('user-agent')) + content_type = request.headers.get('content-type') + assert request.body.decode('utf-8') == requestBody, 'unexpected body: {}'.format(request.body) + assert content_type == 'application/json; charset=utf-8', 'expected application/json but received Content-Type: {}'.format( + content_type) + headers['x-acs-request-id'] = 'A45EE076-334D-5012-9746-A8F828D20FD4' + return [200, headers, responseBody] + + httpretty.register_uri( + httpretty.POST, "http://test.aliyuncs.com/test", + body=request_callback) + result = client.call_api(params, request, runtime) + self.assertEqual('A45EE076-334D-5012-9746-A8F828D20FD4', result.get("headers").get("x-acs-request-id")) + self.assertEqual('test', result.get('body').get('AppId')) + self.assertEqual('test', result.get('body').get('ClassId')) + self.assertEqual(123, result.get('body').get('UserId')) + + @httpretty.activate(allow_net_connect=False) + def test_response_body_type(self): + requestBody = 'key1=value&key2=1&key3=True' + config = self.create_config() + runtime = self.create_runtime_options() + config.protocol = 'HTTP' + config.endpoint = 'test.aliyuncs.com' + client = OpenApiClient(config) + request = self.create_open_api_request() + request.headers['type'] = 'json' + params = open_api_models.Params( + action='TestAPI', + version='2022-06-01', + protocol='HTTPS', + pathname='/test', + method='POST', + auth_type='AK', + style='ROA', + req_body_type='formData', + body_type='json' + ) + + def request_callback(request, uri, headers): + assert 'value' == request.querystring['key1'][0] + assert '1' == request.querystring['key2'][0] + assert 'True' == request.querystring['key3'][0] + assert 'global-value' == request.querystring['global-query'][0] + assert 'sdk' == request.headers.get('for-test') + assert 'global-value' == request.headers.get('global-key') + assert 'test.aliyuncs.com' == request.headers.get('host') + assert '2022-06-01' == request.headers.get('x-acs-version') + assert 'TestAPI' == request.headers.get('x-acs-action') + assert 'application/json' == request.headers.get('accept') + assert 'ak' == request.headers.get('x-acs-accesskey-id') + assert 'token' == request.headers.get('x-acs-security-token') + assert None is not request.headers.get('x-acs-date') + assert None is not request.headers.get('x-acs-signature-nonce') + assert None is not request.headers.get('x-acs-content-sha256') + + assert None is not re.match('AlibabaCloud.+TeaDSL/1 config.userAgent', request.headers.get('user-agent')) + content_type = request.headers.get('content-type') + assert request.body.decode('utf-8') == requestBody, 'unexpected body: {}'.format(request.body) + assert content_type == 'application/x-www-form-urlencoded', 'expected application/json but received Content-Type: {}'.format( + content_type) + headers['x-acs-request-id'] = 'A45EE076-334D-5012-9746-A8F828D20FD4' + if request.headers.get('type') == 'array': + return [200, headers, '["AppId", "ClassId", "UserId"]'] + elif request.headers.get('type') == 'error': + return [400, headers, '{"Code":"error code", "Message":"error message", ' + '"RequestId":"A45EE076-334D-5012-9746-A8F828D20FD4"}'] + return [200, headers, '{"AppId":"test", "ClassId":"test", "UserId":123}'] + + httpretty.register_uri( + httpretty.POST, "http://test.aliyuncs.com/test", + body=request_callback) + result = client.call_api(params, request, runtime) + self.assertEqual('A45EE076-334D-5012-9746-A8F828D20FD4', result.get("headers").get("x-acs-request-id")) + self.assertEqual('test', result.get('body').get('AppId')) + self.assertEqual('test', result.get('body').get('ClassId')) + self.assertEqual(123, result.get('body').get('UserId')) + + params.body_type = 'array' + request.headers.update({'type': 'array'}) + result = client.call_api(params, request, runtime) + self.assertEqual('A45EE076-334D-5012-9746-A8F828D20FD4', result.get("headers").get("x-acs-request-id")) + self.assertEqual('AppId', result.get('body')[0]) + self.assertEqual('ClassId', result.get('body')[1]) + self.assertEqual('UserId', result.get('body')[2]) + + params.body_type = 'string' + result = client.call_api(params, request, runtime) + self.assertEqual('A45EE076-334D-5012-9746-A8F828D20FD4', result.get("headers").get("x-acs-request-id")) + self.assertEqual('["AppId", "ClassId", "UserId"]', result.get('body')) + + params.body_type = 'byte' + result = client.call_api(params, request, runtime) + self.assertEqual('A45EE076-334D-5012-9746-A8F828D20FD4', result.get("headers").get("x-acs-request-id")) + self.assertEqual('["AppId", "ClassId", "UserId"]', result.get('body').decode('utf-8')) + + request.headers.update({'type': 'error'}) + try: + client.call_api(params, request, runtime) + except TeaException as e: + self.assertEqual('code: 400, error message request id: A45EE076-334D-5012-9746-A8F828D20FD4', e.message) + self.assertEqual('error code', e.code) diff --git a/swift/AlibabacloudOpenApi.podspec b/swift/AlibabacloudOpenApi.podspec index c4fc7e9..a5e6799 100644 --- a/swift/AlibabacloudOpenApi.podspec +++ b/swift/AlibabacloudOpenApi.podspec @@ -18,7 +18,7 @@ Pod::Spec.new do |spec| spec.tvos.deployment_target = '13.0' spec.dependency 'Tea', '~> 1.0.1' - spec.dependency 'TeaUtils', '~> 1.0.2' + spec.dependency 'TeaUtils', '~> 1.0.3' spec.dependency 'AlibabaCloudCredentials', '~> 1.0.1' spec.dependency 'AlibabaCloudOpenApiUtil', '~> 1.0.1' diff --git a/swift/Cartfile b/swift/Cartfile index af2639f..9eb516c 100644 --- a/swift/Cartfile +++ b/swift/Cartfile @@ -1,4 +1,4 @@ github aliyun/tea-swift ~> 1.0.1 -github alibabacloud-sdk-swift/tea-utils ~> 1.0.2 +github alibabacloud-sdk-swift/tea-utils ~> 1.0.3 github aliyun/credentials-swift ~> 1.0.1 github alibabacloud-sdk-swift/openapi-util ~> 1.0.1 diff --git a/swift/Package.swift b/swift/Package.swift index fa29f8b..a806970 100644 --- a/swift/Package.swift +++ b/swift/Package.swift @@ -16,7 +16,7 @@ let package = Package( dependencies: [ // Dependencies declare other packages that this package depends on. .package(url: "https://github.com/aliyun/tea-swift.git", from: "1.0.1"), - .package(url: "https://github.com/alibabacloud-sdk-swift/tea-utils", from: "1.0.2"), + .package(url: "https://github.com/alibabacloud-sdk-swift/tea-utils", from: "1.0.3"), .package(url: "https://github.com/aliyun/credentials-swift", from: "1.0.1"), .package(url: "https://github.com/alibabacloud-sdk-swift/openapi-util", from: "1.0.1"), ], diff --git a/swift/Sources/AlibabacloudOpenApi/Client.swift b/swift/Sources/AlibabacloudOpenApi/Client.swift index 0b31605..5555083 100644 --- a/swift/Sources/AlibabacloudOpenApi/Client.swift +++ b/swift/Sources/AlibabacloudOpenApi/Client.swift @@ -786,7 +786,9 @@ open class Client { ] } else { + var anything: String = try await TeaUtils.Client.readAsString(_response.body) return [ + "body": anything as! String, "headers": _response.headers, "statusCode": _response.statusCode ] diff --git a/swift/Sources/AlibabacloudOpenApi/Models.swift b/swift/Sources/AlibabacloudOpenApi/Models.swift index 5ddde1c..b930938 100644 --- a/swift/Sources/AlibabacloudOpenApi/Models.swift +++ b/swift/Sources/AlibabacloudOpenApi/Models.swift @@ -3,6 +3,8 @@ import Tea import TeaUtils import AlibabaCloudCredentials import AlibabaCloudOpenApiUtil +import AlibabacloudGatewaySPI +import DarabonbaXML public class GlobalParameters : Tea.TeaModel { public var headers: [String: String]? @@ -33,10 +35,10 @@ public class GlobalParameters : Tea.TeaModel { } public override func fromMap(_ dict: [String: Any]) -> Void { - if dict.keys.contains("headers") { + if dict.keys.contains("headers") && dict["headers"] != nil { self.headers = dict["headers"] as! [String: String] } - if dict.keys.contains("queries") { + if dict.keys.contains("queries") && dict["queries"] != nil { self.queries = dict["queries"] as! [String: String] } } @@ -202,90 +204,90 @@ public class Config : Tea.TeaModel { } public override func fromMap(_ dict: [String: Any]) -> Void { - if dict.keys.contains("accessKeyId") { + if dict.keys.contains("accessKeyId") && dict["accessKeyId"] != nil { self.accessKeyId = dict["accessKeyId"] as! String } - if dict.keys.contains("accessKeySecret") { + if dict.keys.contains("accessKeySecret") && dict["accessKeySecret"] != nil { self.accessKeySecret = dict["accessKeySecret"] as! String } - if dict.keys.contains("securityToken") { + if dict.keys.contains("securityToken") && dict["securityToken"] != nil { self.securityToken = dict["securityToken"] as! String } - if dict.keys.contains("protocol") { + if dict.keys.contains("protocol") && dict["protocol"] != nil { self.protocol_ = dict["protocol"] as! String } - if dict.keys.contains("method") { + if dict.keys.contains("method") && dict["method"] != nil { self.method = dict["method"] as! String } - if dict.keys.contains("regionId") { + if dict.keys.contains("regionId") && dict["regionId"] != nil { self.regionId = dict["regionId"] as! String } - if dict.keys.contains("readTimeout") { + if dict.keys.contains("readTimeout") && dict["readTimeout"] != nil { self.readTimeout = dict["readTimeout"] as! Int } - if dict.keys.contains("connectTimeout") { + if dict.keys.contains("connectTimeout") && dict["connectTimeout"] != nil { self.connectTimeout = dict["connectTimeout"] as! Int } - if dict.keys.contains("httpProxy") { + if dict.keys.contains("httpProxy") && dict["httpProxy"] != nil { self.httpProxy = dict["httpProxy"] as! String } - if dict.keys.contains("httpsProxy") { + if dict.keys.contains("httpsProxy") && dict["httpsProxy"] != nil { self.httpsProxy = dict["httpsProxy"] as! String } - if dict.keys.contains("credential") { + if dict.keys.contains("credential") && dict["credential"] != nil { self.credential = dict["credential"] as! AlibabaCloudCredentials.Client } - if dict.keys.contains("endpoint") { + if dict.keys.contains("endpoint") && dict["endpoint"] != nil { self.endpoint = dict["endpoint"] as! String } - if dict.keys.contains("noProxy") { + if dict.keys.contains("noProxy") && dict["noProxy"] != nil { self.noProxy = dict["noProxy"] as! String } - if dict.keys.contains("maxIdleConns") { + if dict.keys.contains("maxIdleConns") && dict["maxIdleConns"] != nil { self.maxIdleConns = dict["maxIdleConns"] as! Int } - if dict.keys.contains("network") { + if dict.keys.contains("network") && dict["network"] != nil { self.network = dict["network"] as! String } - if dict.keys.contains("userAgent") { + if dict.keys.contains("userAgent") && dict["userAgent"] != nil { self.userAgent = dict["userAgent"] as! String } - if dict.keys.contains("suffix") { + if dict.keys.contains("suffix") && dict["suffix"] != nil { self.suffix = dict["suffix"] as! String } - if dict.keys.contains("socks5Proxy") { + if dict.keys.contains("socks5Proxy") && dict["socks5Proxy"] != nil { self.socks5Proxy = dict["socks5Proxy"] as! String } - if dict.keys.contains("socks5NetWork") { + if dict.keys.contains("socks5NetWork") && dict["socks5NetWork"] != nil { self.socks5NetWork = dict["socks5NetWork"] as! String } - if dict.keys.contains("endpointType") { + if dict.keys.contains("endpointType") && dict["endpointType"] != nil { self.endpointType = dict["endpointType"] as! String } - if dict.keys.contains("openPlatformEndpoint") { + if dict.keys.contains("openPlatformEndpoint") && dict["openPlatformEndpoint"] != nil { self.openPlatformEndpoint = dict["openPlatformEndpoint"] as! String } - if dict.keys.contains("type") { + if dict.keys.contains("type") && dict["type"] != nil { self.type = dict["type"] as! String } - if dict.keys.contains("signatureVersion") { + if dict.keys.contains("signatureVersion") && dict["signatureVersion"] != nil { self.signatureVersion = dict["signatureVersion"] as! String } - if dict.keys.contains("signatureAlgorithm") { + if dict.keys.contains("signatureAlgorithm") && dict["signatureAlgorithm"] != nil { self.signatureAlgorithm = dict["signatureAlgorithm"] as! String } - if dict.keys.contains("globalParameters") { + if dict.keys.contains("globalParameters") && dict["globalParameters"] != nil { var model = GlobalParameters() model.fromMap(dict["globalParameters"] as! [String: Any]) self.globalParameters = model } - if dict.keys.contains("key") { + if dict.keys.contains("key") && dict["key"] != nil { self.key = dict["key"] as! String } - if dict.keys.contains("cert") { + if dict.keys.contains("cert") && dict["cert"] != nil { self.cert = dict["cert"] as! String } - if dict.keys.contains("ca") { + if dict.keys.contains("ca") && dict["ca"] != nil { self.ca = dict["ca"] as! String } } @@ -340,22 +342,22 @@ public class OpenApiRequest : Tea.TeaModel { } public override func fromMap(_ dict: [String: Any]) -> Void { - if dict.keys.contains("headers") { + if dict.keys.contains("headers") && dict["headers"] != nil { self.headers = dict["headers"] as! [String: String] } - if dict.keys.contains("query") { + if dict.keys.contains("query") && dict["query"] != nil { self.query = dict["query"] as! [String: String] } - if dict.keys.contains("body") { + if dict.keys.contains("body") && dict["body"] != nil { self.body = dict["body"] as! Any } - if dict.keys.contains("stream") { + if dict.keys.contains("stream") && dict["stream"] != nil { self.stream = dict["stream"] as! InputStream } - if dict.keys.contains("hostMap") { + if dict.keys.contains("hostMap") && dict["hostMap"] != nil { self.hostMap = dict["hostMap"] as! [String: String] } - if dict.keys.contains("endpointOverride") { + if dict.keys.contains("endpointOverride") && dict["endpointOverride"] != nil { self.endpointOverride = dict["endpointOverride"] as! String } } @@ -433,31 +435,31 @@ public class Params : Tea.TeaModel { } public override func fromMap(_ dict: [String: Any]) -> Void { - if dict.keys.contains("action") { + if dict.keys.contains("action") && dict["action"] != nil { self.action = dict["action"] as! String } - if dict.keys.contains("version") { + if dict.keys.contains("version") && dict["version"] != nil { self.version = dict["version"] as! String } - if dict.keys.contains("protocol") { + if dict.keys.contains("protocol") && dict["protocol"] != nil { self.protocol_ = dict["protocol"] as! String } - if dict.keys.contains("pathname") { + if dict.keys.contains("pathname") && dict["pathname"] != nil { self.pathname = dict["pathname"] as! String } - if dict.keys.contains("method") { + if dict.keys.contains("method") && dict["method"] != nil { self.method = dict["method"] as! String } - if dict.keys.contains("authType") { + if dict.keys.contains("authType") && dict["authType"] != nil { self.authType = dict["authType"] as! String } - if dict.keys.contains("bodyType") { + if dict.keys.contains("bodyType") && dict["bodyType"] != nil { self.bodyType = dict["bodyType"] as! String } - if dict.keys.contains("reqBodyType") { + if dict.keys.contains("reqBodyType") && dict["reqBodyType"] != nil { self.reqBodyType = dict["reqBodyType"] as! String } - if dict.keys.contains("style") { + if dict.keys.contains("style") && dict["style"] != nil { self.style = dict["style"] as! String } } diff --git a/ts/package.json b/ts/package.json index c3fc32c..01dd1b8 100644 --- a/ts/package.json +++ b/ts/package.json @@ -24,9 +24,9 @@ }, "dependencies": { "@alicloud/tea-typescript": "^1.7.1", - "@alicloud/tea-util": "^1.4.5", + "@alicloud/tea-util": "^1.4.7", "@alicloud/credentials": "^2", - "@alicloud/openapi-util": "^0.3.1", + "@alicloud/openapi-util": "^0.3.2", "@alicloud/gateway-spi": "^0.0.8", "@alicloud/tea-xml": "0.0.2" }, diff --git a/ts/src/client.ts b/ts/src/client.ts index 132f4db..f669224 100644 --- a/ts/src/client.ts +++ b/ts/src/client.ts @@ -1070,7 +1070,9 @@ export default class Client { statusCode: response_.statusCode, }; } else { + let anything = await Util.readAsString(response_.body); return { + body: anything, headers: response_.headers, statusCode: response_.statusCode, };