Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -581,13 +581,36 @@ setup(
} else {
this.emit('def __init__(self):\n', level + 2);
}
const wirePop = this.shouldWirePopGateway();
if (ast.initBody && ast.initBody.stmts.length !== 0) {
this.isStaticFunction = false;
this.visitStmts(ast.initBody, level + 4);
this.isStaticFunction = true;
} else {
} else if (!wirePop) {
this.emit('pass\n', level + 4);
}
if (wirePop) {
this.imports.push({
packageName: 'alibabacloud_gateway_pop.client',
className: 'Client',
aliasName: 'PopClient',
});
this.package.dependencies.alibabacloud_gateway_pop = '0.1.4';
this.emit(`self._product_id = '${this.config.productId}'\n`, level + 4);
this.emit('self._spi = PopClient()\n', level + 4);
}
}

shouldWirePopGateway() {
const productId = this.config && this.config.productId;
if (typeof productId !== 'string' || !/^[A-Za-z][A-Za-z0-9]*$/.test(productId)) {
return false;
}
if (!this.parentModule) {
return false;
}
const info = this.packageInfo && this.packageInfo[_name(this.parentModule)];
return !!(info && info.namemespace === 'alibabacloud_tea_openapi');
}

eachImport(imports, usedModels, innerModule, filepath, level) {
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/popv4/.libraries.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"alibabacloud:OpenApi:*": "libraries/OpenApi"
}
14 changes: 14 additions & 0 deletions tests/fixtures/popv4/Darafile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"scope": "alibabacloud",
"name": "main",
"version": "0.0.1",
"main": "./main.dara",
"productId": "Ecs",
"libraries": {
"OpenApi": "alibabacloud:OpenApi:*"
},
"python": {
"package": "tea_python_tests",
"clientName": "client"
}
}
13 changes: 13 additions & 0 deletions tests/fixtures/popv4/libraries/OpenApi/Darafile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"scope": "alibabacloud",
"name": "openapi",
"version": "0.0.1",
"main": "./main.dara",
"python": {
"package": "alibabacloud_tea_openapi",
"clientName": "client"
},
"releases": {
"python": "alibabacloud_tea_openapi:0.4.5"
}
}
3 changes: 3 additions & 0 deletions tests/fixtures/popv4/libraries/OpenApi/main.dara
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
model Config = {}

init(config: Config);
7 changes: 7 additions & 0 deletions tests/fixtures/popv4/main.dara
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import OpenApi;

extends OpenApi;

init(config: OpenApi.Config) {
super(config);
}
22 changes: 22 additions & 0 deletions tests/main.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,4 +350,26 @@ describe('Python Generator', function () {
}
});
});

it('openapi product wires pop gateway', function () {
const moduleName = 'popv4';
const prefixDir = path.join(fixturesDir, moduleName);
const pkg = JSON.parse(fs.readFileSync(path.join(prefixDir, 'Darafile'), 'utf8'));
const moduleOutputDir = path.join(outputDir, moduleName);
const config = {
outputDir: moduleOutputDir,
pkgDir: prefixDir,
...pkg,
...pkg.python
};
const generator = new Generator(config, lang);
const mainFilePath = path.join(prefixDir, 'main.dara');
generator.visit(DSL.parse(fs.readFileSync(mainFilePath, 'utf8'), mainFilePath));
const client = fs.readFileSync(path.join(moduleOutputDir, 'tea_python_tests', 'client.py'), 'utf8');
assert.ok(client.includes('from alibabacloud_gateway_pop.client import Client as PopClient'));
assert.ok(client.includes("self._product_id = 'Ecs'"));
assert.ok(client.includes('self._spi = PopClient()'));
const setup = fs.readFileSync(path.join(moduleOutputDir, 'setup.py'), 'utf8');
assert.ok(setup.includes('alibabacloud_gateway_pop>=0.1.4'));
});
});
Loading