diff --git a/lib/generator.js b/lib/generator.js index dac15a3..76cd958 100644 --- a/lib/generator.js +++ b/lib/generator.js @@ -163,7 +163,7 @@ class Visitor { return _string(clientNote.arg.value); } const fileInfo = path.parse(phpPath); - return `${_upperFirst(fileInfo.name.toLowerCase())}Client`; + return `${_upperFirst(fileInfo.name)}Client`; } saveInnerModule(ast, targetPath) { @@ -172,8 +172,7 @@ class Visitor { while (!data.done) { const aliasId = data.value; const moduleAst = ast.innerDep.get(aliasId); - - const filepath = path.join(path.dirname(targetPath), `${ast.innerModule.get(aliasId)}.php`); + const filepath = ast.innerModule.get(aliasId); this.visitModule(moduleAst, filepath, false, 0); data = keys.next(); } @@ -600,14 +599,17 @@ ${this.config.clientName}::main(array_slice($argv, 1));`); if (!moduleDir && innerPath) { let phpPath = innerPath.replace(/(\.tea)$|(\.spec)$|(\.dara)$/gi, ''); if (phpPath.startsWith('./') || phpPath.startsWith('../')) { + phpPath = phpPath.split('/').map(dir => _upperFirst(dir)).join(path.sep); phpPath = path.join(path.dirname(filepath), `${phpPath}.php`); } else if (phpPath.startsWith('/')) { + phpPath = phpPath.split('/').map(dir => _upperFirst(dir)).join(path.sep); phpPath = `${phpPath}.php`; } const classNamespace = this.getClassNamespace(phpPath); const className = this.getInnerClient(aliasId, phpPath); - innerModule.set(aliasId, innerPath); + + innerModule.set(aliasId, path.join(path.dirname(phpPath), `${className}.php`)); this.moduleClass.set(aliasId, { namespace: classNamespace, className: className, @@ -2196,7 +2198,7 @@ ${this.config.clientName}::main(array_slice($argv, 1));`); clientName = _string(clientNote.arg.value); } else { const fileInfo = path.parse(filepath); - clientName = `${_upperFirst(fileInfo.name.toLowerCase())}Client`; + clientName = _upperFirst(fileInfo.name); } } diff --git a/tests/expected/multi/api.php b/tests/expected/multi/ApiClient.php similarity index 93% rename from tests/expected/multi/api.php rename to tests/expected/multi/ApiClient.php index b130730..bb3eda5 100644 --- a/tests/expected/multi/api.php +++ b/tests/expected/multi/ApiClient.php @@ -6,8 +6,9 @@ use AlibabaCloud\Dara\Dara; use AlibabaCloud\Dara\RetryPolicy\RetryPolicyContext; use AlibabaCloud\Dara\Request; -use Dara\PHP\Tests\model\UserModel; -use Dara\PHP\Tests\lib\UtilClient; +use Dara\PHP\Tests\Model\UserModel; +use Dara\PHP\Tests\Lib\UtilClient; +use AlibabaCloud\Tea\Console\Client; use AlibabaCloud\Dara\Exception\DaraException; use AlibabaCloud\Dara\Exception\DaraUnableRetryException; class ApiClient { @@ -55,6 +56,7 @@ public function test3() $_lastRequest = $_request; $_lastResponse = $_response; + Client::log('test'); return $_response->statusCode; } catch (DaraException $e) { $_context = new RetryPolicyContext([ diff --git a/tests/expected/multi/Client.php b/tests/expected/multi/Client.php index 5aa2415..efe53d9 100644 --- a/tests/expected/multi/Client.php +++ b/tests/expected/multi/Client.php @@ -3,8 +3,8 @@ // This file is auto-generated, don't edit it. Thanks. namespace Dara\PHP\Tests; -use Dara\PHP\Tests\model\Models\Info; -use Dara\PHP\Tests\lib\UtilClient; +use Dara\PHP\Tests\Model\Models\Info; +use Dara\PHP\Tests\Lib\UtilClient; use Dara\PHP\Tests\ApiClient; class Client { /** diff --git a/tests/expected/multi/lib/util.php b/tests/expected/multi/Lib/UtilClient.php similarity index 92% rename from tests/expected/multi/lib/util.php rename to tests/expected/multi/Lib/UtilClient.php index 40b9438..37b6f34 100644 --- a/tests/expected/multi/lib/util.php +++ b/tests/expected/multi/Lib/UtilClient.php @@ -2,7 +2,7 @@ // This file is auto-generated, don't edit it. Thanks. -namespace Dara\PHP\Tests\lib; +namespace Dara\PHP\Tests\Lib; use RuntimeException; class UtilClient { diff --git a/tests/expected/multi/Model/Models/Info.php b/tests/expected/multi/Model/Models/Info.php new file mode 100644 index 0000000..ffb09eb --- /dev/null +++ b/tests/expected/multi/Model/Models/Info.php @@ -0,0 +1,81 @@ + 'name', + 'age' => 'age', + 'runtime' => 'runtime', + ]; + + public function validate() + { + Model::validateRequired('name', $this->name, true); + Model::validateRequired('age', $this->age, true); + if(null !== $this->runtime) { + $this->runtime->validate(); + } + Model::validateRequired('runtime', $this->runtime, true); + parent::validate(); + } + + public function toArray($noStream = false) + { + $res = []; + if (null !== $this->name) { + $res['name'] = $this->name; + } + + if (null !== $this->age) { + $res['age'] = $this->age; + } + + if (null !== $this->runtime) { + $res['runtime'] = null !== $this->runtime ? $this->runtime->toArray($noStream) : $this->runtime; + } + + return $res; + } + + public function toMap($noStream = false) + { + return $this->toArray($noStream); + } + + public static function fromMap($map = []) + { + $model = new self(); + if (isset($map['name'])) { + $model->name = $map['name']; + } + + if (isset($map['age'])) { + $model->age = $map['age']; + } + + if (isset($map['runtime'])) { + $model->runtime = RuntimeOptions::fromMap($map['runtime']); + } + + return $model; + } + + +} + diff --git a/tests/expected/multi/model/user.php b/tests/expected/multi/Model/UserModel.php similarity index 86% rename from tests/expected/multi/model/user.php rename to tests/expected/multi/Model/UserModel.php index 2bfe694..501937a 100644 --- a/tests/expected/multi/model/user.php +++ b/tests/expected/multi/Model/UserModel.php @@ -2,9 +2,9 @@ // This file is auto-generated, don't edit it. Thanks. -namespace Dara\PHP\Tests\model; +namespace Dara\PHP\Tests\Model; use AlibabaCloud\Tea\Utils\Utils; -use Dara\PHP\Tests\lib\UtilClient; +use Dara\PHP\Tests\Lib\UtilClient; class UserModel { /** diff --git a/tests/expected/multi/model/Models/Info.php b/tests/expected/multi/model/Models/Info.php index 69a960f..ffb09eb 100644 --- a/tests/expected/multi/model/Models/Info.php +++ b/tests/expected/multi/model/Models/Info.php @@ -2,7 +2,7 @@ // This file is auto-generated, don't edit it. Thanks. -namespace Dara\PHP\Tests\model\Models; +namespace Dara\PHP\Tests\Model\Models; use AlibabaCloud\Dara\Model; use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions; class Info extends Model { diff --git a/tests/fixtures/multi/.libraries.json b/tests/fixtures/multi/.libraries.json index a1e0097..8ce65f1 100644 --- a/tests/fixtures/multi/.libraries.json +++ b/tests/fixtures/multi/.libraries.json @@ -1,3 +1,4 @@ { - "darabonba:Util:*": "libraries/darabonba_Util_0.2.11" + "darabonba:Util:*": "libraries/darabonba_Util_0.2.11", + "darabonba:Console:*": "libraries/darabonba_Console_0.1.3" } \ No newline at end of file diff --git a/tests/fixtures/multi/Darafile b/tests/fixtures/multi/Darafile index 8dcfeb4..1642730 100644 --- a/tests/fixtures/multi/Darafile +++ b/tests/fixtures/multi/Darafile @@ -4,6 +4,7 @@ "version": "0.2.10", "main": "./sdk.dara", "libraries": { - "DARAUtil": "darabonba:Util:*" + "DARAUtil": "darabonba:Util:*", + "Console": "darabonba:Console:*" } } \ No newline at end of file diff --git a/tests/fixtures/multi/api.dara b/tests/fixtures/multi/api.dara index fcde1b7..f78fd10 100644 --- a/tests/fixtures/multi/api.dara +++ b/tests/fixtures/multi/api.dara @@ -1,5 +1,6 @@ import "./model/user" User; import "./lib/util" Util; +import Console; init() { } @@ -15,6 +16,7 @@ api test3(): number { }; __request.query = Util.getQuery(); } returns { + Console.log('test'); return __response.statusCode; } runtime { timeouted = 'retry' diff --git a/tests/fixtures/multi/libraries/darabonba_Console_0.1.3/Teafile b/tests/fixtures/multi/libraries/darabonba_Console_0.1.3/Teafile new file mode 100644 index 0000000..a0e659f --- /dev/null +++ b/tests/fixtures/multi/libraries/darabonba_Console_0.1.3/Teafile @@ -0,0 +1,79 @@ +{ + "scope": "darabonba", + "name": "Console", + "version": "0.1.3", + "main": "./main.tea", + "releases": { + "go": "github.com/alibabacloud-go/tea-console/client:v1.0.0", + "ts": "@alicloud/tea-console:^1.0.0", + "csharp": "AlibabaCloud.TeaConsole:0.1.0", + "java": "com.aliyun:tea-console:0.0.1", + "php": "alibabacloud/tea-console:^0.1.0", + "python": "alibabacloud_tea_console:0.0.1", + "python2": "alibabacloud_tea_console_py2:0.0.1", + "swift": "alibabacloud-sdk-swift/darabonba-console:1.0.0" + }, + "java": { + "package": "com.aliyun.teaconsole", + "packageInfo": { + "description": "Alibaba Cloud Tea Console Output Library for for Java", + "url": "https://github.com/aliyun/alibabacloud-sdk", + "licenseNmae": "The Apache License, Version 2.0", + "licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "developerId": "aliyunproducts", + "developerName": "Aliyun SDK", + "developerEmail": "aliyunsdk@aliyun.com" + } + }, + "csharp": { + "namespace": "AlibabaCloud.TeaConsole", + "className": "Client", + "packageInfo": { + "name": "console", + "title": "alibabacloud-console", + "description": "Alibaba Cloud Tea Console Output Library for .NET", + "company": "Alibaba Cloud, Inc" + } + }, + "php": { + "package": "AlibabaCloud.Tea.Console", + "clientName": "Client", + "packageInfo": { + "name": "alibabacloud/tea-console", + "desc": "Alibaba Cloud Tea Console Output Library for PHP", + "github": "https://github.com/aliyun/tea-console" + } + }, + "python": { + "package": "alibabacloud_tea_console", + "clientName": "client", + "packageInfo": { + "name": "alibabacloud_tea_console", + "desc": "Alibaba Cloud Tea Console Output Library for Python", + "github": "https://github.com/aliyun/alibabacloud-sdk", + "author": "Alibaba Cloud SDK", + "email": "sdk-team@alibabacloud.com" + } + }, + "python2": { + "package": "alibabacloud_tea_console", + "clientName": "client", + "packageInfo": { + "name": "alibabacloud_tea_console", + "desc": "Alibaba Cloud Tea Console Output Library for Python", + "github": "https://github.com/aliyun/alibabacloud-sdk", + "author": "Alibaba Cloud SDK", + "email": "sdk-team@alibabacloud.com" + } + }, + "swift": { + "clientName": "Client", + "packageInfo": { + "name": "AlibabacloudTeaConsole", + "desc": "Alibaba Cloud Tea Console Output Library for Swift(5.6)", + "github": "https://github.com/alibabacloud-sdk-swift/darabonba-console", + "author": "Alibaba Cloud SDK", + "email": "sdk-team@alibabacloud.com" + } + } +} \ No newline at end of file diff --git a/tests/fixtures/multi/libraries/darabonba_Console_0.1.3/main.tea b/tests/fixtures/multi/libraries/darabonba_Console_0.1.3/main.tea new file mode 100644 index 0000000..8b281f3 --- /dev/null +++ b/tests/fixtures/multi/libraries/darabonba_Console_0.1.3/main.tea @@ -0,0 +1,43 @@ +/** + * This is a console module + */ + +/** + * Console val with log level into stdout + * @param val the printing string + * @return void + * @example \[LOG\] tea console example + */ +static function log(val: string): void; + +/** + * Console val with info level into stdout + * @param val the printing string + * @return void + * @example \[INFO\] tea console example + */ +static function info(val: string): void; + +/** + * Console val with warning level into stdout + * @param val the printing string + * @return void + * @example \[WARNING\] tea console example + */ +static function warning(val: string): void; + +/** + * Console val with debug level into stdout + * @param val the printing string + * @return void + * @example \[DEBUG\] tea console example + */ +static function debug(val: string): void; + +/** + * Console val with error level into stderr + * @param val the printing string + * @return void + * @example \[ERROR\] tea console example + */ +static function error(val: string): void; \ No newline at end of file