Skip to content

Commit

Permalink
fix the multi file name
Browse files Browse the repository at this point in the history
  • Loading branch information
peze committed Nov 18, 2024
1 parent 1c23198 commit c540ebd
Show file tree
Hide file tree
Showing 12 changed files with 226 additions and 15 deletions.
12 changes: 7 additions & 5 deletions lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -55,6 +56,7 @@ public function test3()
$_lastRequest = $_request;
$_lastResponse = $_response;

Client::log('test');
return $_response->statusCode;
} catch (DaraException $e) {
$_context = new RetryPolicyContext([
Expand Down
4 changes: 2 additions & 2 deletions tests/expected/multi/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
81 changes: 81 additions & 0 deletions tests/expected/multi/Model/Models/Info.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

// This file is auto-generated, don't edit it. Thanks.

namespace Dara\PHP\Tests\Model\Models;
use AlibabaCloud\Dara\Model;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
class Info extends Model {
/**
* @var string
*/
public $name;
/**
* @var int
*/
public $age;
/**
* @var RuntimeOptions
*/
public $runtime;
protected $_name = [
'name' => '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;
}


}

Original file line number Diff line number Diff line change
Expand Up @@ -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 {

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/expected/multi/model/Models/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion tests/fixtures/multi/.libraries.json
Original file line number Diff line number Diff line change
@@ -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"
}
3 changes: 2 additions & 1 deletion tests/fixtures/multi/Darafile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"version": "0.2.10",
"main": "./sdk.dara",
"libraries": {
"DARAUtil": "darabonba:Util:*"
"DARAUtil": "darabonba:Util:*",
"Console": "darabonba:Console:*"
}
}
2 changes: 2 additions & 0 deletions tests/fixtures/multi/api.dara
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "./model/user" User;
import "./lib/util" Util;
import Console;

init() {
}
Expand All @@ -15,6 +16,7 @@ api test3(): number {
};
__request.query = Util.getQuery();
} returns {
Console.log('test');
return __response.statusCode;
} runtime {
timeouted = 'retry'
Expand Down
79 changes: 79 additions & 0 deletions tests/fixtures/multi/libraries/darabonba_Console_0.1.3/Teafile
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
43 changes: 43 additions & 0 deletions tests/fixtures/multi/libraries/darabonba_Console_0.1.3/main.tea
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit c540ebd

Please sign in to comment.