├── .eslintignore ├── .eslintrc ├── .github ├── dependabot.yml └── workflows │ └── ci.yml ├── .gitignore ├── CHANGELOG.md ├── ChangeLog.md ├── LICENSE ├── README-CN.md ├── README.md ├── lib ├── builtin.js ├── generator.js └── helper.js ├── nyc.config.js ├── package.json └── tests ├── expected ├── alias │ ├── .gitignore │ ├── setup.py │ └── tea_python_tests │ │ ├── __init__.py │ │ └── client.py ├── annotation │ └── tea_python_tests │ │ ├── __init__.py │ │ ├── client.py │ │ └── models │ │ ├── __init__.py │ │ └── _test.py ├── api │ └── tea_python_tests │ │ ├── __init__.py │ │ └── client.py ├── builtin │ └── tea_python_tests │ │ └── client.py ├── comment │ └── tea_python_tests │ │ ├── __init__.py │ │ ├── client.py │ │ └── models │ │ ├── __init__.py │ │ ├── _test_1.py │ │ ├── _test_2.py │ │ └── _test_3.py ├── complex │ └── tea_python_tests │ │ ├── __init__.py │ │ ├── client.py │ │ ├── exceptions │ │ ├── __init__.py │ │ ├── _err_1.py │ │ └── _err_2.py │ │ └── models │ │ ├── __init__.py │ │ ├── _complex_request.py │ │ └── _response.py ├── const │ └── tea_python_tests │ │ ├── __init__.py │ │ └── client.py ├── empty │ ├── .gitignore │ ├── setup.py │ └── tea_python_tests │ │ ├── __init__.py │ │ └── client.py ├── exec │ └── tea_python_tests │ │ ├── __init__.py │ │ └── exec_client.py ├── function │ └── tea_python_tests │ │ ├── __init__.py │ │ └── client.py ├── import │ ├── setup.py │ └── tea_python_tests │ │ ├── __init__.py │ │ └── client.py ├── map │ └── tea_python_tests │ │ ├── __init__.py │ │ └── client.py ├── model │ └── tea_python_tests │ │ ├── __init__.py │ │ ├── client.py │ │ ├── exceptions │ │ ├── __init__.py │ │ └── _main_file.py │ │ └── models │ │ ├── __init__.py │ │ ├── _class.py │ │ ├── _m.py │ │ ├── _main_file.py │ │ ├── _model.py │ │ └── _my_model.py ├── modelConfig │ └── tea_python_tests │ │ ├── __init__.py │ │ ├── client.py │ │ ├── exceptions │ │ ├── __init__.py │ │ └── _main_file.py │ │ └── models │ │ ├── __init__.py │ │ ├── _class.py │ │ ├── _m.py │ │ ├── _main_file.py │ │ ├── _model.py │ │ └── _my_model.py ├── multi │ └── tea_python_tests │ │ ├── __init__.py │ │ ├── api.py │ │ ├── api_models │ │ ├── __init__.py │ │ └── _test_model_dir_2.py │ │ ├── client.py │ │ ├── exceptions │ │ ├── __init__.py │ │ └── _err.py │ │ ├── lib │ │ └── util.py │ │ ├── model │ │ ├── user.py │ │ ├── user_exceptions │ │ │ ├── __init__.py │ │ │ ├── _err.py │ │ │ ├── _err_1.py │ │ │ └── _err_2.py │ │ └── user_models │ │ │ ├── __init__.py │ │ │ ├── _base_info.py │ │ │ └── _info.py │ │ └── models │ │ ├── __init__.py │ │ └── _test_model_dir.py ├── statements │ └── tea_python_tests │ │ ├── __init__.py │ │ └── client.py ├── super │ └── tea_python_tests │ │ ├── __init__.py │ │ └── client.py └── typedef │ ├── setup.py │ └── tea_python_tests │ ├── __init__.py │ ├── client.py │ └── models │ ├── __init__.py │ └── _m.py ├── fixtures ├── alias │ ├── .libraries.json │ ├── Darafile │ ├── libraries │ │ ├── Alias-Symbol │ │ │ ├── Darafile │ │ │ └── main.dara │ │ ├── Alias │ │ │ ├── Darafile │ │ │ └── alias.dara │ │ ├── AliasSource │ │ │ ├── Darafile │ │ │ └── main.dara │ │ ├── Import │ │ │ ├── Darafile │ │ │ └── import.dara │ │ └── Source │ │ │ ├── Darafile │ │ │ └── source.dara │ └── main.dara ├── annotation │ ├── Darafile │ └── main.dara ├── api │ ├── Darafile │ └── main.dara ├── builtin │ ├── Darafile │ └── main.dara ├── comment │ ├── .libraries.json │ ├── Darafile │ ├── libraries │ │ ├── Darafile │ │ └── import.dara │ └── main.dara ├── complex │ ├── .libraries.json │ ├── Darafile │ ├── libraries │ │ ├── Darafile │ │ └── import.dara │ └── main.dara ├── const │ ├── Darafile │ └── main.dara ├── empty │ ├── Darafile │ └── main.dara ├── exec │ ├── Darafile │ └── main.dara ├── function │ ├── Darafile │ └── main.dara ├── import │ ├── .libraries.json │ ├── Darafile │ ├── libraries │ │ ├── Darafile │ │ └── import.dara │ ├── main.dara │ └── pack │ │ ├── Darafile │ │ └── local.dara ├── map │ ├── .libraries.json │ ├── Darafile │ ├── libraries │ │ ├── Darafile │ │ └── import.dara │ └── main.dara ├── model │ ├── .libraries.json │ ├── Darafile │ ├── libraries │ │ ├── Darafile │ │ └── import.dara │ └── main.dara ├── modelConfig │ ├── .libraries.json │ ├── Darafile │ ├── libraries │ │ ├── Darafile │ │ └── import.dara │ └── main.dara ├── multi │ ├── .libraries.json │ ├── Darafile │ ├── api.dara │ ├── lib │ │ └── util.dara │ ├── libraries │ │ └── darabonba_Util_0.2.11 │ │ │ ├── Teafile │ │ │ ├── main.tea │ │ │ └── util.tea │ ├── main.dara │ └── model │ │ └── user.dara ├── statements │ ├── Darafile │ └── main.dara ├── super │ ├── .libraries.json │ ├── Darafile │ ├── libraries │ │ ├── Darafile │ │ └── import.dara │ └── main.dara └── typedef │ ├── .libraries.json │ ├── Darafile │ ├── libraries │ └── alibabacloud-OSS-0.0.1 │ │ ├── Darafile │ │ └── oss.dara │ └── main.dara └── main.tests.js /.eslintignore: -------------------------------------------------------------------------------- 1 | *.debug.js 2 | *.min.js 3 | node_modules/* 4 | app/public/* 5 | coverage/* 6 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | "indent": [2, 2], 4 | "quotes": [2, "single"], 5 | "linebreak-style": [2, "unix"], 6 | "semi": [2, "always"], 7 | "strict": [2, "global"], 8 | "curly": 2, 9 | "eqeqeq": 2, 10 | "no-eval": 2, 11 | "guard-for-in": 2, 12 | "no-caller": 2, 13 | "no-else-return": 2, 14 | "no-eq-null": 2, 15 | "no-extend-native": 2, 16 | "no-extra-bind": 2, 17 | "no-floating-decimal": 2, 18 | "no-implied-eval": 2, 19 | "no-labels": 2, 20 | "no-with": 2, 21 | "no-loop-func": 1, 22 | "no-native-reassign": 2, 23 | "no-redeclare": [2, {"builtinGlobals": true}], 24 | "no-delete-var": 2, 25 | "no-shadow-restricted-names": 2, 26 | "no-undef-init": 2, 27 | "no-use-before-define": 2, 28 | "no-unused-vars": [2, {"args": "none"}], 29 | "no-undefined": 1, 30 | "no-undef": 2, 31 | "global-require": 0, 32 | "no-console": 0 33 | }, 34 | "env": { 35 | "es6": true, 36 | "node": true, 37 | "browser": true 38 | }, 39 | "globals": { 40 | "describe": true, 41 | "it": true, 42 | "before": true, 43 | "after": true, 44 | "beforeEach": true 45 | }, 46 | "parserOptions": { 47 | "ecmaVersion": 2018, 48 | "sourceType": "script", 49 | "ecmaFeatures": { 50 | } 51 | }, 52 | "extends": "eslint:recommended" 53 | } -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "npm" # See documentation for possible values 9 | directory: "/" # Location of package manifests 10 | schedule: 11 | interval: "weekly" 12 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions 3 | 4 | name: CI 5 | 6 | on: 7 | push: 8 | branches: [ master ] 9 | pull_request: 10 | branches: [ master ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | strategy: 18 | matrix: 19 | node-version: [14.x, 16.x, 18.x, 20.x] 20 | 21 | steps: 22 | - uses: actions/checkout@v2 23 | - name: Use Node.js ${{ matrix.node-version }} 24 | uses: actions/setup-node@v2 25 | with: 26 | node-version: ${{ matrix.node-version }} 27 | - run: npm install 28 | - run: npm run ci 29 | - name: Upload coverage to Codecov 30 | uses: codecov/codecov-action@v3 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | coverage/ 3 | runtime/ 4 | output/ 5 | .DS_Store 6 | .nyc_output/ 7 | tests/package/ 8 | package-lock 9 | .idea/ 10 | .vscode/ 11 | .gitignore 12 | .git/ 13 | .gitmodules 14 | .gitignore 15 | .gitattributes 16 | .gitkeep -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # ChangeLog 2 | 3 | # 2.0.12 4 | - Fixed the catch id error. 5 | 6 | # 2.0.10 7 | - Upgrade the sse function generate function. 8 | 9 | # 2.0.9 10 | - Fixed the arr & map init error in from map 11 | 12 | # 2.0.8 13 | - Optimized the directory structure of models 14 | 15 | # 2.0.7 16 | - Fixed the FileField from. 17 | 18 | # 2.0.6 19 | - Fixed the from map init submodel name. 20 | 21 | # 2.0.5 22 | - Add the model generate config. 23 | - Fixed the model validate function error. 24 | 25 | # 2.0.4 26 | - Fixed the writable & readable assert logic. 27 | 28 | # 2.0.3 29 | - Optimized the directory structure of models and exceptions. 30 | 31 | # 2.0.2 32 | - Fixed the to_map & from_map 33 | 34 | # 2.0.1 35 | - Fixed the Inner Import & Export 36 | 37 | # 2.0.0 38 | - Upgrade By Darbaonba V2 -------------------------------------------------------------------------------- /ChangeLog.md: -------------------------------------------------------------------------------- 1 | # ChangeLog 2 | 3 | # 2.0.12 4 | - Fixed the catch id error. 5 | 6 | # 2.0.10 7 | - Upgrade the sse function generate function. 8 | 9 | # 2.0.9 10 | - Fixed the arr & map init error in from map 11 | 12 | # 2.0.8 13 | - Optimized the directory structure of models 14 | 15 | # 2.0.7 16 | - Fixed the FileField from. 17 | 18 | # 2.0.6 19 | - Fixed the from map init submodel name. 20 | 21 | # 2.0.5 22 | - Add the model generate config. 23 | - Fixed the model validate function error. 24 | 25 | # 2.0.4 26 | - Fixed the writable & readable assert logic. 27 | 28 | # 2.0.3 29 | - Optimized the directory structure of models and exceptions. 30 | 31 | # 2.0.2 32 | - Fixed the to_map & from_map 33 | 34 | # 2.0.1 35 | - Fixed the Inner Import & Export 36 | 37 | # 2.0.0 38 | - Upgrade By Darbaonba V2 -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009-present, Alibaba Cloud All rights reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. -------------------------------------------------------------------------------- /README-CN.md: -------------------------------------------------------------------------------- 1 | [English](/README.md) | 简体中文 2 | 3 | # Darabonba Python 生成器 4 | 5 | [![CI](https://github.com/aliyun/darabonba-python-generator/actions/workflows/ci.yml/badge.svg)](https://github.com/aliyun/darabonba-python-generator/actions/workflows/ci.yml) 6 | [![codecov][cov-image]][cov-url] 7 | [![NPM version][npm-image]][npm-url] 8 | [![npm download][download-image]][download-url] 9 | 10 | [npm-image]: https://img.shields.io/npm/v/@darabonba/python-generator.svg?style=flat-square 11 | [npm-url]: https://npmjs.org/package/@darabonba/python-generator 12 | [cov-image]: https://codecov.io/gh/aliyun/darabonba-python-generator/branch/master/graph/badge.svg 13 | [cov-url]: https://codecov.io/gh/aliyun/darabonba-python-generator 14 | [download-image]: https://img.shields.io/npm/dm/@darabonba/python-generator.svg?style=flat-square 15 | [download-url]: https://npmjs.org/package/@darabonba/python-generator 16 | 17 | ## 安装 18 | 19 | Darabonba 生成器只能在 Node.js 环境下运行。建议使用 [NPM](https://www.npmjs.com/) 包管理工具安装。在终端输入以下命令进行安装: 20 | 21 | ```bash 22 | npm install @darabonba/python-generator 23 | ``` 24 | 25 | ## 使用说明 26 | 27 | ```javascript 28 | 'use strict'; 29 | 30 | const path = require('path'); 31 | const fs = require('fs'); 32 | 33 | const Generator = require('@darabonba/python-generator'); 34 | const DSL = require('@darabonba/parser'); 35 | 36 | const modulePath = ''; 37 | const outputDir = ''; 38 | 39 | const teaFile = fs.readFileSync(path.join(modulePath, 'Darafile'), 'utf8'); 40 | const main = fs.readFileSync(path.join(modulePath, 'main.dara'), 'utf8'); 41 | 42 | const pkgInfo = JSON.parse(teaFile); 43 | const config = { 44 | outputDir: outputDir, 45 | pkgDir: modulePath, 46 | ...pkgInfo 47 | }; 48 | 49 | const ast = DSL.parse(main, path.join(modulePath, 'main.dara')); 50 | const generator = new Generator(config, 'python'); 51 | 52 | generator.visit(ast); 53 | ``` 54 | 55 | ## 问题 56 | 57 | [Opening an Issue](https://github.com/aliyun/darabonba-python-generator/issues/new),不符合指南的问题可能会立即关闭。 58 | 59 | ## 发布日志 60 | 61 | 发布详情会更新在 [release notes](/ChangeLog.md) 文件中 62 | 63 | ## 许可证 64 | 65 | [Apache-2.0](/LICENSE) 66 | Copyright (c) 2009-present, Alibaba Cloud All rights reserved. 67 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | English | [简体中文](/README-CN.md) 2 | 3 | # Darabonba Python Generator 4 | 5 | [![CI](https://github.com/aliyun/darabonba-python-generator/actions/workflows/ci.yml/badge.svg)](https://github.com/aliyun/darabonba-python-generator/actions/workflows/ci.yml) 6 | [![codecov][cov-image]][cov-url] 7 | [![NPM version][npm-image]][npm-url] 8 | [![npm download][download-image]][download-url] 9 | 10 | [npm-image]: https://img.shields.io/npm/v/@darabonba/python-generator.svg?style=flat-square 11 | [npm-url]: https://npmjs.org/package/@darabonba/python-generator 12 | [cov-image]: https://codecov.io/gh/aliyun/darabonba-python-generator/branch/master/graph/badge.svg 13 | [cov-url]: https://codecov.io/gh/aliyun/darabonba-python-generator 14 | [download-image]: https://img.shields.io/npm/dm/@darabonba/python-generator.svg?style=flat-square 15 | [download-url]: https://npmjs.org/package/@darabonba/python-generator 16 | 17 | ## Installation 18 | 19 | Darabonba Code Generator was designed to work in Node.js. The preferred way to install the Generator is to use the [NPM](https://www.npmjs.com/) package manager. Simply type the following into a terminal window: 20 | 21 | ```bash 22 | npm install @darabonba/python-generator 23 | ``` 24 | 25 | ## Usage 26 | 27 | ```javascript 28 | 'use strict'; 29 | 30 | const path = require('path'); 31 | const fs = require('fs'); 32 | 33 | const Generator = require('@darabonba/python-generator'); 34 | const DSL = require('@darabonba/parser'); 35 | 36 | const modulePath = ''; 37 | const moduleOutputDir = ''; 38 | 39 | const teaFile = fs.readFileSync(path.join(modulePath, 'Darafile'), 'utf8'); 40 | const main = fs.readFileSync(path.join(modulePath, 'main.dara'), 'utf8'); 41 | 42 | const pkgInfo = JSON.parse(teaFile); 43 | const config = { 44 | outputDir: moduleOutputDir, 45 | pkgDir: modulePath, 46 | ...pkgInfo 47 | }; 48 | // generate AST data by parser 49 | const ast = DSL.parse(main, path.join(modulePath, 'main.dara')); 50 | // initialize generator 51 | const generator = new Generator(config, 'python'); 52 | 53 | generator.visit(ast); 54 | ``` 55 | 56 | ## Issues 57 | 58 | [Opening an Issue](https://github.com/aliyun/darabonba-python-generator/issues/new), Issues not conforming to the guidelines may be closed immediately. 59 | 60 | ## Changelog 61 | 62 | Detailed changes for each release are documented in the [release notes](/ChangeLog.md). 63 | 64 | ## License 65 | 66 | [Apache-2.0](/LICENSE) 67 | Copyright (c) 2009-present, Alibaba Cloud All rights reserved. 68 | -------------------------------------------------------------------------------- /lib/helper.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const DSL = require('@darabonba/parser'); 3 | const fs = require('fs'); 4 | const path = require('path'); 5 | const keywords = [ 6 | 'False', 'None', 'True', '__peg_parser__', 'and', 7 | 'as', 'assert', 'async', 'await', 'break', 8 | 'class', 'continue', 'def', 'del', 'elif', 9 | 'else', 'except', 'finally', 'for', 'from', 10 | 'global', 'if', 'import', 'in', 'is', 11 | 'lambda', 'nonlocal', 'not', 'or', 'pass', 12 | 'raise', 'return', 'try', 'while', 'with', 'yield' 13 | ]; 14 | // 定义标准库模块列表(Python 3.x常用标准库) 15 | const standardLibraries = new Set([ 16 | '__future__', 'abc', 'argparse', 'ast', 'asyncio', 'base64', 'bisect', 17 | 'builtins', 'calendar', 'collections', 'concurrent', 'configparser', 18 | 'contextlib', 'copy', 'csv', 'datetime', 'decimal', 'difflib', 19 | 'email', 'enum', 'errno', 'faulthandler', 'fileinput', 'fnmatch', 20 | 'fractions', 'functools', 'gc', 'glob', 'gzip', 'hashlib', 'heapq', 21 | 'hmac', 'html', 'http', 'importlib', 'inspect', 'io', 'ipaddress', 22 | 'itertools', 'json', 'keyword', 'linecache', 'locale', 'logging', 23 | 'lzma', 'math', 'mimetypes', 'multiprocessing', 'numbers', 'operator', 24 | 'os', 'pathlib', 'pickle', 'platform', 'pprint', 'queue', 'random', 25 | 're', 'reprlib', 'secrets', 'shlex', 'shutil', 'signal', 'socket', 26 | 'sqlite3', 'ssl', 'statistics', 'string', 'subprocess', 'sys', 27 | 'tarfile', 'tempfile', 'textwrap', 'threading', 'time', 'timeit', 28 | 'traceback', 'types', 'typing', 'unittest', 'urllib', 'uuid', 29 | 'warnings', 'weakref', 'xml', 'zipfile', 'zlib' 30 | ]); 31 | 32 | const builtinModels = [ 33 | '$Request', '$Response', '$Error', '$SSEEvent', '$Model', 34 | '$RuntimeOptions', '$ExtendsParameters', '$RetryOptions', 35 | '$ResponseError', '$FileField' 36 | ]; 37 | 38 | const CORE = 'Dara'; 39 | const REQUEST = '_request'; 40 | const RESPONSE = '_response'; 41 | const EXCEPTION = 'darabonba.exceptions.DaraException'; 42 | const RESP_EXCEPTION = 'darabonba.exceptions.ResponseException'; 43 | const MODEL = 'darabonba.model'; 44 | 45 | const builtinImports = { 46 | DaraStream: { 47 | packageName: 'darabonba.utils.stream', 48 | className: 'Stream', 49 | aliasName: 'DaraStream' 50 | }, 51 | DaraConsole: { 52 | packageName: 'darabonba.utils.console', 53 | className: 'Logger', 54 | aliasName: 'DaraConsole' 55 | }, 56 | DaraXML: { 57 | packageName: 'darabonba.utils.xml', 58 | className: 'XML', 59 | aliasName: 'DaraXML' 60 | }, 61 | DaraURL: { 62 | packageName: 'darabonba.url', 63 | className: 'Url', 64 | aliasName: 'DaraURL' 65 | }, 66 | DaraForm: { 67 | packageName: 'darabonba.utils.form', 68 | className: 'Form', 69 | aliasName: 'DaraForm' 70 | }, 71 | DaraFile: { 72 | packageName: 'darabonba.file', 73 | className: 'File', 74 | aliasName: 'DaraFile' 75 | }, 76 | DaraBytes: { 77 | packageName: 'darabonba.utils.bytes', 78 | className: 'Bytes', 79 | aliasName: 'DaraBytes' 80 | }, 81 | DaraDate: { 82 | packageName: 'darabonba.date', 83 | className: 'Date', 84 | aliasName: 'DaraDate' 85 | }, 86 | DaraCore: { 87 | packageName: 'darabonba.core', 88 | className: 'DaraCore', 89 | }, 90 | DaraRequest: { 91 | packageName: 'darabonba.request', 92 | className: 'DaraRequest', 93 | }, 94 | DaraResponse: { 95 | packageName: 'darabonba.response', 96 | className: 'DaraResponse', 97 | }, 98 | DaraModel: { 99 | packageName: 'darabonba.model', 100 | className: 'DaraModel', 101 | }, 102 | RuntimeOptions: { 103 | packageName: 'darabonba.runtime', 104 | className: 'RuntimeOptions', 105 | }, 106 | DaraException: { 107 | packageName: 'darabonba.exceptions', 108 | className: 'DaraException', 109 | }, 110 | UnretryableException: { 111 | packageName: 'darabonba.exceptions', 112 | className: 'UnretryableException', 113 | }, 114 | ResponseException: { 115 | packageName: 'darabonba.exceptions', 116 | className: 'ResponseException', 117 | }, 118 | RetryPolicyContext: { 119 | packageName: 'darabonba.policy.retry', 120 | className: 'RetryPolicyContext', 121 | }, 122 | RetryOptions: { 123 | packageName: 'darabonba.policy.retry', 124 | className: 'RetryOptions', 125 | }, 126 | SSEEvent: { 127 | packageName: 'darabonba.event', 128 | className: 'Event', 129 | aliasName: 'SSEEvent' 130 | }, 131 | FileField: { 132 | packageName: 'darabonba.utils.form', 133 | className: 'FileField', 134 | }, 135 | ExtendsParameters: { 136 | packageName: 'darabonba.runtime', 137 | className: 'ExtendsParameters', 138 | }, 139 | DaraEnv: { 140 | className: 'os', 141 | }, 142 | DaraLogger: { 143 | className: 'logging', 144 | } 145 | }; 146 | 147 | function _name(str) { 148 | if (str.lexeme === '__request') { 149 | return REQUEST; 150 | } 151 | 152 | if (str.lexeme === '__response') { 153 | return RESPONSE; 154 | } 155 | 156 | if (str.lexeme === 'from') { 157 | return 'from_'; 158 | } 159 | 160 | if (str.lexeme === 'self') { 161 | return 'self_'; 162 | } 163 | 164 | return str.lexeme || str.name; 165 | } 166 | 167 | function _vid(vid) { 168 | return `_${_name(vid).substr(1)}`; 169 | } 170 | 171 | function _string(str) { 172 | if (str.string === '\'\'') { 173 | return '\\\'\\\''; 174 | } 175 | return str.string.replace(/([^\\])'+|^'/g, function (str) { 176 | return str.replace(/'/g, '\\\''); 177 | }); 178 | } 179 | 180 | function _upperFirst(str) { 181 | return str.charAt(0).toUpperCase() + str.slice(1); 182 | } 183 | function _lowerFirst(str) { 184 | return str[0].toLowerCase() + str.substring(1); 185 | } 186 | 187 | function _subModelName(name) { 188 | return name.split('.').map((name) => _upperFirst(name)).join(''); 189 | } 190 | 191 | function _avoidKeywords(str) { 192 | // 区分大小写 193 | if (keywords.indexOf(str) > -1) { 194 | return str + '_'; 195 | } 196 | return str; 197 | } 198 | 199 | function _camelCase(str, split = '_') { 200 | // 先将字符串中的下划线拆分 201 | if (str.indexOf(split) > -1) { 202 | let tmp = str.split(split); 203 | tmp = tmp.map((s, i) => { 204 | // 如果是第一个单词则不处理,其他单词首字母大写 205 | return _upperFirst(s); 206 | }); 207 | str = tmp.join(''); 208 | } else { 209 | // 如果没有下划线,对整个字符串首字母大写 210 | str = _upperFirst(str); 211 | } 212 | 213 | return str; 214 | } 215 | 216 | function _snakeCase(str) { 217 | if (!str) { 218 | return ''; 219 | } 220 | let res = ''; 221 | let tmp = ''; 222 | for (const c of str) { 223 | if (/[A-Z|0-9]/.test(c)) { 224 | tmp += c; 225 | } else { 226 | if (tmp.length > 0) { 227 | res += res === '' ? tmp.toLowerCase() : '_' + tmp.toLowerCase(); 228 | tmp = ''; 229 | } 230 | res += c; 231 | } 232 | } 233 | if (tmp.length > 0) { 234 | res += '_' + tmp.toLowerCase(); 235 | } 236 | res = res.replace(/-/g, '_'); 237 | if (res[0] === '_' && str[0] !== '_') { 238 | res = res.substring(1); 239 | } 240 | return res; 241 | } 242 | 243 | function _deepClone(obj) { 244 | return JSON.parse(JSON.stringify(obj)); 245 | } 246 | 247 | function _isSnakeCase(str) { 248 | if (/[^\da-z_]/.test(str)) { 249 | return false; 250 | } 251 | 252 | if (/\d/.test(str[0])) { 253 | return false; 254 | } 255 | 256 | return true; 257 | } 258 | 259 | function _isBasicType(type) { 260 | return DSL.util.isBasicType(type); 261 | } 262 | 263 | function _isBinaryOp(type) { 264 | const op = [ 265 | 'or', 'eq', 'neq', 266 | 'gt', 'gte', 'lt', 267 | 'lte', 'add', 'subtract', 268 | 'div', 'multi', 'and' 269 | ]; 270 | return op.includes(type); 271 | } 272 | 273 | function _isBuiltinModel(name) { 274 | return builtinModels.includes(name); 275 | } 276 | 277 | function _isDefault(expr) { 278 | if (expr.type !== 'call' || expr.left.type !== 'method_call') { 279 | return false; 280 | } 281 | const name = _name(expr.left.id); 282 | 283 | if (name !== '$default') { 284 | return false; 285 | } 286 | 287 | return true; 288 | } 289 | 290 | function _type(name) { 291 | if (name === 'string') { 292 | return 'str'; 293 | } 294 | 295 | if (name === 'boolean') { 296 | return 'bool'; 297 | } 298 | 299 | if (name === 'any') { 300 | return 'Any'; 301 | } 302 | 303 | if (name === 'void') { 304 | return 'None'; 305 | } 306 | 307 | if (name === 'integer' || name === 'number' || 308 | name === 'int8' || name === 'uint8' || 309 | name === 'int16' || name === 'uint16' || 310 | name === 'int32' || name === 'uint32' || 311 | name === 'int64' || name === 'uint64' || 312 | name === 'long' || name === 'ulong') { 313 | return 'int'; 314 | } 315 | 316 | if (name === 'float' || name === 'double') { 317 | return 'float'; 318 | } 319 | 320 | if (name === 'readable') { 321 | return 'BinaryIO'; 322 | } 323 | 324 | if (name === 'writable') { 325 | return 'BinaryIO'; 326 | } 327 | 328 | if (name === '$Request') { 329 | return `${CORE}Request`; 330 | } 331 | 332 | if (name === '$Response') { 333 | return `${CORE}Response`; 334 | } 335 | 336 | if (name === '$Model') { 337 | return `${CORE}Model`; 338 | } 339 | 340 | if (name === '$Error') { 341 | return `${CORE}Exception`; 342 | } 343 | 344 | if (name === '$SSEEvent') { 345 | return 'SSEEvent'; 346 | } 347 | 348 | if (name === '$RetryOptions') { 349 | return 'RetryOptions'; 350 | } 351 | 352 | if (name === '$RuntimeOptions') { 353 | return 'RuntimeOptions'; 354 | } 355 | 356 | if (name === '$ResponseError') { 357 | return 'ResponseError'; 358 | } 359 | 360 | if (name === '$FileField') { 361 | return 'FileField'; 362 | } 363 | 364 | if (name === '$ExtendsParameters') { 365 | return 'ExtendsParameters'; 366 | } 367 | 368 | if (name === '$Date') { 369 | return `${CORE}Date`; 370 | } 371 | 372 | if (name === '$File') { 373 | return `${CORE}File`; 374 | } 375 | 376 | if (name === '$URL') { 377 | return `${CORE}URL`; 378 | } 379 | 380 | if (name === '$Stream') { 381 | return `${CORE}Stream`; 382 | } 383 | 384 | if (name === 'object') { 385 | return 'dict'; 386 | } 387 | 388 | if (name === 'bytes') { 389 | return 'bytes'; 390 | } 391 | 392 | return name; 393 | } 394 | 395 | function _adaptedQuotes(str) { 396 | const line = str.split('\n'); 397 | let quote = '\''; 398 | if (str.indexOf('\'') !== -1 && str.indexOf('"') !== -1 || line.length > 1) { 399 | quote = '\'\'\''; 400 | } else if (str.indexOf('\'') !== -1) { 401 | quote = '"'; 402 | } 403 | return quote; 404 | } 405 | 406 | function _getImport(type) { 407 | return builtinImports[type]; 408 | } 409 | 410 | function _escape(str) { 411 | return str.includes('-') ? `'${str}'` : str; 412 | } 413 | 414 | function _removeFilesInDirectory(directoryPath) { 415 | if (!fs.existsSync(directoryPath)) { 416 | return; 417 | } 418 | const files = fs.readdirSync(directoryPath); 419 | for (const file of files) { 420 | const filePath = path.join(directoryPath, file); 421 | const stat = fs.statSync(filePath); 422 | 423 | if (stat.isDirectory()) { 424 | _removeFilesInDirectory(filePath); 425 | fs.rmdirSync(filePath); 426 | } else { 427 | fs.unlinkSync(filePath); 428 | } 429 | } 430 | } 431 | 432 | /** 433 | * 按照Python PEP 8标准对imports进行排序 434 | * @param {Array} imports - import对象数组 435 | * @returns {Array} 排序后的imports数组 436 | */ 437 | function _sortImports(imports) { 438 | function isStandardLibrary(packageName) { 439 | if (!packageName) { return false; } 440 | 441 | // 处理子模块,如 os.path -> os 442 | const rootModule = packageName.split('.')[0]; 443 | return standardLibraries.has(rootModule); 444 | } 445 | 446 | function isThirdPartyLibrary(packageName) { 447 | if (!packageName) { return false; } 448 | 449 | // 不是标准库且不是相对导入(不以.开头) 450 | return !isStandardLibrary(packageName) && !packageName.startsWith('.'); 451 | } 452 | 453 | function isLocalImport(packageName) { 454 | if (!packageName) { return false; } 455 | 456 | // 以.开头的相对导入,或者看起来像本地模块的导入 457 | return packageName.startsWith('.') || 458 | (!isStandardLibrary(packageName) && !isThirdPartyLibrary(packageName)); 459 | } 460 | 461 | function getImportPriority(importObj) { 462 | const { packageName, className } = importObj; 463 | 464 | // 1. __future__ imports (最高优先级) 465 | if (packageName === '__future__') { 466 | return 1; 467 | } 468 | 469 | // 2. 标准库 import 语句 470 | if (!packageName && isStandardLibrary(className)) { 471 | return 2; 472 | } 473 | 474 | // 3. 标准库 from...import 语句 475 | if (packageName && isStandardLibrary(packageName)) { 476 | return 3; 477 | } 478 | 479 | // 4. 第三方库 import 语句 480 | if (!packageName && isThirdPartyLibrary(className)) { 481 | return 4; 482 | } 483 | 484 | // 5. 第三方库 from...import 语句 485 | if (packageName && isThirdPartyLibrary(packageName)) { 486 | return 5; 487 | } 488 | 489 | // 6. 本地/相对 import 语句 490 | if (!packageName && isLocalImport(className)) { 491 | return 6; 492 | } 493 | 494 | // 7. 本地/相对 from...import 语句 495 | if (packageName && isLocalImport(packageName)) { 496 | return 7; 497 | } 498 | 499 | // 8. 其他情况 500 | return 8; 501 | } 502 | 503 | 504 | // 生成排序键 505 | function getSortKey(importObj) { 506 | const { packageName, className } = importObj; 507 | const priority = getImportPriority(importObj); 508 | 509 | // 构建排序键:优先级 + 包名 + 类名 510 | const sortPackage = packageName || ''; 511 | const sortClass = className || ''; 512 | 513 | return `${priority.toString().padStart(2, '0')}_${sortPackage}_${sortClass}`; 514 | } 515 | 516 | //合并同一包的from imports 517 | function mergeFromImportsByPackage(imports) { 518 | const packageGroups = new Map(); 519 | const nonFromImports = []; 520 | 521 | for (const importObj of imports) { 522 | if (importObj.packageName) { 523 | if (!packageGroups.has(importObj.packageName)) { 524 | packageGroups.set(importObj.packageName, []); 525 | } 526 | packageGroups.get(importObj.packageName).push(importObj); 527 | } else { 528 | nonFromImports.push(importObj); 529 | } 530 | } 531 | 532 | const mergedImports = [...nonFromImports]; 533 | for (const [packageName, packageImports] of packageGroups) { 534 | if (packageImports.length === 1) { 535 | mergedImports.push(packageImports[0]); 536 | } else { 537 | const canMerge = packageImports.every(imp => !imp.aliasName); 538 | 539 | if (canMerge) { 540 | const classNames = packageImports.map(imp => imp.className).sort(); 541 | mergedImports.push({ 542 | packageName: packageName, 543 | className: classNames.join(', '), 544 | aliasName: '', 545 | _isMerged: true 546 | }); 547 | } else { 548 | mergedImports.push(...packageImports); 549 | } 550 | } 551 | } 552 | 553 | return mergedImports; 554 | } 555 | 556 | 557 | const importMap = new Map(); 558 | for (const importObj of imports) { 559 | const key = `${importObj.packageName}|${importObj.className}|${importObj.aliasName}`; 560 | 561 | if (importMap.has(key)) { 562 | continue; 563 | } 564 | importMap.set(key, importObj); 565 | } 566 | 567 | 568 | const mergedImports = mergeFromImportsByPackage(Array.from(importMap.values())); 569 | 570 | // 对imports进行排序 571 | const sortedImports = [...mergedImports].sort((a, b) => { 572 | const keyA = getSortKey(a); 573 | const keyB = getSortKey(b); 574 | return keyA.localeCompare(keyB); 575 | }); 576 | 577 | return sortedImports; 578 | } 579 | 580 | // 辅助函数:将排序后的导入转换为Python代码字符串 581 | function _importsToString(sortedImports) { 582 | const lines = []; 583 | let lastPriority = -1; 584 | 585 | // 内部函数需要访问外部的getImportPriority 586 | function getImportPriority(importObj) { 587 | const { packageName, className } = importObj; 588 | 589 | function isStandardLibrary(packageName) { 590 | if (!packageName) { return false; } 591 | const rootModule = packageName.split('.')[0]; 592 | return standardLibraries.has(rootModule); 593 | } 594 | 595 | if (packageName === '__future__') { return 1; } 596 | if (!packageName && isStandardLibrary(className)) { return 2; } 597 | if (packageName && isStandardLibrary(packageName)) { return 3; } 598 | if (!packageName && !isStandardLibrary(className)) { return 4; } 599 | if (packageName && !isStandardLibrary(packageName)) { return 5; } 600 | return 6; 601 | } 602 | 603 | sortedImports.forEach(importObj => { 604 | const { packageName, className, aliasName } = importObj; 605 | const currentPriority = getImportPriority(importObj); 606 | 607 | // 在不同优先级组之间添加空行 608 | if (lastPriority !== -1 && currentPriority !== lastPriority) { 609 | lines.push(''); 610 | } 611 | 612 | // 生成import语句 613 | let importLine; 614 | if (packageName) { 615 | // from...import 语句 616 | if (aliasName) { 617 | importLine = `from ${packageName} import ${className} as ${aliasName}`; 618 | } else { 619 | importLine = `from ${packageName} import ${className}`; 620 | } 621 | } else { 622 | // import 语句 623 | if (aliasName) { 624 | importLine = `import ${className} as ${aliasName}`; 625 | } else { 626 | importLine = `import ${className}`; 627 | } 628 | } 629 | 630 | lines.push(importLine); 631 | lastPriority = currentPriority; 632 | }); 633 | 634 | return lines.join('\n'); 635 | } 636 | 637 | 638 | module.exports = { 639 | _removeFilesInDirectory, 640 | _name, 641 | _escape, 642 | _vid, 643 | _string, 644 | _upperFirst, 645 | _lowerFirst, 646 | _subModelName, 647 | _avoidKeywords, 648 | _camelCase, 649 | _snakeCase, 650 | _deepClone, 651 | _isSnakeCase, 652 | _isBasicType, 653 | _isBinaryOp, 654 | _isBuiltinModel, 655 | _isDefault, 656 | _type, 657 | _getImport, 658 | _adaptedQuotes, 659 | _sortImports, 660 | _importsToString, 661 | CORE, 662 | REQUEST, 663 | RESPONSE, 664 | EXCEPTION, 665 | RESP_EXCEPTION, 666 | MODEL, 667 | }; -------------------------------------------------------------------------------- /nyc.config.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | exclude: [ 5 | 'coverage', 6 | 'self-coverage', 7 | 'tests/*.js', 8 | 'bin/*.js', 9 | 'commands/*.js', 10 | 'source/*', 11 | 'output/*' 12 | ], 13 | branches: 100, 14 | functions: 100, 15 | lines: 100, 16 | statements: 100 17 | }; 18 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@darabonba/python-generator", 3 | "version": "2.0.12", 4 | "description": "The darabonba generator for Python", 5 | "main": "lib/generator.js", 6 | "directories": { 7 | "lib": "lib" 8 | }, 9 | "scripts": { 10 | "lint": "eslint --fix lib/ tests/", 11 | "test": "mocha -R spec -t 3000 tests/*.tests.js", 12 | "test-cov": "nyc -r=lcov -r=html -r=text -r=json npm run test", 13 | "ci": "npm run lint && npm run test-cov" 14 | }, 15 | "repository": { 16 | "type": "git", 17 | "url": "git@github.com:aliyun/darabonba-python-generator.git" 18 | }, 19 | "devDependencies": { 20 | "chai": "^4.2.0", 21 | "eslint": "^8.55.0", 22 | "expect.js": "^0.3.1", 23 | "has-flag": "^5.0.1", 24 | "mm": "^3.2.0", 25 | "mocha": "^10.2.0", 26 | "mocha-sinon": "^2.1.2", 27 | "nyc": "^15.1.0", 28 | "sinon": "^9.2.1" 29 | }, 30 | "author": "Alibaba Cloud OpenAPI Team", 31 | "license": "Apache-2.0", 32 | "dependencies": { 33 | "@darabonba/annotation-parser": "^1.0.1", 34 | "@darabonba/parser": "^2.1.4", 35 | "enum": "^3.0.4" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /tests/expected/alias/.gitignore: -------------------------------------------------------------------------------- 1 | runtime/ 2 | .idea/ 3 | .vscode/ 4 | __pycache__/ 5 | .pytest_cache/ -------------------------------------------------------------------------------- /tests/expected/alias/setup.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Licensed to the Apache Software Foundation (ASF) under one 4 | or more contributor license agreements. See the NOTICE file 5 | distributed with this work for additional information 6 | regarding copyright ownership. The ASF licenses this file 7 | to you under the Apache License, Version 2.0 (the 8 | "License"); you may not use this file except in compliance 9 | with the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, 14 | software distributed under the License is distributed on an 15 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | KIND, either express or implied. See the License for the 17 | specific language governing permissions and limitations 18 | under the License. 19 | """ 20 | 21 | import os 22 | from setuptools import setup, find_packages 23 | 24 | """ 25 | setup module for tea-python-tests. 26 | 27 | Created on * 28 | 29 | @author: AlibabaCloud SDK Team 30 | """ 31 | 32 | PACKAGE = "tea_python_tests" 33 | NAME = "tea-python-tests" 34 | DESCRIPTION = "Generate setup.py" 35 | AUTHOR = "AlibabaCloud SDK Team" 36 | AUTHOR_EMAIL = "sdkteam@alibabacloud.com" 37 | URL = "https://github.com/dara" 38 | VERSION = __import__(PACKAGE).__version__ 39 | REQUIRES = [ 40 | "darabonba-core>=1.0.0, <2.0.0", 41 | "source>=0.0.1, <1.0.0", 42 | "import>=1.1.2, <2.0.0", 43 | "alibabacloud_tea_util>=0.3.11, <1.0.0", 44 | "xxx1>=0.0.1, <1.0.0", 45 | "xxx2>=0.0.1, <1.0.0" 46 | ] 47 | 48 | LONG_DESCRIPTION = '' 49 | if os.path.exists('./README.md'): 50 | with open("README.md", encoding='utf-8') as fp: 51 | LONG_DESCRIPTION = fp.read() 52 | 53 | setup( 54 | name=NAME, 55 | version=VERSION, 56 | description=DESCRIPTION, 57 | long_description=LONG_DESCRIPTION, 58 | long_description_content_type='text/markdown', 59 | author=AUTHOR, 60 | author_email=AUTHOR_EMAIL, 61 | license="Apache License 2.0", 62 | url=URL, 63 | keywords=["tea","python","tests"], 64 | packages=find_packages(exclude=["tests*"]), 65 | include_package_data=True, 66 | platforms="any", 67 | install_requires=REQUIRES, 68 | python_requires=">=3.7", 69 | classifiers=( 70 | "Development Status :: 4 - Beta", 71 | "Intended Audience :: Developers", 72 | "License :: OSI Approved :: Apache Software License", 73 | "Programming Language :: Python", 74 | "Programming Language :: Python :: 3", 75 | "Programming Language :: Python :: 3.7", 76 | "Programming Language :: Python :: 3.8", 77 | "Programming Language :: Python :: 3.9", 78 | "Programming Language :: Python :: 3.10", 79 | "Programming Language :: Python :: 3.11", 80 | "Programming Language :: Python :: 3.12", 81 | "Topic :: Software Development" 82 | ) 83 | ) -------------------------------------------------------------------------------- /tests/expected/alias/tea_python_tests/__init__.py: -------------------------------------------------------------------------------- 1 | __version__ = "1.0.0" 2 | -------------------------------------------------------------------------------- /tests/expected/alias/tea_python_tests/client.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from alias_source.source_client import SourceClient as AliasSourceSourceClient 6 | from alias_symbol import models as alias_symbol_models 7 | from alias_symbol.client import Client as AliasSymbolClient 8 | from Alias.alias_client import AliasClient 9 | from Import.client import Client as ImportClient 10 | from Source.client import Client as SourceClient 11 | 12 | 13 | 14 | class Client: 15 | 16 | def __init__(self): 17 | pass 18 | 19 | @staticmethod 20 | def empty_model() -> None: 21 | ImportClient.test() 22 | SourceClient.test() 23 | AliasClient.test() 24 | AliasSourceSourceClient.test() 25 | AliasSymbolClient.test() 26 | model = alias_symbol_models.TestModel() 27 | 28 | @staticmethod 29 | async def empty_model_async() -> None: 30 | ImportClient.test() 31 | await SourceClient.test_async() 32 | AliasClient.test() 33 | AliasSourceSourceClient.test() 34 | AliasSymbolClient.test() 35 | model = alias_symbol_models.TestModel() 36 | -------------------------------------------------------------------------------- /tests/expected/annotation/tea_python_tests/__init__.py: -------------------------------------------------------------------------------- 1 | __version__ = "1.0.0" 2 | -------------------------------------------------------------------------------- /tests/expected/annotation/tea_python_tests/client.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from darabonba.core import DaraCore 6 | from darabonba.exceptions import UnretryableException 7 | from darabonba.policy.retry import RetryPolicyContext 8 | from darabonba.request import DaraRequest 9 | 10 | """ 11 | * @remarks 12 | * top annotation 13 | """ 14 | class Client: 15 | _a: str = None 16 | def __init__(self): 17 | pass 18 | 19 | """ 20 | * @remarks 21 | * testAPI 22 | """ 23 | def test_api(self) -> None: 24 | _runtime = { 25 | } 26 | _last_request = None 27 | _last_response = None 28 | _retries_attempted = 0 29 | _context = RetryPolicyContext( 30 | retries_attempted= _retries_attempted 31 | ) 32 | while DaraCore.should_retry(_runtime.get('retryOptions'), _context): 33 | if _retries_attempted > 0: 34 | _backoff_time = DaraCore.get_backoff_time(_runtime.get('retryOptions'), _context) 35 | if _backoff_time > 0: 36 | DaraCore.sleep(_backoff_time) 37 | _retries_attempted = _retries_attempted + 1 38 | try: 39 | _request = DaraRequest() 40 | pass 41 | _last_request = _request 42 | _response = DaraCore.do_action(_request, _runtime) 43 | _last_response = _response 44 | return 45 | except Exception as e: 46 | _context = RetryPolicyContext( 47 | retries_attempted= _retries_attempted, 48 | http_request = _last_request, 49 | http_response = _last_response, 50 | exception = e 51 | ) 52 | continue 53 | raise UnretryableException(_context) 54 | 55 | async def test_api_async(self) -> None: 56 | _runtime = { 57 | } 58 | _last_request = None 59 | _last_response = None 60 | _retries_attempted = 0 61 | _context = RetryPolicyContext( 62 | retries_attempted= _retries_attempted 63 | ) 64 | while DaraCore.should_retry(_runtime.get('retryOptions'), _context): 65 | if _retries_attempted > 0: 66 | _backoff_time = DaraCore.get_backoff_time(_runtime.get('retryOptions'), _context) 67 | if _backoff_time > 0: 68 | DaraCore.sleep(_backoff_time) 69 | _retries_attempted = _retries_attempted + 1 70 | try: 71 | _request = DaraRequest() 72 | pass 73 | _last_request = _request 74 | _response = await DaraCore.async_do_action(_request, _runtime) 75 | _last_response = _response 76 | return 77 | except Exception as e: 78 | _context = RetryPolicyContext( 79 | retries_attempted= _retries_attempted, 80 | http_request = _last_request, 81 | http_response = _last_response, 82 | exception = e 83 | ) 84 | continue 85 | raise UnretryableException(_context) 86 | 87 | @staticmethod 88 | def test_func() -> None: 89 | pass 90 | 91 | @staticmethod 92 | async def test_func_async() -> None: 93 | pass 94 | -------------------------------------------------------------------------------- /tests/expected/annotation/tea_python_tests/models/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from ._test import Test 6 | 7 | __all__ = [ 8 | Test 9 | ] 10 | -------------------------------------------------------------------------------- /tests/expected/annotation/tea_python_tests/models/_test.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from darabonba.model import DaraModel 6 | 7 | """ 8 | * @remarks 9 | * TestModel 10 | """ 11 | class Test(DaraModel): 12 | def __init__( 13 | self, 14 | test: str = None, 15 | ): 16 | # Alichange app id 17 | self.test = test 18 | 19 | def validate(self): 20 | self.validate_required(self.test, 'test') 21 | 22 | def to_map(self): 23 | result = dict() 24 | _map = super().to_map() 25 | if _map is not None: 26 | result = _map 27 | if self.test is not None: 28 | result['test'] = self.test 29 | 30 | return result 31 | 32 | def from_map(self, m: dict = None): 33 | m = m or dict() 34 | if m.get('test') is not None: 35 | self.test = m.get('test') 36 | 37 | return self 38 | 39 | -------------------------------------------------------------------------------- /tests/expected/api/tea_python_tests/__init__.py: -------------------------------------------------------------------------------- 1 | __version__ = "1.0.0" 2 | -------------------------------------------------------------------------------- /tests/expected/api/tea_python_tests/client.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from darabonba.core import DaraCore 6 | from darabonba.exceptions import UnretryableException 7 | from darabonba.policy.retry import RetryPolicyContext 8 | from darabonba.request import DaraRequest 9 | 10 | class Client: 11 | def __init__(self): 12 | pass 13 | 14 | def hello(self) -> None: 15 | _request = DaraRequest() 16 | _request.method = 'GET' 17 | _request.pathname = '/' 18 | _request.headers = { 19 | 'host': 'www.test.com' 20 | } 21 | _last_request = _request 22 | _response = DaraCore.do_action(_request) 23 | return 24 | 25 | async def hello_async(self) -> None: 26 | _request = DaraRequest() 27 | _request.method = 'GET' 28 | _request.pathname = '/' 29 | _request.headers = { 30 | 'host': 'www.test.com' 31 | } 32 | _last_request = _request 33 | _response = await DaraCore.async_do_action(_request) 34 | return 35 | 36 | def hello_runtime(self) -> None: 37 | _runtime = { 38 | } 39 | _last_request = None 40 | _last_response = None 41 | _retries_attempted = 0 42 | _context = RetryPolicyContext( 43 | retries_attempted= _retries_attempted 44 | ) 45 | while DaraCore.should_retry(_runtime.get('retryOptions'), _context): 46 | if _retries_attempted > 0: 47 | _backoff_time = DaraCore.get_backoff_time(_runtime.get('retryOptions'), _context) 48 | if _backoff_time > 0: 49 | DaraCore.sleep(_backoff_time) 50 | _retries_attempted = _retries_attempted + 1 51 | try: 52 | _request = DaraRequest() 53 | _request.method = 'GET' 54 | _request.pathname = '/' 55 | _request.headers = { 56 | 'host': 'www.test.com' 57 | } 58 | _last_request = _request 59 | _response = DaraCore.do_action(_request, _runtime) 60 | _last_response = _response 61 | return 62 | except Exception as e: 63 | _context = RetryPolicyContext( 64 | retries_attempted= _retries_attempted, 65 | http_request = _last_request, 66 | http_response = _last_response, 67 | exception = e 68 | ) 69 | continue 70 | raise UnretryableException(_context) 71 | 72 | async def hello_runtime_async(self) -> None: 73 | _runtime = { 74 | } 75 | _last_request = None 76 | _last_response = None 77 | _retries_attempted = 0 78 | _context = RetryPolicyContext( 79 | retries_attempted= _retries_attempted 80 | ) 81 | while DaraCore.should_retry(_runtime.get('retryOptions'), _context): 82 | if _retries_attempted > 0: 83 | _backoff_time = DaraCore.get_backoff_time(_runtime.get('retryOptions'), _context) 84 | if _backoff_time > 0: 85 | DaraCore.sleep(_backoff_time) 86 | _retries_attempted = _retries_attempted + 1 87 | try: 88 | _request = DaraRequest() 89 | _request.method = 'GET' 90 | _request.pathname = '/' 91 | _request.headers = { 92 | 'host': 'www.test.com' 93 | } 94 | _last_request = _request 95 | _response = await DaraCore.async_do_action(_request, _runtime) 96 | _last_response = _response 97 | return 98 | except Exception as e: 99 | _context = RetryPolicyContext( 100 | retries_attempted= _retries_attempted, 101 | http_request = _last_request, 102 | http_response = _last_response, 103 | exception = e 104 | ) 105 | continue 106 | raise UnretryableException(_context) 107 | -------------------------------------------------------------------------------- /tests/expected/comment/tea_python_tests/__init__.py: -------------------------------------------------------------------------------- 1 | __version__ = "1.0.0" 2 | -------------------------------------------------------------------------------- /tests/expected/comment/tea_python_tests/client.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from typing import List, Dict, BinaryIO, Any 6 | 7 | from darabonba.core import DaraCore 8 | from darabonba.exceptions import UnretryableException 9 | from darabonba.policy.retry import RetryPolicyContext 10 | from darabonba.request import DaraRequest 11 | from tea_python_tests import models as main_models 12 | 13 | # top comment 14 | """ 15 | * @remarks 16 | * top annotation 17 | """ 18 | class Client: 19 | # type's comment 20 | _a: List[str] = None 21 | _comple_list: List[List[str]] = None 22 | _endpoint_map: Dict[str, str] = None 23 | def __init__(self): 24 | # string declate comment 25 | str = 'sss' 26 | # new model instance comment 27 | model_instance = main_models.Test1( 28 | test = 'test', 29 | # est declare back comment 30 | test_2 = 'test2' 31 | ) 32 | array = [ 33 | # array string comment 34 | 'string', 35 | # array number comment 36 | 300 37 | # array back comment 38 | ] 39 | 40 | """ 41 | * @remarks 42 | * testAPI 43 | """ 44 | # estAPI comment one 45 | # estAPI comment two 46 | def test_api(self) -> None: 47 | _runtime = { 48 | } 49 | _last_request = None 50 | _last_response = None 51 | _retries_attempted = 0 52 | _context = RetryPolicyContext( 53 | retries_attempted= _retries_attempted 54 | ) 55 | while DaraCore.should_retry(_runtime.get('retryOptions'), _context): 56 | if _retries_attempted > 0: 57 | _backoff_time = DaraCore.get_backoff_time(_runtime.get('retryOptions'), _context) 58 | if _backoff_time > 0: 59 | DaraCore.sleep(_backoff_time) 60 | _retries_attempted = _retries_attempted + 1 61 | try: 62 | _request = DaraRequest() 63 | # new model instance comment 64 | model_instance = main_models.Test1( 65 | # test declare front comment 66 | test = 'test', 67 | # test2 declare front comment 68 | test_2 = 'test2' 69 | ) 70 | # number declare comment 71 | num = 123 72 | # static function call comment 73 | self.static_func() 74 | _last_request = _request 75 | _response = DaraCore.do_action(_request, _runtime) 76 | _last_response = _response 77 | # static async function call 78 | self.test_func('test', True, [ 79 | [ 80 | 'str' 81 | ], 82 | [ 83 | 'str1' 84 | ] 85 | ]) 86 | # return comment 87 | return 88 | except Exception as e: 89 | _context = RetryPolicyContext( 90 | retries_attempted= _retries_attempted, 91 | http_request = _last_request, 92 | http_response = _last_response, 93 | exception = e 94 | ) 95 | continue 96 | raise UnretryableException(_context) 97 | 98 | async def test_api_async(self) -> None: 99 | _runtime = { 100 | } 101 | _last_request = None 102 | _last_response = None 103 | _retries_attempted = 0 104 | _context = RetryPolicyContext( 105 | retries_attempted= _retries_attempted 106 | ) 107 | while DaraCore.should_retry(_runtime.get('retryOptions'), _context): 108 | if _retries_attempted > 0: 109 | _backoff_time = DaraCore.get_backoff_time(_runtime.get('retryOptions'), _context) 110 | if _backoff_time > 0: 111 | DaraCore.sleep(_backoff_time) 112 | _retries_attempted = _retries_attempted + 1 113 | try: 114 | _request = DaraRequest() 115 | # new model instance comment 116 | model_instance = main_models.Test1( 117 | # test declare front comment 118 | test = 'test', 119 | # test2 declare front comment 120 | test_2 = 'test2' 121 | ) 122 | # number declare comment 123 | num = 123 124 | # static function call comment 125 | self.static_func() 126 | _last_request = _request 127 | _response = await DaraCore.async_do_action(_request, _runtime) 128 | _last_response = _response 129 | # static async function call 130 | await self.test_func_async('test', True, [ 131 | [ 132 | 'str' 133 | ], 134 | [ 135 | 'str1' 136 | ] 137 | ]) 138 | # return comment 139 | return 140 | except Exception as e: 141 | _context = RetryPolicyContext( 142 | retries_attempted= _retries_attempted, 143 | http_request = _last_request, 144 | http_response = _last_response, 145 | exception = e 146 | ) 147 | continue 148 | raise UnretryableException(_context) 149 | 150 | # testAPI2 comment 151 | def test_api2(self) -> None: 152 | _runtime = { 153 | 'retry': True, 154 | } 155 | _last_request = None 156 | _last_response = None 157 | _retries_attempted = 0 158 | _context = RetryPolicyContext( 159 | retries_attempted= _retries_attempted 160 | ) 161 | while DaraCore.should_retry(_runtime.get('retryOptions'), _context): 162 | if _retries_attempted > 0: 163 | _backoff_time = DaraCore.get_backoff_time(_runtime.get('retryOptions'), _context) 164 | if _backoff_time > 0: 165 | DaraCore.sleep(_backoff_time) 166 | _retries_attempted = _retries_attempted + 1 167 | try: 168 | _request = DaraRequest() 169 | # new model instance comment 170 | model_instance = main_models.Test3() 171 | # boolean declare comment 172 | bool = True 173 | if bool: 174 | # mpty if 175 | pass 176 | else: 177 | # mpty else 178 | pass 179 | # api function call comment 180 | self.test_api() 181 | # back comment 182 | _last_request = _request 183 | _response = DaraCore.do_action(_request, _runtime) 184 | _last_response = _response 185 | # empty return comment 186 | pass 187 | except Exception as e: 188 | _context = RetryPolicyContext( 189 | retries_attempted= _retries_attempted, 190 | http_request = _last_request, 191 | http_response = _last_response, 192 | exception = e 193 | ) 194 | continue 195 | raise UnretryableException(_context) 196 | 197 | async def test_api2_async(self) -> None: 198 | _runtime = { 199 | 'retry': True, 200 | } 201 | _last_request = None 202 | _last_response = None 203 | _retries_attempted = 0 204 | _context = RetryPolicyContext( 205 | retries_attempted= _retries_attempted 206 | ) 207 | while DaraCore.should_retry(_runtime.get('retryOptions'), _context): 208 | if _retries_attempted > 0: 209 | _backoff_time = DaraCore.get_backoff_time(_runtime.get('retryOptions'), _context) 210 | if _backoff_time > 0: 211 | DaraCore.sleep(_backoff_time) 212 | _retries_attempted = _retries_attempted + 1 213 | try: 214 | _request = DaraRequest() 215 | # new model instance comment 216 | model_instance = main_models.Test3() 217 | # boolean declare comment 218 | bool = True 219 | if bool: 220 | # mpty if 221 | pass 222 | else: 223 | # mpty else 224 | pass 225 | # api function call comment 226 | await self.test_api_async() 227 | # back comment 228 | _last_request = _request 229 | _response = await DaraCore.async_do_action(_request, _runtime) 230 | _last_response = _response 231 | # empty return comment 232 | pass 233 | except Exception as e: 234 | _context = RetryPolicyContext( 235 | retries_attempted= _retries_attempted, 236 | http_request = _last_request, 237 | http_response = _last_response, 238 | exception = e 239 | ) 240 | continue 241 | raise UnretryableException(_context) 242 | 243 | @staticmethod 244 | def static_func() -> None: 245 | a = [ 246 | # empty annotation comment 247 | ] 248 | 249 | @staticmethod 250 | def test_func( 251 | str: str, 252 | val: bool, 253 | comple_list: List[List[str]], 254 | ) -> str: 255 | # empty comment1 256 | # empty comment2 257 | s = 'test' 258 | return s 259 | 260 | @staticmethod 261 | async def test_func_async( 262 | str: str, 263 | val: bool, 264 | comple_list: List[List[str]], 265 | ) -> str: 266 | # empty comment1 267 | # empty comment2 268 | s = 'test' 269 | return s 270 | 271 | @staticmethod 272 | def test_func_params( 273 | comple_list: List[List[str]], 274 | map_test: Dict[str, str], 275 | read: BinaryIO, 276 | any_test: Any, 277 | test_1: main_models.Test1, 278 | ) -> None: 279 | pass 280 | 281 | @staticmethod 282 | async def test_func_params_async( 283 | comple_list: List[List[str]], 284 | map_test: Dict[str, str], 285 | read: BinaryIO, 286 | any_test: Any, 287 | test_1: main_models.Test1, 288 | ) -> None: 289 | pass 290 | -------------------------------------------------------------------------------- /tests/expected/comment/tea_python_tests/models/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from ._test_1 import Test1 6 | from ._test_2 import Test2 7 | from ._test_3 import Test3 8 | 9 | __all__ = [ 10 | Test1, 11 | Test2, 12 | Test3 13 | ] 14 | -------------------------------------------------------------------------------- /tests/expected/comment/tea_python_tests/models/_test_1.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from typing import List 6 | 7 | from darabonba.model import DaraModel 8 | 9 | # import comment 10 | 11 | 12 | """ 13 | * @remarks 14 | * TestModel 15 | """ 16 | class Test1(DaraModel): 17 | def __init__( 18 | self, 19 | test: str = None, 20 | # odel的test back comment 21 | test_2: str = None, 22 | # odel的test2 back comment 23 | test_3: List[List[str]] = None, 24 | test_5: str = None, 25 | sts: str = None, 26 | a_sts: str = None, 27 | ): 28 | # test desc 29 | self.test = test 30 | # odel的test back comment 31 | # test2 desc 32 | self.test_2 = test_2 33 | # odel的test2 back comment 34 | # test3 desc 35 | self.test_3 = test_3 36 | # test desc 37 | self.test_5 = test_5 38 | # sts desc 39 | self.sts = sts 40 | # asts desc 41 | self.a_sts = a_sts 42 | 43 | def validate(self): 44 | self.validate_required(self.test, 'test') 45 | # odel的test back comment 46 | self.validate_required(self.test_2, 'test_2') 47 | # odel的test2 back comment 48 | self.validate_required(self.test_3, 'test_3') 49 | self.validate_required(self.test_5, 'test_5') 50 | self.validate_required(self.sts, 'sts') 51 | self.validate_required(self.a_sts, 'a_sts') 52 | 53 | def to_map(self): 54 | result = dict() 55 | _map = super().to_map() 56 | if _map is not None: 57 | result = _map 58 | if self.test is not None: 59 | result['test'] = self.test 60 | 61 | # odel的test back comment 62 | if self.test_2 is not None: 63 | result['test2'] = self.test_2 64 | 65 | # odel的test2 back comment 66 | if self.test_3 is not None: 67 | result['test3'] = self.test_3 68 | 69 | if self.test_5 is not None: 70 | result['test5'] = self.test_5 71 | 72 | if self.sts is not None: 73 | result['sts'] = self.sts 74 | 75 | if self.a_sts is not None: 76 | result['asts'] = self.a_sts 77 | 78 | return result 79 | 80 | def from_map(self, m: dict = None): 81 | m = m or dict() 82 | if m.get('test') is not None: 83 | self.test = m.get('test') 84 | 85 | # odel的test back comment 86 | if m.get('test2') is not None: 87 | self.test_2 = m.get('test2') 88 | 89 | # odel的test2 back comment 90 | if m.get('test3') is not None: 91 | self.test_3 = m.get('test3') 92 | 93 | if m.get('test5') is not None: 94 | self.test_5 = m.get('test5') 95 | 96 | if m.get('sts') is not None: 97 | self.sts = m.get('sts') 98 | 99 | if m.get('asts') is not None: 100 | self.a_sts = m.get('asts') 101 | 102 | return self 103 | 104 | -------------------------------------------------------------------------------- /tests/expected/comment/tea_python_tests/models/_test_2.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from darabonba.model import DaraModel 6 | 7 | """ 8 | * @remarks 9 | * TestModel2 10 | """ 11 | class Test2(DaraModel): 12 | def __init__( 13 | self, 14 | # model的test front comment 15 | test: str = None, 16 | # model的test front comment 17 | test_2: str = None, 18 | ): 19 | # model的test front comment 20 | # test desc 21 | self.test = test 22 | # model的test front comment 23 | # test2 desc 24 | self.test_2 = test_2 25 | 26 | def validate(self): 27 | # model的test front comment 28 | self.validate_required(self.test, 'test') 29 | # model的test front comment 30 | self.validate_required(self.test_2, 'test_2') 31 | 32 | def to_map(self): 33 | result = dict() 34 | _map = super().to_map() 35 | if _map is not None: 36 | result = _map 37 | # model的test front comment 38 | if self.test is not None: 39 | result['test'] = self.test 40 | 41 | # model的test front comment 42 | if self.test_2 is not None: 43 | result['test2'] = self.test_2 44 | 45 | return result 46 | 47 | def from_map(self, m: dict = None): 48 | m = m or dict() 49 | # model的test front comment 50 | if m.get('test') is not None: 51 | self.test = m.get('test') 52 | 53 | # model的test front comment 54 | if m.get('test2') is not None: 55 | self.test_2 = m.get('test2') 56 | 57 | return self 58 | 59 | -------------------------------------------------------------------------------- /tests/expected/comment/tea_python_tests/models/_test_3.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from darabonba.model import DaraModel 6 | 7 | """ 8 | * @remarks 9 | * TestModel3 10 | """ 11 | class Test3(DaraModel): 12 | def __init__( 13 | self, 14 | # model的test front comment 15 | test: str = None, 16 | # empty comment1 17 | # empy comment2 18 | test_1: str = None, 19 | ): 20 | # model的test front comment 21 | # test desc 22 | self.test = test 23 | # empty comment1 24 | # empy comment2 25 | # test desc 26 | self.test_1 = test_1 27 | 28 | def validate(self): 29 | # model的test front comment 30 | self.validate_required(self.test, 'test') 31 | # empty comment1 32 | # empy comment2 33 | self.validate_required(self.test_1, 'test_1') 34 | 35 | def to_map(self): 36 | result = dict() 37 | _map = super().to_map() 38 | if _map is not None: 39 | result = _map 40 | # model的test front comment 41 | if self.test is not None: 42 | result['test'] = self.test 43 | 44 | # empty comment1 45 | # empy comment2 46 | if self.test_1 is not None: 47 | result['test1'] = self.test_1 48 | 49 | return result 50 | 51 | def from_map(self, m: dict = None): 52 | m = m or dict() 53 | # model的test front comment 54 | if m.get('test') is not None: 55 | self.test = m.get('test') 56 | 57 | # empty comment1 58 | # empy comment2 59 | if m.get('test1') is not None: 60 | self.test_1 = m.get('test1') 61 | 62 | return self 63 | 64 | # odel的test back comment 65 | -------------------------------------------------------------------------------- /tests/expected/complex/tea_python_tests/__init__.py: -------------------------------------------------------------------------------- 1 | __version__ = "1.0.0" 2 | -------------------------------------------------------------------------------- /tests/expected/complex/tea_python_tests/exceptions/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from ._err_1 import Err1Exception 6 | from ._err_2 import Err2Exception 7 | 8 | __all__ = [ 9 | Err1Exception, 10 | Err2Exception 11 | ] 12 | -------------------------------------------------------------------------------- /tests/expected/complex/tea_python_tests/exceptions/_err_1.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from typing import Dict 6 | 7 | from darabonba.exceptions import DaraException 8 | 9 | class Err1Exception(DaraException): 10 | def __init__( 11 | self, 12 | message: str = None, 13 | code: str = None, 14 | stack: str = None, 15 | data: Dict[str, str] = None, 16 | ): 17 | super().__init__({ 18 | 'message': message, 19 | 'code': code, 20 | 'stack': stack, 21 | }) 22 | self.name = 'Err1Exception' 23 | self.data = data 24 | 25 | -------------------------------------------------------------------------------- /tests/expected/complex/tea_python_tests/exceptions/_err_2.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from darabonba.exceptions import DaraException 6 | 7 | class Err2Exception(DaraException): 8 | def __init__( 9 | self, 10 | message: str = None, 11 | code: str = None, 12 | stack: str = None, 13 | access_err_message: str = None, 14 | ): 15 | super().__init__({ 16 | 'message': message, 17 | 'code': code, 18 | 'stack': stack, 19 | }) 20 | self.name = 'Err2Exception' 21 | self.access_err_message = access_err_message 22 | 23 | -------------------------------------------------------------------------------- /tests/expected/complex/tea_python_tests/models/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from ._complex_request import ComplexRequest 6 | from ._response import Response 7 | from ._complex_request import ComplexRequestHeader 8 | from ._complex_request import ComplexRequestConfigs 9 | from ._complex_request import ComplexRequestPart 10 | 11 | __all__ = [ 12 | ComplexRequest, 13 | Response, 14 | ComplexRequestHeader, 15 | ComplexRequestConfigs, 16 | ComplexRequestPart 17 | ] 18 | -------------------------------------------------------------------------------- /tests/expected/complex/tea_python_tests/models/_response.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from darabonba.model import DaraModel 6 | from tea_python_tests import models as main_models 7 | 8 | class Response(DaraModel): 9 | def __init__( 10 | self, 11 | instance: main_models.ComplexRequestPart = None, 12 | ): 13 | self.instance = instance 14 | 15 | def validate(self): 16 | self.validate_required(self.instance, 'instance') 17 | 18 | def to_map(self): 19 | result = dict() 20 | _map = super().to_map() 21 | if _map is not None: 22 | result = _map 23 | if self.instance is not None: 24 | result['instance'] = self.instance 25 | 26 | return result 27 | 28 | def from_map(self, m: dict = None): 29 | m = m or dict() 30 | if m.get('instance') is not None: 31 | self.instance = m.get('instance') 32 | 33 | return self 34 | 35 | -------------------------------------------------------------------------------- /tests/expected/const/tea_python_tests/__init__.py: -------------------------------------------------------------------------------- 1 | __version__ = "1.0.0" 2 | -------------------------------------------------------------------------------- /tests/expected/const/tea_python_tests/client.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | class Client: 6 | 7 | def __init__(self): 8 | pass 9 | 10 | @staticmethod 11 | def hello() -> str: 12 | return f"'Hello' {'World!'}" 13 | -------------------------------------------------------------------------------- /tests/expected/empty/.gitignore: -------------------------------------------------------------------------------- 1 | runtime/ 2 | .idea/ 3 | .vscode/ 4 | __pycache__/ 5 | .pytest_cache/ -------------------------------------------------------------------------------- /tests/expected/empty/setup.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Licensed to the Apache Software Foundation (ASF) under one 4 | or more contributor license agreements. See the NOTICE file 5 | distributed with this work for additional information 6 | regarding copyright ownership. The ASF licenses this file 7 | to you under the Apache License, Version 2.0 (the 8 | "License"); you may not use this file except in compliance 9 | with the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, 14 | software distributed under the License is distributed on an 15 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | KIND, either express or implied. See the License for the 17 | specific language governing permissions and limitations 18 | under the License. 19 | """ 20 | 21 | import os 22 | from setuptools import setup, find_packages 23 | 24 | """ 25 | setup module for tea_python_tests. 26 | 27 | Created on 24/12/2020 28 | 29 | @author: Alibaba 30 | """ 31 | 32 | PACKAGE = "tea_python_tests" 33 | NAME = "tea_python_tests" or "alibabacloud-package" 34 | DESCRIPTION = "Generate setup.py" 35 | AUTHOR = "Alibaba" 36 | AUTHOR_EMAIL = "sdk-team@alibabacloud.com" 37 | URL = "https://github.com/" 38 | VERSION = __import__(PACKAGE).__version__ 39 | REQUIRES = [] 40 | 41 | LONG_DESCRIPTION = '' 42 | if os.path.exists('./README.md'): 43 | with open("README.md", encoding='utf-8') as fp: 44 | LONG_DESCRIPTION = fp.read() 45 | 46 | setup( 47 | name=NAME, 48 | version=VERSION, 49 | description=DESCRIPTION, 50 | long_description=LONG_DESCRIPTION, 51 | long_description_content_type='text/markdown', 52 | author=AUTHOR, 53 | author_email=AUTHOR_EMAIL, 54 | license="Apache License 2.0", 55 | url=URL, 56 | keywords=["tea","python","tests"], 57 | packages=find_packages(exclude=["tests*"]), 58 | include_package_data=True, 59 | platforms="any", 60 | install_requires=REQUIRES, 61 | python_requires=">=3.6", 62 | classifiers=( 63 | "Development Status :: 4 - Beta", 64 | "Intended Audience :: Developers", 65 | "License :: OSI Approved :: Apache Software License", 66 | "Programming Language :: Python", 67 | "Programming Language :: Python :: 3", 68 | "Programming Language :: Python :: 3.6", 69 | 'Programming Language :: Python :: 3.7', 70 | 'Programming Language :: Python :: 3.8', 71 | 'Programming Language :: Python :: 3.9', 72 | "Topic :: Software Development" 73 | ) 74 | ) 75 | -------------------------------------------------------------------------------- /tests/expected/empty/tea_python_tests/__init__.py: -------------------------------------------------------------------------------- 1 | __version__ = "1.0.0" 2 | -------------------------------------------------------------------------------- /tests/expected/empty/tea_python_tests/client.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | class Client: 6 | 7 | def __init__(self): 8 | pass 9 | -------------------------------------------------------------------------------- /tests/expected/exec/tea_python_tests/__init__.py: -------------------------------------------------------------------------------- 1 | __version__ = "1.0.0" 2 | -------------------------------------------------------------------------------- /tests/expected/exec/tea_python_tests/exec_client.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | import sys 6 | 7 | from typing import List 8 | 9 | class ExecClient: 10 | 11 | def __init__(self): 12 | pass 13 | 14 | @staticmethod 15 | def main( 16 | args: List[str], 17 | ) -> None: 18 | pass 19 | 20 | 21 | if __name__ == '__main__': 22 | ExecClient.main(sys.argv[1:]) 23 | -------------------------------------------------------------------------------- /tests/expected/function/tea_python_tests/__init__.py: -------------------------------------------------------------------------------- 1 | __version__ = "1.0.0" 2 | -------------------------------------------------------------------------------- /tests/expected/function/tea_python_tests/client.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from typing import Dict, List 6 | 7 | from darabonba.core import DaraCore 8 | 9 | class Client: 10 | def __init__(self): 11 | pass 12 | 13 | @staticmethod 14 | def hello() -> None: 15 | return 16 | 17 | @staticmethod 18 | def hello_map() -> Dict[str, str]: 19 | m = {} 20 | return DaraCore.merge({ 21 | 'key': 'value', 22 | 'key-1': 'value-1', 23 | 'key-2': 'value-2', 24 | '': 'value-3', 25 | }, m) 26 | 27 | @staticmethod 28 | def hello_array_map() -> List[Dict[str, str]]: 29 | return [ 30 | { 31 | 'key': 'value' 32 | } 33 | ] 34 | 35 | @staticmethod 36 | def hello_params( 37 | a: str, 38 | b: str, 39 | ) -> None: 40 | Client.hello_interface() 41 | Client.hello_array_map() 42 | 43 | @staticmethod 44 | async def hello_params_async( 45 | a: str, 46 | b: str, 47 | ) -> None: 48 | await Client.hello_interface_async() 49 | Client.hello_array_map() 50 | 51 | @staticmethod 52 | def hello_interface() -> None: 53 | # interface mode 54 | raise Exception('Un-implemented') 55 | 56 | @staticmethod 57 | async def hello_interface_async() -> None: 58 | # interface mode 59 | raise Exception('Un-implemented') 60 | 61 | def a_params(self) -> None: 62 | self.hello_params('a', 'b') 63 | 64 | async def a_params_async(self) -> None: 65 | await self.hello_params_async('a', 'b') 66 | -------------------------------------------------------------------------------- /tests/expected/import/setup.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Licensed to the Apache Software Foundation (ASF) under one 4 | or more contributor license agreements. See the NOTICE file 5 | distributed with this work for additional information 6 | regarding copyright ownership. The ASF licenses this file 7 | to you under the Apache License, Version 2.0 (the 8 | "License"); you may not use this file except in compliance 9 | with the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, 14 | software distributed under the License is distributed on an 15 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | KIND, either express or implied. See the License for the 17 | specific language governing permissions and limitations 18 | under the License. 19 | """ 20 | 21 | import os 22 | from setuptools import setup, find_packages 23 | 24 | """ 25 | setup module for tea_python_tests. 26 | 27 | Created on * 28 | 29 | @author: Alibaba 30 | """ 31 | 32 | PACKAGE = "tea_python_tests" 33 | NAME = "tea_python_tests" 34 | DESCRIPTION = "" 35 | AUTHOR = "Alibaba" 36 | AUTHOR_EMAIL = "sdk-team@alibabacloud.com" 37 | URL = "https://github.com/" 38 | VERSION = __import__(PACKAGE).__version__ 39 | REQUIRES = [ 40 | "darabonba-core>=1.0.0, <2.0.0", 41 | "alibabacloud_import==0.0.1rc1", 42 | "alibabacloud_local>=0.0.1, <1.0.0" 43 | ] 44 | 45 | LONG_DESCRIPTION = '' 46 | if os.path.exists('./README.md'): 47 | with open("README.md", encoding='utf-8') as fp: 48 | LONG_DESCRIPTION = fp.read() 49 | 50 | setup( 51 | name=NAME, 52 | version=VERSION, 53 | description=DESCRIPTION, 54 | long_description=LONG_DESCRIPTION, 55 | long_description_content_type='text/markdown', 56 | author=AUTHOR, 57 | author_email=AUTHOR_EMAIL, 58 | license="Apache License 2.0", 59 | url=URL, 60 | keywords=["tea","python","tests"], 61 | packages=find_packages(exclude=["tests*"]), 62 | include_package_data=True, 63 | platforms="any", 64 | install_requires=REQUIRES, 65 | python_requires=">=3.7", 66 | classifiers=( 67 | "Development Status :: 4 - Beta", 68 | "Intended Audience :: Developers", 69 | "License :: OSI Approved :: Apache Software License", 70 | "Programming Language :: Python", 71 | "Programming Language :: Python :: 3", 72 | "Programming Language :: Python :: 3.7", 73 | "Programming Language :: Python :: 3.8", 74 | "Programming Language :: Python :: 3.9", 75 | "Programming Language :: Python :: 3.10", 76 | "Programming Language :: Python :: 3.11", 77 | "Programming Language :: Python :: 3.12", 78 | "Topic :: Software Development" 79 | ) 80 | ) -------------------------------------------------------------------------------- /tests/expected/import/tea_python_tests/__init__.py: -------------------------------------------------------------------------------- 1 | __version__ = "1.0.0" 2 | -------------------------------------------------------------------------------- /tests/expected/import/tea_python_tests/client.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from typing import List 6 | 7 | from Local import models as local_models 8 | from Source import models as source_models 9 | from Source.source_client import SourceClient 10 | 11 | 12 | 13 | class Client: 14 | _id: List[str] = None 15 | _str: str = None 16 | _model: local_models.Local = None 17 | 18 | def __init__(self): 19 | pass 20 | 21 | @staticmethod 22 | def sample( 23 | client: SourceClient, 24 | ) -> None: 25 | runtime = source_models.RuntimeObject() 26 | request = source_models.Request( 27 | accesskey = 'accesskey', 28 | region = 'region' 29 | ) 30 | client.print(runtime) 31 | -------------------------------------------------------------------------------- /tests/expected/map/tea_python_tests/__init__.py: -------------------------------------------------------------------------------- 1 | __version__ = "1.0.0" 2 | -------------------------------------------------------------------------------- /tests/expected/map/tea_python_tests/client.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from darabonba.core import DaraCore 6 | from Source import models as source_models 7 | from Source.source_client import SourceClient 8 | 9 | 10 | 11 | class Client(SourceClient): 12 | 13 | def __init__( 14 | self, 15 | config: source_models.Config, 16 | ): 17 | super().__init__(config) 18 | a = { 19 | 'test': 'test' 20 | } 21 | c = { 22 | 'test': 'test' 23 | } 24 | self._endpoint_rule = 'central' 25 | self._endpoint_map = DaraCore.merge({ 26 | 'ap-northeast-1': 'cusanalytic.aliyuncs.com', 27 | 'ap-south-1': 'cusanalytic.aliyuncs.com', 28 | 'ap-south-2-test': SourceClient.hello() 29 | }, a, c) 30 | b = { 31 | 'ap-northeast-1': { 32 | 'ap-south-1': 'cusanalytic.aliyuncs.com' 33 | }, 34 | 'ap-south-2': SourceClient.hello() 35 | } 36 | self._endpoint_map.get('ap-northeast-1') 37 | self._endpoint_map['ap-northeast-1'] = '' 38 | self._endpoint_map[config.str_value] = 'str' 39 | self._endpoint_map.get(config.str_value) 40 | -------------------------------------------------------------------------------- /tests/expected/model/tea_python_tests/__init__.py: -------------------------------------------------------------------------------- 1 | __version__ = "1.0.0" 2 | -------------------------------------------------------------------------------- /tests/expected/model/tea_python_tests/client.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | class Client: 6 | 7 | def __init__(self): 8 | pass 9 | -------------------------------------------------------------------------------- /tests/expected/model/tea_python_tests/exceptions/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from ._main_file import MainFileException 6 | 7 | __all__ = [ 8 | MainFileException 9 | ] 10 | -------------------------------------------------------------------------------- /tests/expected/model/tea_python_tests/exceptions/_main_file.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from typing import Dict 6 | 7 | from darabonba.exceptions import DaraException 8 | from tea_python_tests import models as main_models 9 | 10 | class MainFileException(DaraException): 11 | def __init__( 12 | self, 13 | message: str = None, 14 | code: str = None, 15 | stack: str = None, 16 | size: int = None, 17 | data: Dict[str, main_models.Model] = None, 18 | model: main_models.MainFileModel = None, 19 | ): 20 | super().__init__({ 21 | 'message': message, 22 | 'code': code, 23 | 'stack': stack, 24 | }) 25 | self.name = 'MainFileException' 26 | self.size = size 27 | self.data = data 28 | self.model = model 29 | 30 | -------------------------------------------------------------------------------- /tests/expected/model/tea_python_tests/models/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from ._m import M 6 | from ._class import Class 7 | from ._model import Model 8 | from ._my_model import MyModel 9 | from ._m import MSubM 10 | from ._main_file import MainFileModelModel 11 | from ._main_file import MainFileModel 12 | from ._my_model import MyModelModelModel 13 | from ._my_model import MyModelModel 14 | from ._my_model import MyModelSubmodelModel 15 | from ._my_model import MyModelSubmodel 16 | from ._my_model import MyModelSubarraymodel 17 | 18 | __all__ = [ 19 | M, 20 | Class, 21 | Model, 22 | MyModel, 23 | MSubM, 24 | MainFileModelModel, 25 | MainFileModel, 26 | MyModelModelModel, 27 | MyModelModel, 28 | MyModelSubmodelModel, 29 | MyModelSubmodel, 30 | MyModelSubarraymodel 31 | ] 32 | -------------------------------------------------------------------------------- /tests/expected/model/tea_python_tests/models/_class.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from darabonba.model import DaraModel 6 | 7 | class Class(DaraModel): 8 | def __init__(self): 9 | pass 10 | def validate(self): 11 | pass 12 | 13 | def to_map(self): 14 | result = dict() 15 | _map = super().to_map() 16 | if _map is not None: 17 | result = _map 18 | return result 19 | 20 | def from_map(self, m: dict = None): 21 | m = m or dict() 22 | return self 23 | 24 | -------------------------------------------------------------------------------- /tests/expected/model/tea_python_tests/models/_m.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from darabonba.model import DaraModel 6 | from tea_python_tests import models as main_models 7 | 8 | class M(DaraModel): 9 | def __init__( 10 | self, 11 | sub_m: main_models.MSubM = None, 12 | ): 13 | self.sub_m = sub_m 14 | 15 | def validate(self): 16 | self.validate_required(self.sub_m, 'sub_m') 17 | if self.sub_m: 18 | self.sub_m.validate() 19 | 20 | def to_map(self): 21 | result = dict() 22 | _map = super().to_map() 23 | if _map is not None: 24 | result = _map 25 | if self.sub_m is not None: 26 | result['subM'] = self.sub_m.to_map() 27 | 28 | return result 29 | 30 | def from_map(self, m: dict = None): 31 | m = m or dict() 32 | if m.get('subM') is not None: 33 | temp_model = main_models.MSubM() 34 | self.sub_m = temp_model.from_map(m.get('subM')) 35 | 36 | return self 37 | 38 | 39 | 40 | class MSubM(DaraModel): 41 | def __init__(self): 42 | pass 43 | def validate(self): 44 | pass 45 | 46 | def to_map(self): 47 | result = dict() 48 | _map = super().to_map() 49 | if _map is not None: 50 | result = _map 51 | return result 52 | 53 | def from_map(self, m: dict = None): 54 | m = m or dict() 55 | return self 56 | 57 | -------------------------------------------------------------------------------- /tests/expected/model/tea_python_tests/models/_main_file.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from darabonba.model import DaraModel 6 | from tea_python_tests import models as main_models 7 | 8 | class MainFileModel(DaraModel): 9 | def __init__( 10 | self, 11 | str: str = None, 12 | model: main_models.MainFileModelModel = None, 13 | ): 14 | self.str = str 15 | self.model = model 16 | 17 | def validate(self): 18 | self.validate_required(self.str, 'str') 19 | self.validate_required(self.model, 'model') 20 | if self.model: 21 | self.model.validate() 22 | 23 | def to_map(self): 24 | result = dict() 25 | _map = super().to_map() 26 | if _map is not None: 27 | result = _map 28 | if self.str is not None: 29 | result['str'] = self.str 30 | 31 | if self.model is not None: 32 | result['model'] = self.model.to_map() 33 | 34 | return result 35 | 36 | def from_map(self, m: dict = None): 37 | m = m or dict() 38 | if m.get('str') is not None: 39 | self.str = m.get('str') 40 | 41 | if m.get('model') is not None: 42 | temp_model = main_models.MainFileModelModel() 43 | self.model = temp_model.from_map(m.get('model')) 44 | 45 | return self 46 | 47 | class MainFileModelModel(DaraModel): 48 | def __init__( 49 | self, 50 | str: str = None, 51 | ): 52 | self.str = str 53 | 54 | def validate(self): 55 | self.validate_required(self.str, 'str') 56 | 57 | def to_map(self): 58 | result = dict() 59 | _map = super().to_map() 60 | if _map is not None: 61 | result = _map 62 | if self.str is not None: 63 | result['str'] = self.str 64 | 65 | return result 66 | 67 | def from_map(self, m: dict = None): 68 | m = m or dict() 69 | if m.get('str') is not None: 70 | self.str = m.get('str') 71 | 72 | return self 73 | 74 | -------------------------------------------------------------------------------- /tests/expected/model/tea_python_tests/models/_model.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from darabonba.model import DaraModel 6 | 7 | class Model(DaraModel): 8 | def __init__( 9 | self, 10 | str: str = None, 11 | ): 12 | self.str = str 13 | 14 | def validate(self): 15 | self.validate_required(self.str, 'str') 16 | 17 | def to_map(self): 18 | result = dict() 19 | _map = super().to_map() 20 | if _map is not None: 21 | result = _map 22 | if self.str is not None: 23 | result['str'] = self.str 24 | 25 | return result 26 | 27 | def from_map(self, m: dict = None): 28 | m = m or dict() 29 | if m.get('str') is not None: 30 | self.str = m.get('str') 31 | 32 | return self 33 | 34 | -------------------------------------------------------------------------------- /tests/expected/modelConfig/tea_python_tests/__init__.py: -------------------------------------------------------------------------------- 1 | __version__ = "1.0.0" 2 | -------------------------------------------------------------------------------- /tests/expected/modelConfig/tea_python_tests/client.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | class Client: 6 | 7 | def __init__(self): 8 | pass 9 | -------------------------------------------------------------------------------- /tests/expected/modelConfig/tea_python_tests/exceptions/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from ._main_file import MainFileException 6 | 7 | __all__ = [ 8 | MainFileException 9 | ] 10 | -------------------------------------------------------------------------------- /tests/expected/modelConfig/tea_python_tests/exceptions/_main_file.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from typing import Dict 6 | 7 | from darabonba.exceptions import DaraException 8 | from tea_python_tests import models as main_models 9 | 10 | class MainFileException(DaraException): 11 | def __init__( 12 | self, *, 13 | message: str = None, 14 | code: str = None, 15 | stack: str = None, 16 | size: int = None, 17 | data: Dict[str, main_models.Model] = None, 18 | model: main_models.MainFileModel = None, 19 | ): 20 | super().__init__({ 21 | 'message': message, 22 | 'code': code, 23 | 'stack': stack, 24 | }) 25 | self.name = 'MainFileException' 26 | self.size = size 27 | self.data = data 28 | self.model = model 29 | 30 | -------------------------------------------------------------------------------- /tests/expected/modelConfig/tea_python_tests/models/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from ._m import M 6 | from ._class import Class 7 | from ._model import Model 8 | from ._my_model import MyModel 9 | from ._m import MSubM 10 | from ._main_file import MainFileModelModel 11 | from ._main_file import MainFileModel 12 | from ._my_model import MyModelModelModel 13 | from ._my_model import MyModelModel 14 | from ._my_model import MyModelSubmodelModel 15 | from ._my_model import MyModelSubmodel 16 | from ._my_model import MyModelSubarraymodel 17 | 18 | __all__ = [ 19 | M, 20 | Class, 21 | Model, 22 | MyModel, 23 | MSubM, 24 | MainFileModelModel, 25 | MainFileModel, 26 | MyModelModelModel, 27 | MyModelModel, 28 | MyModelSubmodelModel, 29 | MyModelSubmodel, 30 | MyModelSubarraymodel 31 | ] 32 | -------------------------------------------------------------------------------- /tests/expected/modelConfig/tea_python_tests/models/_class.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from darabonba.model import DaraModel 6 | 7 | class Class(DaraModel): 8 | def __init__(self): 9 | pass 10 | def validate(self): 11 | pass 12 | 13 | def to_map(self): 14 | result = dict() 15 | _map = super().to_map() 16 | if _map is not None: 17 | result = _map 18 | return result 19 | 20 | def from_map(self, m: dict = None): 21 | m = m or dict() 22 | return self 23 | 24 | -------------------------------------------------------------------------------- /tests/expected/modelConfig/tea_python_tests/models/_m.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from darabonba.model import DaraModel 6 | from tea_python_tests import models as main_models 7 | 8 | class M(DaraModel): 9 | def __init__( 10 | self, *, 11 | sub_m: main_models.MSubM = None, 12 | ): 13 | self.sub_m = sub_m 14 | 15 | def validate(self): 16 | self.validate_required(self.sub_m, 'sub_m') 17 | if self.sub_m: 18 | self.sub_m.validate() 19 | 20 | def to_map(self): 21 | result = dict() 22 | _map = super().to_map() 23 | if _map is not None: 24 | result = _map 25 | if self.sub_m is not None: 26 | result['subM'] = self.sub_m.to_map() 27 | 28 | return result 29 | 30 | def from_map(self, m: dict = None): 31 | m = m or dict() 32 | if m.get('subM') is not None: 33 | temp_model = main_models.MSubM() 34 | self.sub_m = temp_model.from_map(m.get('subM')) 35 | 36 | return self 37 | 38 | 39 | 40 | class MSubM(DaraModel): 41 | def __init__(self): 42 | pass 43 | def validate(self): 44 | pass 45 | 46 | def to_map(self): 47 | result = dict() 48 | _map = super().to_map() 49 | if _map is not None: 50 | result = _map 51 | return result 52 | 53 | def from_map(self, m: dict = None): 54 | m = m or dict() 55 | return self 56 | 57 | -------------------------------------------------------------------------------- /tests/expected/modelConfig/tea_python_tests/models/_main_file.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from darabonba.model import DaraModel 6 | from tea_python_tests import models as main_models 7 | 8 | class MainFileModel(DaraModel): 9 | def __init__( 10 | self, *, 11 | str: str = None, 12 | model: main_models.MainFileModelModel = None, 13 | ): 14 | self.str = str 15 | self.model = model 16 | 17 | def validate(self): 18 | self.validate_required(self.str, 'str') 19 | self.validate_required(self.model, 'model') 20 | if self.model: 21 | self.model.validate() 22 | 23 | def to_map(self): 24 | result = dict() 25 | _map = super().to_map() 26 | if _map is not None: 27 | result = _map 28 | if self.str is not None: 29 | result['str'] = self.str 30 | 31 | if self.model is not None: 32 | result['model'] = self.model.to_map() 33 | 34 | return result 35 | 36 | def from_map(self, m: dict = None): 37 | m = m or dict() 38 | if m.get('str') is not None: 39 | self.str = m.get('str') 40 | 41 | if m.get('model') is not None: 42 | temp_model = main_models.MainFileModelModel() 43 | self.model = temp_model.from_map(m.get('model')) 44 | 45 | return self 46 | 47 | class MainFileModelModel(DaraModel): 48 | def __init__( 49 | self, *, 50 | str: str = None, 51 | ): 52 | self.str = str 53 | 54 | def validate(self): 55 | self.validate_required(self.str, 'str') 56 | 57 | def to_map(self): 58 | result = dict() 59 | _map = super().to_map() 60 | if _map is not None: 61 | result = _map 62 | if self.str is not None: 63 | result['str'] = self.str 64 | 65 | return result 66 | 67 | def from_map(self, m: dict = None): 68 | m = m or dict() 69 | if m.get('str') is not None: 70 | self.str = m.get('str') 71 | 72 | return self 73 | 74 | -------------------------------------------------------------------------------- /tests/expected/modelConfig/tea_python_tests/models/_model.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from darabonba.model import DaraModel 6 | 7 | class Model(DaraModel): 8 | def __init__( 9 | self, *, 10 | str: str = None, 11 | ): 12 | self.str = str 13 | 14 | def validate(self): 15 | self.validate_required(self.str, 'str') 16 | 17 | def to_map(self): 18 | result = dict() 19 | _map = super().to_map() 20 | if _map is not None: 21 | result = _map 22 | if self.str is not None: 23 | result['str'] = self.str 24 | 25 | return result 26 | 27 | def from_map(self, m: dict = None): 28 | m = m or dict() 29 | if m.get('str') is not None: 30 | self.str = m.get('str') 31 | 32 | return self 33 | 34 | -------------------------------------------------------------------------------- /tests/expected/multi/tea_python_tests/__init__.py: -------------------------------------------------------------------------------- 1 | __version__ = "1.0.0" 2 | -------------------------------------------------------------------------------- /tests/expected/multi/tea_python_tests/api.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from darabonba.core import DaraCore 6 | from darabonba.exceptions import UnretryableException 7 | from darabonba.policy.retry import RetryPolicyContext 8 | from darabonba.request import DaraRequest 9 | from tea_python_tests.lib.util import Util 10 | 11 | class Client: 12 | def __init__(self): 13 | pass 14 | 15 | def test_3(self) -> int: 16 | _runtime = { 17 | 'timeouted': 'retry', 18 | } 19 | _last_request = None 20 | _last_response = None 21 | _retries_attempted = 0 22 | _context = RetryPolicyContext( 23 | retries_attempted= _retries_attempted 24 | ) 25 | while DaraCore.should_retry(_runtime.get('retryOptions'), _context): 26 | if _retries_attempted > 0: 27 | _backoff_time = DaraCore.get_backoff_time(_runtime.get('retryOptions'), _context) 28 | if _backoff_time > 0: 29 | DaraCore.sleep(_backoff_time) 30 | _retries_attempted = _retries_attempted + 1 31 | try: 32 | _request = DaraRequest() 33 | _request.protocol = 'https' 34 | _request.method = 'DELETE' 35 | _request.pathname = '/' 36 | _request.headers = { 37 | 'host': 'test.aliyun.com', 38 | 'accept': 'application/json' 39 | } 40 | _request.query = Util.get_query() 41 | _last_request = _request 42 | _response = DaraCore.do_action(_request, _runtime) 43 | _last_response = _response 44 | return _response.status_code 45 | except Exception as e: 46 | _context = RetryPolicyContext( 47 | retries_attempted= _retries_attempted, 48 | http_request = _last_request, 49 | http_response = _last_response, 50 | exception = e 51 | ) 52 | continue 53 | raise UnretryableException(_context) 54 | 55 | async def test_3_async(self) -> int: 56 | _runtime = { 57 | 'timeouted': 'retry', 58 | } 59 | _last_request = None 60 | _last_response = None 61 | _retries_attempted = 0 62 | _context = RetryPolicyContext( 63 | retries_attempted= _retries_attempted 64 | ) 65 | while DaraCore.should_retry(_runtime.get('retryOptions'), _context): 66 | if _retries_attempted > 0: 67 | _backoff_time = DaraCore.get_backoff_time(_runtime.get('retryOptions'), _context) 68 | if _backoff_time > 0: 69 | DaraCore.sleep(_backoff_time) 70 | _retries_attempted = _retries_attempted + 1 71 | try: 72 | _request = DaraRequest() 73 | _request.protocol = 'https' 74 | _request.method = 'DELETE' 75 | _request.pathname = '/' 76 | _request.headers = { 77 | 'host': 'test.aliyun.com', 78 | 'accept': 'application/json' 79 | } 80 | _request.query = Util.get_query() 81 | _last_request = _request 82 | _response = await DaraCore.async_do_action(_request, _runtime) 83 | _last_response = _response 84 | return _response.status_code 85 | except Exception as e: 86 | _context = RetryPolicyContext( 87 | retries_attempted= _retries_attempted, 88 | http_request = _last_request, 89 | http_response = _last_response, 90 | exception = e 91 | ) 92 | continue 93 | raise UnretryableException(_context) 94 | -------------------------------------------------------------------------------- /tests/expected/multi/tea_python_tests/api_models/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from ._test_model_dir_2 import TestModelDir2 6 | 7 | __all__ = [ 8 | TestModelDir2 9 | ] 10 | -------------------------------------------------------------------------------- /tests/expected/multi/tea_python_tests/api_models/_test_model_dir_2.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from darabonba.model import DaraModel 6 | 7 | 8 | 9 | class TestModelDir2(DaraModel): 10 | def __init__( 11 | self, 12 | test: int = None, 13 | ): 14 | self.test = test 15 | 16 | def validate(self): 17 | self.validate_required(self.test, 'test') 18 | 19 | def to_map(self): 20 | result = dict() 21 | _map = super().to_map() 22 | if _map is not None: 23 | result = _map 24 | if self.test is not None: 25 | result['test'] = self.test 26 | 27 | return result 28 | 29 | def from_map(self, m: dict = None): 30 | m = m or dict() 31 | if m.get('test') is not None: 32 | self.test = m.get('test') 33 | 34 | return self 35 | 36 | -------------------------------------------------------------------------------- /tests/expected/multi/tea_python_tests/client.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from typing import Generator, AsyncGenerator 6 | 7 | from tea_python_tests.api import Client as APIClient 8 | from tea_python_tests.lib.util import Util 9 | from tea_python_tests.model import user_models as user_models 10 | 11 | class Client: 12 | _user: user_models.Info = None 13 | def __init__(self): 14 | self._user = user_models.Info( 15 | name = 'test', 16 | age = 124, 17 | max_attemp = 3, 18 | autoretry = True 19 | ) 20 | 21 | def test_3(self) -> Generator[str, None, None]: 22 | it = Util.test_1() 23 | for test in it: 24 | yield test 25 | 26 | async def test_3_async(self) -> AsyncGenerator[str, None, None]: 27 | it = Util.test_1() 28 | for test in it: 29 | yield test 30 | 31 | def test_4(self) -> int: 32 | api = APIClient() 33 | status = api.test_3() 34 | return status 35 | 36 | async def test_4_async(self) -> int: 37 | api = APIClient() 38 | status = await api.test_3_async() 39 | return status 40 | -------------------------------------------------------------------------------- /tests/expected/multi/tea_python_tests/exceptions/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from ._err import ErrException 6 | from ._err import ERRException 7 | 8 | __all__ = [ 9 | ErrException, 10 | ERRException 11 | ] 12 | -------------------------------------------------------------------------------- /tests/expected/multi/tea_python_tests/exceptions/_err.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from darabonba.exceptions import DaraException 6 | 7 | class ERRException(DaraException): 8 | def __init__( 9 | self, 10 | message: str = None, 11 | code: str = None, 12 | stack: str = None, 13 | test: int = None, 14 | ): 15 | super().__init__({ 16 | 'message': message, 17 | 'code': code, 18 | 'stack': stack, 19 | }) 20 | self.name = 'ERRException' 21 | self.test = test 22 | 23 | class ErrException(DaraException): 24 | def __init__( 25 | self, 26 | message: str = None, 27 | code: str = None, 28 | stack: str = None, 29 | test: str = None, 30 | ): 31 | super().__init__({ 32 | 'message': message, 33 | 'code': code, 34 | 'stack': stack, 35 | }) 36 | self.name = 'ErrException' 37 | self.test = test 38 | 39 | -------------------------------------------------------------------------------- /tests/expected/multi/tea_python_tests/lib/util.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from typing import Generator, Dict 6 | 7 | class Util: 8 | 9 | def __init__(self): 10 | pass 11 | 12 | @staticmethod 13 | def test_1() -> Generator[str, None, None]: 14 | raise Exception('Un-implemented') 15 | 16 | @staticmethod 17 | def get_query() -> Dict[str, str]: 18 | raise Exception('Un-implemented') 19 | -------------------------------------------------------------------------------- /tests/expected/multi/tea_python_tests/model/user.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from typing import Generator, AsyncGenerator 6 | 7 | from alibabacloud_tea_util.util import Utils 8 | from tea_python_tests.lib.util import Util 9 | 10 | class Client: 11 | 12 | def __init__(self): 13 | pass 14 | 15 | @staticmethod 16 | def test() -> Generator[str, None, None]: 17 | Utils.test() 18 | it = Util.test_1() 19 | for test in it: 20 | yield test 21 | 22 | @staticmethod 23 | async def test_async() -> AsyncGenerator[str, None, None]: 24 | Utils.test() 25 | it = Util.test_1() 26 | for test in it: 27 | yield test 28 | -------------------------------------------------------------------------------- /tests/expected/multi/tea_python_tests/model/user_exceptions/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from ._err import ErrException 6 | from ._err_1 import Err1Exception 7 | from ._err_2 import Err2Exception 8 | 9 | __all__ = [ 10 | ErrException, 11 | Err1Exception, 12 | Err2Exception 13 | ] 14 | -------------------------------------------------------------------------------- /tests/expected/multi/tea_python_tests/model/user_exceptions/_err.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from darabonba.exceptions import DaraException 6 | 7 | class ErrException(DaraException): 8 | def __init__( 9 | self, 10 | message: str = None, 11 | code: str = None, 12 | stack: str = None, 13 | msg: str = None, 14 | ): 15 | super().__init__({ 16 | 'message': message, 17 | 'code': code, 18 | 'stack': stack, 19 | }) 20 | self.name = 'ErrException' 21 | self.msg = msg 22 | 23 | -------------------------------------------------------------------------------- /tests/expected/multi/tea_python_tests/model/user_exceptions/_err_1.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from tea_python_tests import user_exceptions as main_exceptions 6 | 7 | class Err1Exception(main_exceptions.BaseInfoException): 8 | def __init__( 9 | self, 10 | max_attemp: int = None, 11 | autoretry: bool = None, 12 | ignore_ssl: bool = None, 13 | key: str = None, 14 | cert: str = None, 15 | ca: str = None, 16 | max_attempts: int = None, 17 | backoff_policy: str = None, 18 | backoff_period: int = None, 19 | read_timeout: int = None, 20 | connect_timeout: int = None, 21 | http_proxy: str = None, 22 | https_proxy: str = None, 23 | no_proxy: str = None, 24 | max_idle_conns: int = None, 25 | local_addr: str = None, 26 | socks_5proxy: str = None, 27 | socks_5net_work: str = None, 28 | keep_alive: bool = None, 29 | msg: str = None, 30 | ): 31 | super().__init__( 32 | max_attemp = max_attemp, 33 | autoretry = autoretry, 34 | ignore_ssl = ignore_ssl, 35 | key = key, 36 | cert = cert, 37 | ca = ca, 38 | max_attempts = max_attempts, 39 | backoff_policy = backoff_policy, 40 | backoff_period = backoff_period, 41 | read_timeout = read_timeout, 42 | connect_timeout = connect_timeout, 43 | http_proxy = http_proxy, 44 | https_proxy = https_proxy, 45 | no_proxy = no_proxy, 46 | max_idle_conns = max_idle_conns, 47 | local_addr = local_addr, 48 | socks_5proxy = socks_5proxy, 49 | socks_5net_work = socks_5net_work, 50 | keep_alive = keep_alive, 51 | ) 52 | self.name = 'Err1Exception' 53 | self.msg = msg 54 | 55 | -------------------------------------------------------------------------------- /tests/expected/multi/tea_python_tests/model/user_exceptions/_err_2.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from tea_python_tests import user_exceptions as main_exceptions 6 | 7 | class Err2Exception(main_exceptions.ErrException): 8 | def __init__( 9 | self, 10 | msg: str = None, 11 | msg_2: str = None, 12 | ): 13 | super().__init__( 14 | msg = msg, 15 | ) 16 | self.name = 'Err2Exception' 17 | self.msg_2 = msg_2 18 | 19 | -------------------------------------------------------------------------------- /tests/expected/multi/tea_python_tests/model/user_models/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from ._base_info import BaseInfo 6 | from ._info import Info 7 | 8 | __all__ = [ 9 | BaseInfo, 10 | Info 11 | ] 12 | -------------------------------------------------------------------------------- /tests/expected/multi/tea_python_tests/model/user_models/_base_info.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from alibabacloud_tea_util import models as darautil_models 6 | 7 | 8 | 9 | class BaseInfo(darautil_models.RuntimeOptions): 10 | def __init__( 11 | self, 12 | autoretry: bool = None, 13 | ignore_ssl: bool = None, 14 | key: str = None, 15 | cert: str = None, 16 | ca: str = None, 17 | max_attempts: int = None, 18 | backoff_policy: str = None, 19 | backoff_period: int = None, 20 | read_timeout: int = None, 21 | connect_timeout: int = None, 22 | http_proxy: str = None, 23 | https_proxy: str = None, 24 | no_proxy: str = None, 25 | max_idle_conns: int = None, 26 | local_addr: str = None, 27 | socks_5proxy: str = None, 28 | socks_5net_work: str = None, 29 | keep_alive: bool = None, 30 | max_attemp: int = None, 31 | ): 32 | super().__init__( 33 | autoretry = autoretry, 34 | ignore_ssl = ignore_ssl, 35 | key = key, 36 | cert = cert, 37 | ca = ca, 38 | max_attempts = max_attempts, 39 | backoff_policy = backoff_policy, 40 | backoff_period = backoff_period, 41 | read_timeout = read_timeout, 42 | connect_timeout = connect_timeout, 43 | http_proxy = http_proxy, 44 | https_proxy = https_proxy, 45 | no_proxy = no_proxy, 46 | max_idle_conns = max_idle_conns, 47 | local_addr = local_addr, 48 | socks_5proxy = socks_5proxy, 49 | socks_5net_work = socks_5net_work, 50 | keep_alive = keep_alive, 51 | ) 52 | self.max_attemp = max_attemp 53 | 54 | def validate(self): 55 | self.validate_required(self.max_attemp, 'max_attemp') 56 | 57 | def to_map(self): 58 | result = dict() 59 | _map = super().to_map() 60 | if _map is not None: 61 | result = _map 62 | if self.max_attemp is not None: 63 | result['maxAttemp'] = self.max_attemp 64 | 65 | return result 66 | 67 | def from_map(self, m: dict = None): 68 | m = m or dict() 69 | if m.get('maxAttemp') is not None: 70 | self.max_attemp = m.get('maxAttemp') 71 | 72 | return self 73 | 74 | -------------------------------------------------------------------------------- /tests/expected/multi/tea_python_tests/model/user_models/_info.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from tea_python_tests import user_models as main_models 6 | 7 | class Info(main_models.BaseInfo): 8 | def __init__( 9 | self, 10 | max_attemp: int = None, 11 | autoretry: bool = None, 12 | ignore_ssl: bool = None, 13 | key: str = None, 14 | cert: str = None, 15 | ca: str = None, 16 | max_attempts: int = None, 17 | backoff_policy: str = None, 18 | backoff_period: int = None, 19 | read_timeout: int = None, 20 | connect_timeout: int = None, 21 | http_proxy: str = None, 22 | https_proxy: str = None, 23 | no_proxy: str = None, 24 | max_idle_conns: int = None, 25 | local_addr: str = None, 26 | socks_5proxy: str = None, 27 | socks_5net_work: str = None, 28 | keep_alive: bool = None, 29 | name: str = None, 30 | age: int = None, 31 | ): 32 | super().__init__( 33 | max_attemp = max_attemp, 34 | autoretry = autoretry, 35 | ignore_ssl = ignore_ssl, 36 | key = key, 37 | cert = cert, 38 | ca = ca, 39 | max_attempts = max_attempts, 40 | backoff_policy = backoff_policy, 41 | backoff_period = backoff_period, 42 | read_timeout = read_timeout, 43 | connect_timeout = connect_timeout, 44 | http_proxy = http_proxy, 45 | https_proxy = https_proxy, 46 | no_proxy = no_proxy, 47 | max_idle_conns = max_idle_conns, 48 | local_addr = local_addr, 49 | socks_5proxy = socks_5proxy, 50 | socks_5net_work = socks_5net_work, 51 | keep_alive = keep_alive, 52 | ) 53 | self.name = name 54 | self.age = age 55 | 56 | def validate(self): 57 | self.validate_required(self.name, 'name') 58 | self.validate_required(self.age, 'age') 59 | 60 | def to_map(self): 61 | result = dict() 62 | _map = super().to_map() 63 | if _map is not None: 64 | result = _map 65 | if self.name is not None: 66 | result['name'] = self.name 67 | 68 | if self.age is not None: 69 | result['age'] = self.age 70 | 71 | return result 72 | 73 | def from_map(self, m: dict = None): 74 | m = m or dict() 75 | if m.get('name') is not None: 76 | self.name = m.get('name') 77 | 78 | if m.get('age') is not None: 79 | self.age = m.get('age') 80 | 81 | return self 82 | 83 | -------------------------------------------------------------------------------- /tests/expected/multi/tea_python_tests/models/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from ._test_model_dir import TestModelDir 6 | from ._test_model_dir import TestModelDIR 7 | 8 | __all__ = [ 9 | TestModelDir, 10 | TestModelDIR 11 | ] 12 | -------------------------------------------------------------------------------- /tests/expected/multi/tea_python_tests/models/_test_model_dir.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from typing import Any 6 | 7 | from darabonba.model import DaraModel 8 | from tea_python_tests.model import user_models as user_models 9 | 10 | class TestModelDIR(DaraModel): 11 | def __init__( 12 | self, 13 | test: str = None, 14 | a: Any = None, 15 | ): 16 | self.test = test 17 | self.a = a 18 | 19 | def validate(self): 20 | self.validate_required(self.test, 'test') 21 | self.validate_required(self.a, 'a') 22 | 23 | def to_map(self): 24 | result = dict() 25 | _map = super().to_map() 26 | if _map is not None: 27 | result = _map 28 | if self.test is not None: 29 | result['test'] = self.test 30 | 31 | if self.a is not None: 32 | result['a'] = self.a 33 | 34 | return result 35 | 36 | def from_map(self, m: dict = None): 37 | m = m or dict() 38 | if m.get('test') is not None: 39 | self.test = m.get('test') 40 | 41 | if m.get('a') is not None: 42 | self.a = m.get('a') 43 | 44 | return self 45 | 46 | 47 | 48 | class TestModelDir(DaraModel): 49 | def __init__( 50 | self, 51 | test: int = None, 52 | m: user_models.Info = None, 53 | ): 54 | self.test = test 55 | self.m = m 56 | 57 | def validate(self): 58 | self.validate_required(self.test, 'test') 59 | self.validate_required(self.m, 'm') 60 | 61 | def to_map(self): 62 | result = dict() 63 | _map = super().to_map() 64 | if _map is not None: 65 | result = _map 66 | if self.test is not None: 67 | result['test'] = self.test 68 | 69 | if self.m is not None: 70 | result['m'] = self.m.to_map() 71 | 72 | return result 73 | 74 | def from_map(self, m: dict = None): 75 | m = m or dict() 76 | if m.get('test') is not None: 77 | self.test = m.get('test') 78 | 79 | if m.get('m') is not None: 80 | temp_model = user_models.Info() 81 | self.m = temp_model.from_map(m.get('m')) 82 | 83 | return self 84 | 85 | -------------------------------------------------------------------------------- /tests/expected/statements/tea_python_tests/__init__.py: -------------------------------------------------------------------------------- 1 | __version__ = "1.0.0" 2 | -------------------------------------------------------------------------------- /tests/expected/statements/tea_python_tests/client.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from darabonba.core import DaraCore 6 | from darabonba.exceptions import DaraException 7 | from darabonba.request import DaraRequest 8 | 9 | class Client: 10 | def __init__(self): 11 | pass 12 | 13 | def hello(self) -> None: 14 | _request = DaraRequest() 15 | _request.method = 'GET' 16 | _request.pathname = '/' 17 | _request.headers = { 18 | 'host': 'www.test.com' 19 | } 20 | if True: 21 | _request.headers["host"] = 'www.test2.com' 22 | _last_request = _request 23 | _response = DaraCore.do_action(_request) 24 | if True: 25 | raise DaraException(_request, _response) 26 | else: 27 | True 28 | 29 | self.hello_if() 30 | not False 31 | a = None 32 | a = 'string' 33 | return 34 | 35 | async def hello_async(self) -> None: 36 | _request = DaraRequest() 37 | _request.method = 'GET' 38 | _request.pathname = '/' 39 | _request.headers = { 40 | 'host': 'www.test.com' 41 | } 42 | if True: 43 | _request.headers["host"] = 'www.test2.com' 44 | _last_request = _request 45 | _response = await DaraCore.async_do_action(_request) 46 | if True: 47 | raise DaraException(_request, _response) 48 | else: 49 | True 50 | 51 | self.hello_if() 52 | not False 53 | a = None 54 | a = 'string' 55 | return 56 | 57 | @staticmethod 58 | def hello_if() -> None: 59 | if True: 60 | pass 61 | if True: 62 | pass 63 | elif True: 64 | pass 65 | else: 66 | pass 67 | 68 | @staticmethod 69 | def hello_throw() -> None: 70 | raise DaraException({}) 71 | 72 | @staticmethod 73 | def hello_for_break() -> None: 74 | for item in [ ]: 75 | break 76 | 77 | @staticmethod 78 | def hello_while() -> None: 79 | while True: 80 | break 81 | 82 | @staticmethod 83 | def hello_declare() -> None: 84 | hello = 'world' 85 | hello_null = None 86 | hello = 'hehe' 87 | -------------------------------------------------------------------------------- /tests/expected/super/tea_python_tests/__init__.py: -------------------------------------------------------------------------------- 1 | __version__ = "1.0.0" 2 | -------------------------------------------------------------------------------- /tests/expected/super/tea_python_tests/client.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from Source import models as source_models 6 | from Source.source_client import SourceClient 7 | 8 | 9 | 10 | class Client(SourceClient): 11 | 12 | def __init__( 13 | self, 14 | config: source_models.Config, 15 | ): 16 | super().__init__(config) 17 | -------------------------------------------------------------------------------- /tests/expected/typedef/setup.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Licensed to the Apache Software Foundation (ASF) under one 4 | or more contributor license agreements. See the NOTICE file 5 | distributed with this work for additional information 6 | regarding copyright ownership. The ASF licenses this file 7 | to you under the Apache License, Version 2.0 (the 8 | "License"); you may not use this file except in compliance 9 | with the License. You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, 14 | software distributed under the License is distributed on an 15 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | KIND, either express or implied. See the License for the 17 | specific language governing permissions and limitations 18 | under the License. 19 | """ 20 | 21 | import os 22 | from setuptools import setup, find_packages 23 | 24 | """ 25 | setup module for tea_python_tests. 26 | 27 | Created on 28/05/2022 28 | 29 | @author: Alibaba 30 | """ 31 | 32 | PACKAGE = "tea_python_tests" 33 | NAME = "tea_python_tests" or "alibabacloud-package" 34 | DESCRIPTION = "Generate setup.py" 35 | AUTHOR = "Alibaba" 36 | AUTHOR_EMAIL = "sdk-team@alibabacloud.com" 37 | URL = "https://github.com/" 38 | VERSION = __import__(PACKAGE).__version__ 39 | REQUIRES = [ 40 | "requests>=2.21.0, <3.0.0", 41 | "darabonba-core>=0.2.9, <1.0.0" 42 | ] 43 | 44 | LONG_DESCRIPTION = '' 45 | if os.path.exists('./README.md'): 46 | with open("README.md", encoding='utf-8') as fp: 47 | LONG_DESCRIPTION = fp.read() 48 | 49 | setup( 50 | name=NAME, 51 | version=VERSION, 52 | description=DESCRIPTION, 53 | long_description=LONG_DESCRIPTION, 54 | long_description_content_type='text/markdown', 55 | author=AUTHOR, 56 | author_email=AUTHOR_EMAIL, 57 | license="Apache License 2.0", 58 | url=URL, 59 | keywords=["tea","python","tests"], 60 | packages=find_packages(exclude=["tests*"]), 61 | include_package_data=True, 62 | platforms="any", 63 | install_requires=REQUIRES, 64 | python_requires=">=3.6", 65 | classifiers=( 66 | "Development Status :: 4 - Beta", 67 | "Intended Audience :: Developers", 68 | "License :: OSI Approved :: Apache Software License", 69 | "Programming Language :: Python", 70 | "Programming Language :: Python :: 3", 71 | "Programming Language :: Python :: 3.6", 72 | 'Programming Language :: Python :: 3.7', 73 | 'Programming Language :: Python :: 3.8', 74 | 'Programming Language :: Python :: 3.9', 75 | "Topic :: Software Development" 76 | ) 77 | ) 78 | -------------------------------------------------------------------------------- /tests/expected/typedef/tea_python_tests/__init__.py: -------------------------------------------------------------------------------- 1 | __version__ = "1.0.0" 2 | -------------------------------------------------------------------------------- /tests/expected/typedef/tea_python_tests/client.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from typing import Dict, Any 6 | 7 | from requests import Request, Response 8 | from Source.source_client import SourceClient 9 | from tea_python_tests import models as main_models 10 | from Tea.model import TeaModel 11 | 12 | class Client: 13 | _vid: Request = None 14 | _model: TeaModel = None 15 | 16 | def __init__( 17 | self, 18 | request: Request, 19 | model: TeaModel, 20 | ): 21 | self._vid = request 22 | self._model = model 23 | 24 | def main( 25 | self, 26 | test_1: Request, 27 | test_2: TeaModel, 28 | ) -> None: 29 | oss = SourceClient(test_1) 30 | m = main_models.M( 31 | a = test_1, 32 | b = test_2 33 | ) 34 | self._vid = test_1 35 | self._model = test_2 36 | 37 | async def main_async( 38 | self, 39 | test_1: Request, 40 | test_2: TeaModel, 41 | ) -> None: 42 | oss = SourceClient(test_1) 43 | m = main_models.M( 44 | a = test_1, 45 | b = test_2 46 | ) 47 | self._vid = test_1 48 | self._model = test_2 49 | 50 | def test_http_request( 51 | self, 52 | req: Request, 53 | ) -> Response: 54 | return self.test_http_request_with('test', req) 55 | 56 | async def test_http_request_async( 57 | self, 58 | req: Request, 59 | ) -> Response: 60 | return self.test_http_request_with('test', req) 61 | 62 | @staticmethod 63 | def test_http_request_with( 64 | method: str, 65 | req: Request, 66 | ) -> Response: 67 | raise Exception('Un-implemented') 68 | 69 | @staticmethod 70 | def test_http_header( 71 | method: str, 72 | headers: Dict[str, Any], 73 | ) -> Response: 74 | raise Exception('Un-implemented') 75 | -------------------------------------------------------------------------------- /tests/expected/typedef/tea_python_tests/models/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from ._m import M 6 | 7 | __all__ = [ 8 | M 9 | ] 10 | -------------------------------------------------------------------------------- /tests/expected/typedef/tea_python_tests/models/_m.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # This file is auto-generated, don't edit it. Thanks. 3 | from __future__ import annotations 4 | 5 | from darabonba.model import DaraModel 6 | from requests import Request 7 | from Tea.model import TeaModel 8 | 9 | 10 | 11 | class M(DaraModel): 12 | def __init__( 13 | self, 14 | a: Request = None, 15 | b: TeaModel = None, 16 | ): 17 | self.a = a 18 | self.b = b 19 | 20 | def validate(self): 21 | pass 22 | 23 | def to_map(self): 24 | result = dict() 25 | _map = super().to_map() 26 | if _map is not None: 27 | result = _map 28 | if self.a is not None: 29 | result['a'] = self.a 30 | 31 | if self.b is not None: 32 | result['b'] = self.b 33 | 34 | return result 35 | 36 | def from_map(self, m: dict = None): 37 | m = m or dict() 38 | if m.get('a') is not None: 39 | self.a = m.get('a') 40 | 41 | if m.get('b') is not None: 42 | self.b = m.get('b') 43 | 44 | return self 45 | 46 | -------------------------------------------------------------------------------- /tests/fixtures/alias/.libraries.json: -------------------------------------------------------------------------------- 1 | { 2 | "alibabacloud:Import:*": "libraries/Import", 3 | "alibabacloud:Alias:*": "libraries/Alias", 4 | "alibabacloud:Source:*": "libraries/Source", 5 | "alibabacloud:AliasSource:*": "libraries/AliasSource", 6 | "alibabacloud:Alias-Symbol:*": "libraries/Alias-Symbol" 7 | } -------------------------------------------------------------------------------- /tests/fixtures/alias/Darafile: -------------------------------------------------------------------------------- 1 | { 2 | "scope": "alibabacloud", 3 | "name": "main", 4 | "version": "0.0.1", 5 | "main": "./main.dara", 6 | "libraries": { 7 | "Import": "alibabacloud:Import:*", 8 | "Source" : "alibabacloud:Source:*", 9 | "Alias" : "alibabacloud:Alias:*", 10 | "AliasSource" : "alibabacloud:AliasSource:*", 11 | "Alias-Symbol": "alibabacloud:Alias-Symbol:*" 12 | }, 13 | "python": { 14 | "package": "tea_python_tests", 15 | "clientName": "client", 16 | "packageInfo": { 17 | "name": "tea-python-tests", 18 | "desc": "Generate setup.py", 19 | "github": "https://github.com/dara", 20 | "author": "AlibabaCloud SDK Team", 21 | "email": "sdkteam@alibabacloud.com", 22 | "require": ["xxx1>=0.0.1, <1.0.0", "xxx2>=0.0.1, <1.0.0"] 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /tests/fixtures/alias/libraries/Alias-Symbol/Darafile: -------------------------------------------------------------------------------- 1 | { 2 | "scope": "alibabacloud", 3 | "name": "Alias-Symbol", 4 | "version": "0.0.1", 5 | "main": "./main.dara", 6 | "releases": { 7 | "go": "github.com/alibabacloud-go/tea-utils/v2/service:v2.0.4", 8 | "ts": "@alicloud/tea-util:^1.4.7", 9 | "csharp": "AlibabaCloud.TeaUtil:0.1.17", 10 | "java": "com.aliyun:tea-util:0.2.21", 11 | "php": "alibabacloud/tea-utils:^0.2.19", 12 | "python": "alibabacloud_tea_util:0.3.11", 13 | "python2": "alibabacloud_tea_util_py2:0.0.9", 14 | "swift": "alibabacloud-sdk-swift/tea-utils:1.0.3", 15 | "cpp": "alibabacloud-sdk-cpp/dara-util:master" 16 | }, 17 | "python": { 18 | "package": "alias_symbol", 19 | "clientName": "client", 20 | "modelDirName": "Models" 21 | }, 22 | "python2": { 23 | "package": "alias_symbol", 24 | "clientName": "client", 25 | "modelDirName": "Models" 26 | } 27 | } -------------------------------------------------------------------------------- /tests/fixtures/alias/libraries/Alias-Symbol/main.dara: -------------------------------------------------------------------------------- 1 | static function test(): void; 2 | 3 | model testModel { 4 | str: string 5 | } -------------------------------------------------------------------------------- /tests/fixtures/alias/libraries/Alias/Darafile: -------------------------------------------------------------------------------- 1 | { 2 | "scope": "alibabacloud", 3 | "name": "alias", 4 | "version": "0.0.1", 5 | "main": "./alias.dara", 6 | "releases": { 7 | "go": "github.com/alibabacloud-go/tea-utils/v2/service:v2.0.4", 8 | "ts": "@alicloud/tea-util:^1.4.7", 9 | "csharp": "AlibabaCloud.TeaUtil:0.1.17", 10 | "java": "com.aliyun:tea-util:0.2.21", 11 | "php": "alibabacloud/tea-utils:^0.2.19", 12 | "python": "alibabacloud_tea_util:0.3.11", 13 | "python2": "alibabacloud_tea_util_py2:0.0.9", 14 | "swift": "alibabacloud-sdk-swift/tea-utils:1.0.3", 15 | "cpp": "alibabacloud-sdk-cpp/dara-util:master" 16 | }, 17 | "python": { 18 | "package": "Alias", 19 | "clientName": "alias_client", 20 | "modelDirName": "Models" 21 | }, 22 | "python2": { 23 | "package": "Alias", 24 | "clientName": "alias_client", 25 | "modelDirName": "Models" 26 | } 27 | } -------------------------------------------------------------------------------- /tests/fixtures/alias/libraries/Alias/alias.dara: -------------------------------------------------------------------------------- 1 | static function test(): void; 2 | -------------------------------------------------------------------------------- /tests/fixtures/alias/libraries/AliasSource/Darafile: -------------------------------------------------------------------------------- 1 | { 2 | "scope": "alibabacloud", 3 | "name": "aliasSource", 4 | "version": "0.0.1", 5 | "main": "./main.dara", 6 | "python": { 7 | "package": "alias_source", 8 | "clientName": "source_client", 9 | "modelDirName": "Models" 10 | }, 11 | "python2": { 12 | "package": "alias_source", 13 | "clientName": "source_client", 14 | "modelDirName": "Models" 15 | } 16 | } -------------------------------------------------------------------------------- /tests/fixtures/alias/libraries/AliasSource/main.dara: -------------------------------------------------------------------------------- 1 | static function test(): void; 2 | -------------------------------------------------------------------------------- /tests/fixtures/alias/libraries/Import/Darafile: -------------------------------------------------------------------------------- 1 | { 2 | "scope": "alibabacloud", 3 | "name": "import", 4 | "version": "0.0.1", 5 | "main": "./import.dara", 6 | "python": { 7 | "package": "Import", 8 | "clientName": "client", 9 | "modelDirName": "Models" 10 | }, 11 | "python2": { 12 | "package": "Import", 13 | "clientName": "client", 14 | "modelDirName": "Models" 15 | }, 16 | "releases": { 17 | "python": "import:1.1.2", 18 | "python2": "import2:1.1.2" 19 | } 20 | } -------------------------------------------------------------------------------- /tests/fixtures/alias/libraries/Import/import.dara: -------------------------------------------------------------------------------- 1 | static function test(): void; 2 | -------------------------------------------------------------------------------- /tests/fixtures/alias/libraries/Source/Darafile: -------------------------------------------------------------------------------- 1 | { 2 | "scope": "alibabacloud", 3 | "name": "source", 4 | "version": "0.0.1", 5 | "main": "./source.dara", 6 | "python": { 7 | "package": "Source", 8 | "clientName": "client", 9 | "modelDirName": "Models" 10 | }, 11 | "python2": { 12 | "package": "Source", 13 | "clientName": "client", 14 | "modelDirName": "Models" 15 | }, 16 | "releases": { 17 | "python": "source:0.0.1", 18 | "python2": "source2:0.0.1" 19 | } 20 | } -------------------------------------------------------------------------------- /tests/fixtures/alias/libraries/Source/source.dara: -------------------------------------------------------------------------------- 1 | static async function test(): void; 2 | -------------------------------------------------------------------------------- /tests/fixtures/alias/main.dara: -------------------------------------------------------------------------------- 1 | import Source; 2 | import Import; 3 | import Alias; 4 | import AliasSource; 5 | import Alias-Symbol 6 | 7 | static async function emptyModel(): void { 8 | Import.test(); 9 | Source.test(); 10 | Alias.test(); 11 | AliasSource.test(); 12 | Alias-Symbol.test(); 13 | var model = new Alias-Symbol.testModel{}; 14 | } -------------------------------------------------------------------------------- /tests/fixtures/annotation/Darafile: -------------------------------------------------------------------------------- 1 | { 2 | "scope": "alibabacloud", 3 | "name": "main", 4 | "version": "0.0.1", 5 | "main": "./main.dara" 6 | } -------------------------------------------------------------------------------- /tests/fixtures/annotation/main.dara: -------------------------------------------------------------------------------- 1 | /** 2 | top annotation 3 | */ 4 | type @a = string 5 | 6 | /** 7 | TestModel 8 | */ 9 | model Test{ 10 | test: string(description='Alichange app id ', name='test') 11 | } 12 | 13 | /** 14 | Init Func 15 | */ 16 | init(){ 17 | } 18 | 19 | /** 20 | testAPI 21 | */ 22 | api testAPI(): void { 23 | } returns { 24 | return; 25 | } runtime {} 26 | 27 | /** 28 | testFunc 29 | */ 30 | static async function testFunc(): void { 31 | 32 | } -------------------------------------------------------------------------------- /tests/fixtures/api/Darafile: -------------------------------------------------------------------------------- 1 | { 2 | "scope": "alibabacloud", 3 | "name": "main", 4 | "version": "0.0.1", 5 | "main": "./main.dara" 6 | } -------------------------------------------------------------------------------- /tests/fixtures/api/main.dara: -------------------------------------------------------------------------------- 1 | init(); 2 | 3 | api hello(): void { 4 | __request.method = 'GET'; 5 | __request.pathname = '/'; 6 | __request.headers = { 7 | host = 'www.test.com', 8 | }; 9 | } returns { 10 | return; 11 | } 12 | 13 | api helloRuntime(): void { 14 | __request.method = 'GET'; 15 | __request.pathname = '/'; 16 | __request.headers = { 17 | host = 'www.test.com', 18 | }; 19 | } returns { 20 | return; 21 | } runtime { 22 | 23 | } 24 | -------------------------------------------------------------------------------- /tests/fixtures/builtin/Darafile: -------------------------------------------------------------------------------- 1 | { 2 | "scope": "alibabacloud", 3 | "name": "main", 4 | "version": "0.0.1", 5 | "main": "./main.dara" 6 | } -------------------------------------------------------------------------------- /tests/fixtures/builtin/main.dara: -------------------------------------------------------------------------------- 1 | static async function arrayTest(args: [string]): void { 2 | if((args.length() > 0) && args.contains('cn-hanghzou')) { 3 | var index = args.index('cn-hanghzou'); 4 | var regionId: string = args.get(index); 5 | var all = args.join(','); 6 | var first = args.shift(); 7 | var last = args.pop(); 8 | var length1 = args.unshift(first); 9 | var length2 = args.push(last); 10 | var length3:integer = length1 + length2; 11 | var longStr = 'long' + first + last; 12 | var fullStr = args.join(','); 13 | var newArr = ['test']; 14 | var cArr: [ string ] = newArr.concat(args); 15 | var acsArr = newArr.sort('acs'); 16 | var descArr = newArr.sort('desc'); 17 | var llArr: [string] = acsArr.concat(descArr); 18 | llArr.append('test', 10); 19 | llArr.remove('test'); 20 | } 21 | } 22 | 23 | static async function bytesTest(args: [string]): void { 24 | var fullStr = args.join(','); 25 | var data = fullStr.toBytes('utf8'); 26 | var newFullStr = data.toString(); 27 | if(fullStr != newFullStr) { 28 | return; 29 | } 30 | var hexStr = data.toHex(); 31 | 32 | var base64Str = data.toBase64(); 33 | 34 | var length: integer = data.length(); 35 | 36 | var obj = data.toJSON(); 37 | 38 | var data2 = $Bytes.from(fullStr, 'base64'); 39 | } 40 | 41 | static async function dateTest(args: [string]): void { 42 | var date = new $Date('2023-09-12 17:47:31.916000 +0800 UTC'); 43 | var dateStr = date.format('YYYY-MM-DD HH:mm:ss'); 44 | var timestamp = date.unix(); 45 | var yesterday = date.sub('day', 1); 46 | var oneDay = date.diff('day', yesterday); 47 | var tomorrow = date.add('day', 1); 48 | var twoDay = tomorrow.diff('day', date) + oneDay; 49 | var hour = date.hour(); 50 | var minute = date.minute(); 51 | var second = date.second(); 52 | var dayOfMonth = date.dayOfMonth(); 53 | var dayOfWeek = date.dayOfWeek(); 54 | var weekOfYear = date.weekOfYear(); 55 | var month = date.month(); 56 | var year = date.year(); 57 | var utcDate = date.UTC(); 58 | } 59 | 60 | static async function envTest(args: [string]): void { 61 | var es = $Env.get('TEST'); 62 | var ma = $Env.set('TEST', es + 'test'); 63 | } 64 | 65 | static async function fileTest(args: [string]): void { 66 | if($File.exists('/tmp/test')) { 67 | var file = new $File('/tmp/test'); 68 | var path = file.path(); 69 | var length = file.length() + 10; 70 | var createTime = file.createTime(); 71 | var modifyTime = file.modifyTime(); 72 | var timeLong = modifyTime.diff('minute', createTime); 73 | var data = file.read(300); 74 | file.write($Bytes.from('test', 'utf8')); 75 | var rs:readable = $File.createReadStream('/tmp/test'); 76 | var ws:writable = $File.createWriteStream('/tmp/test'); 77 | } 78 | } 79 | 80 | static async function formTest(args: [string]): void { 81 | var m = { 82 | key1 = 'test1', 83 | key2 = 'test2', 84 | key3 = 3, 85 | key4 = { 86 | key5 = 123, 87 | key6 = '321' 88 | } 89 | }; 90 | var form = $Form.toFormString(m); 91 | form = form + "&key7=23233&key8=" + $Form.getBoundary(); 92 | 93 | var r:readable = $Form.toFileForm(m, $Form.getBoundary()); 94 | } 95 | 96 | static async function jsonTest(args: [string]): void { 97 | var m = { 98 | key1 = 'test1', 99 | key2 = 'test2', 100 | key3 = 3, 101 | key4 = { 102 | key5 = 123, 103 | key6 = '321' 104 | } 105 | }; 106 | var ms = $JSON.stringify(m); 107 | var ma = $JSON.parseJSON(ms); 108 | var arrStr = '[1,2,3,4]'; 109 | var arr = $JSON.parseJSON(arrStr); 110 | } 111 | 112 | static async function logerTest(args: [string]): void { 113 | $Logger.log("test"); 114 | $Logger.info("test"); 115 | $Logger.warning("test"); 116 | $Logger.debug("test"); 117 | $Logger.error("test"); 118 | } 119 | 120 | static async function mapTestCase(args: [string]): void { 121 | var mapTest = { 122 | key1 = 'value1', 123 | key2 = 'value2', 124 | key3 = 'value3', 125 | }; 126 | 127 | var length = mapTest.length(); 128 | var num = length + 3; 129 | var keys = mapTest.keySet(); 130 | var allKey = ''; 131 | for(var key : keys) { 132 | allKey = allKey + key; 133 | } 134 | var entries: [ entry[string] ] = mapTest.entries(); 135 | var newKey = ''; 136 | var newValue = ''; 137 | for(var e : entries) { 138 | newKey = newKey + e.key(); 139 | newValue = newValue + e.value(); 140 | } 141 | 142 | var json = mapTest.toJSON(); 143 | var mapTest2 = { 144 | key1 = 'value4', 145 | key4 = 'value5', 146 | }; 147 | var mapTest3 = mapTest.merge(mapTest2); 148 | if(mapTest3['key1'] == 'value4') { 149 | return; 150 | } 151 | } 152 | 153 | static async function numberTest(args: [string]): void { 154 | var num = 3.2; 155 | var inum: integer = num.parseInt(); 156 | var lnum: long = num.parseLong(); 157 | var fnum: float = num.parseFloat(); 158 | var dnum: double = num.parseDouble(); 159 | 160 | inum = inum.parseInt(); 161 | lnum = inum.parseLong(); 162 | fnum = inum.parseFloat(); 163 | dnum = inum.parseDouble(); 164 | 165 | inum = lnum.parseInt(); 166 | lnum = lnum.parseLong(); 167 | fnum = lnum.parseFloat(); 168 | dnum = lnum.parseDouble(); 169 | 170 | inum = fnum.parseInt(); 171 | lnum = fnum.parseLong(); 172 | fnum = fnum.parseFloat(); 173 | dnum = fnum.parseDouble(); 174 | 175 | inum = dnum.parseInt(); 176 | lnum = dnum.parseLong(); 177 | fnum = dnum.parseFloat(); 178 | dnum = dnum.parseDouble(); 179 | 180 | lnum = inum.itol(); 181 | inum = lnum.ltoi(); 182 | 183 | var randomNum = $Number.random(); 184 | inum = $Number.floor(inum); 185 | inum = $Number.round(inum); 186 | } 187 | 188 | static async function streamTest(args: [string]): void { 189 | if($File.exists('/tmp/test')) { 190 | var rs:readable = $File.createReadStream('/tmp/test'); 191 | var ws:writable = $File.createWriteStream('/tmp/test'); 192 | var data = rs.read(30); 193 | ws.write(data); 194 | rs.pipe(ws); 195 | data = $Stream.readAsBytes(rs); 196 | var obj = $Stream.readAsJSON(rs); 197 | var jsonStr = $Stream.readAsString(rs); 198 | } 199 | } 200 | 201 | static async function stringTest(args: [string]): void { 202 | var fullStr = args.join(','); 203 | args = fullStr.split(','); 204 | 205 | if((fullStr.length() > 0) && fullStr.contains('hangzhou')) { 206 | var newStr1 = fullStr.replace('/hangzhou/g', 'beijing'); 207 | } 208 | 209 | if(fullStr.hasPrefix('cn')) { 210 | var newStr2 = fullStr.replace('/cn/gi', 'zh'); 211 | } 212 | 213 | if(fullStr.hasPrefix('beijing')) { 214 | var newStr3 = fullStr.replace('/beijing/', 'chengdu'); 215 | } 216 | 217 | var start = fullStr.index('beijing'); 218 | 219 | var end = start + 7; 220 | 221 | var region = fullStr.subString(start, end); 222 | 223 | var lowerRegion = region.toLower(); 224 | var upperRegion = region.toUpper(); 225 | 226 | if(region.equals('beijing')) { 227 | region = region + ' '; 228 | region = region.trim(); 229 | } 230 | 231 | var tb: bytes = fullStr.toBytes('utf8'); 232 | var em = 'xxx'; 233 | if(em.empty()) { 234 | return; 235 | } 236 | var num = '32.0a'; 237 | var inum = num.parseInt() + 3; 238 | var lnum:long = num.parseLong(); 239 | var fnum:float = num.parseFloat() + 1.0; 240 | var dnum:double = num.parseDouble() + 1.0d; 241 | } 242 | 243 | static async function urlTest(args: [string]): void { 244 | var url = new $URL(args[0]); 245 | var path = url.path(); 246 | var pathname = url.pathname(); 247 | var protocol = url.protocol(); 248 | var hostname = url.hostname(); 249 | var port = url.port(); 250 | var host = url.host(); 251 | var hash = url.hash(); 252 | var search = url.search(); 253 | var href = url.href(); 254 | var auth = url.auth(); 255 | var url2 = $URL.parse(args[1]); 256 | path = url2.path(); 257 | var newUrl = $URL.urlEncode(args[2]); 258 | var newSearch = $URL.percentEncode(search); 259 | var newPath = $URL.pathEncode(pathname); 260 | var all = 'test' + path + protocol + hostname + hash + search + href + auth + newUrl + newSearch + newPath; 261 | } 262 | 263 | static async function xmlTest(args: [string]): void { 264 | var m = { 265 | key1 = 'test1', 266 | key2 = 'test2', 267 | key3 = 3, 268 | key4 = { 269 | key5 = 123, 270 | key6 = '321' 271 | } 272 | }; 273 | var xml = $XML.toXML(m); 274 | xml = xml + "132"; 275 | 276 | var respMap : map[string]any = $XML.parseXml(xml, null); 277 | } 278 | 279 | static function returnAny(): any; 280 | 281 | static async function main(args: [string]):void { 282 | arrayTest(args); 283 | bytesTest(args); 284 | dateTest(args); 285 | envTest(args); 286 | fileTest(args); 287 | formTest(args); 288 | logerTest(args); 289 | mapTestCase(args); 290 | numberTest(args); 291 | streamTest(args); 292 | stringTest(args); 293 | urlTest(args); 294 | xmlTest(args); 295 | 296 | var a: integer = $integer(args[0]) + 10; 297 | var b: string = $string(a) + args[1] + $string(returnAny()); 298 | var c: number = $number(b) + $number(a) + $number(returnAny()); 299 | var d: int8 = $int8(b) + $int8(a) + $int8(returnAny()); 300 | var e: int16 = $int16(b) + $int16(a) + $int16(returnAny()); 301 | var f: int32 = $int32(b) + $int32(a) + $int32(returnAny()); 302 | var g: int64 = $int64(b) + $int64(a) + $int64(returnAny()); 303 | var h: long = $long(b) + $long(a) + $long(returnAny()); 304 | var i: ulong = $ulong(b) + $ulong(a) + $ulong(returnAny()); 305 | var j: uint8 = $uint8(b) + $uint8(a) + $uint8(returnAny()); 306 | var k: uint16 = $uint16(b) + $uint16(a) + $uint16(returnAny()); 307 | var l: uint32 = $uint32(b) + $uint32(a) + $uint32(returnAny()); 308 | var m: uint64 = $uint64(b) + $uint64(a) + $uint64(returnAny()); 309 | var n: float = $float(b) + $float(a) + $float(returnAny()); 310 | var o: double = $double(b) + $double(a) + $double(returnAny()); 311 | if($boolean(args[2])) { 312 | var data = $bytes(returnAny()); 313 | var length: integer = data.length(); 314 | var test: any = $any(data); 315 | var maps: map[string]string = { 316 | key = 'value', 317 | }; 318 | var obj: object = $object(maps); 319 | var ws = $writable(obj); 320 | var rs = $readable(maps); 321 | data = rs.read(30); 322 | if(!$isNull(data)) { 323 | ws.write(data); 324 | } 325 | } 326 | 327 | $sleep(a); 328 | var defaultVal = $string($default(args[0], args[1])); 329 | 330 | if($equal(defaultVal, b)) { 331 | return; 332 | } 333 | } -------------------------------------------------------------------------------- /tests/fixtures/comment/.libraries.json: -------------------------------------------------------------------------------- 1 | { 2 | "alibabacloud:Import:*": "./libraries" 3 | } -------------------------------------------------------------------------------- /tests/fixtures/comment/Darafile: -------------------------------------------------------------------------------- 1 | { 2 | "scope": "alibabacloud", 3 | "name": "main", 4 | "version": "0.0.1", 5 | "main": "./main.dara", 6 | "libraries": { 7 | "Source": "alibabacloud:Import:*" 8 | } 9 | } -------------------------------------------------------------------------------- /tests/fixtures/comment/libraries/Darafile: -------------------------------------------------------------------------------- 1 | { 2 | "scope": "alibabacloud", 3 | "name": "import", 4 | "version": "0.0.1", 5 | "main": "./import.dara", 6 | "java": { 7 | "package": "com.import", 8 | "baseClient": "com.import.baseclient.BaseClient" 9 | }, 10 | "csharp": { 11 | "namespace": "AlibabaCloud.import" 12 | }, 13 | "go": { 14 | "baseClient": "gitlab.alibaba-inc.com/alicloud-sdk/import/baseclient" 15 | }, 16 | "typescript": { 17 | "baseClient": "@ali/import-baseclient" 18 | }, 19 | "python": { 20 | "package": "import", 21 | "clientName": "client" 22 | }, 23 | "python2": { 24 | "package": "import", 25 | "clientName": "client" 26 | }, 27 | "releases": { 28 | "ts": "@scope/module:*" 29 | } 30 | } -------------------------------------------------------------------------------- /tests/fixtures/comment/libraries/import.dara: -------------------------------------------------------------------------------- 1 | model RuntimeObject = {} 2 | 3 | init(); 4 | 5 | function print(runtime: RuntimeObject): void { 6 | return; 7 | } 8 | 9 | model Request = { 10 | accesskey?: string(name='accesskey', description='accesskey'), 11 | region?: string(name='region', description='region'), 12 | } 13 | -------------------------------------------------------------------------------- /tests/fixtures/comment/main.dara: -------------------------------------------------------------------------------- 1 | // top comment 2 | /** 3 | top annotation 4 | */ 5 | // import comment 6 | import Source 7 | // type's comment 8 | type @a = [ string ] 9 | type @compleList = [[string]] 10 | type @endpointMap = map[string]string 11 | 12 | /** 13 | TestModel 14 | */ 15 | model Test1{ 16 | test: string(description='test desc', name='test'), //model的test back comment 17 | test2: string(description='test2 desc', name='test2', deprecated=true), //model的test2 back comment 18 | test3: [[string]](description='test3 desc', name='test3'), 19 | Test5: string(description='test desc', name='test5', deprecated=true), 20 | STS: string(description='sts desc', name='sts', deprecated=true), 21 | aSTS: string(description='asts desc', name='asts', deprecated=true), 22 | } 23 | 24 | /** 25 | TestModel2 26 | */ 27 | model Test2{ 28 | // model的test front comment 29 | test: string(description='test desc', name='test'), 30 | // model的test front comment 31 | test2: string(description='test2 desc', name='test2'), 32 | } 33 | 34 | /** 35 | TestModel3 36 | */ 37 | model Test3{ 38 | // model的test front comment 39 | test: string(description='test desc', name='test'), 40 | 41 | // empty comment1 42 | // empy comment2 43 | 44 | test1: string(description='test desc', name='test1'), //model的test back comment 45 | } 46 | 47 | /** 48 | Init Func 49 | */ 50 | // comment between init and annotation 51 | init(){ 52 | // string declate comment 53 | var str = 'sss'; 54 | // new model instance comment 55 | var modelInstance = new Test1{ 56 | test = 'test', //test declare back comment 57 | test2 = 'test2', //test2 declare back comment 58 | }; 59 | 60 | var array = [ 61 | // array string comment 62 | 'string', 63 | // array number comment 64 | 300 65 | // array back comment 66 | ]; 67 | } 68 | 69 | /** 70 | testAPI 71 | */ 72 | //testAPI comment one 73 | //testAPI comment two 74 | api testAPI(): void { 75 | // new model instance comment 76 | var modelInstance = new Test1{ 77 | // test declare front comment 78 | test = 'test', 79 | // test2 declare front comment 80 | test2 = 'test2', 81 | }; 82 | // number declare comment 83 | var num = 123; 84 | // static function call comment 85 | staticFunc(); 86 | } returns { 87 | // static async function call 88 | testFunc('test',true, [['str'], ['str1']]); 89 | // return comment 90 | return; 91 | } runtime { 92 | // empty runtime comment 93 | // another runtime comment 94 | } 95 | 96 | // testAPI2 comment 97 | api testAPI2(): void { 98 | // new model instance comment 99 | var modelInstance = new Test3{ 100 | //empty model 101 | }; 102 | // boolean declare comment 103 | var bool = true; 104 | if(bool){ 105 | //empty if 106 | }else{ 107 | //empty else 108 | } 109 | // api function call comment 110 | testAPI(); 111 | // back comment 112 | } returns { 113 | // empty return comment 114 | } runtime { 115 | // runtime retry comment 116 | retry = true 117 | // runtime back comment one 118 | // runtime back comment two 119 | } 120 | 121 | static function staticFunc(): void{ 122 | var a = [ 123 | // empty annotation comment 124 | ]; 125 | } 126 | 127 | /** 128 | * testFunc 129 | * @param str description: string parameter 130 | * @param val description: boolean parameter 131 | * @return `test` for return 132 | */ 133 | static async function testFunc(str: string, val: boolean, compleList:[[string]]): string { 134 | // empty comment1 135 | // empty comment2 136 | var s = 'test'; 137 | return s; 138 | } 139 | 140 | /** 141 | * testFuncComment 142 | * @param compleList list parameter 143 | * @param mapTest dict parameter 144 | * @param read readable parameter 145 | * @param anyTest any parameter 146 | * @param test1 Model parameter 147 | * @return void description for return 148 | */ 149 | static async function testFuncParams(compleList:[[string]], mapTest: map[string]string, read: readable, anyTest: any, test1: Test1): void { 150 | } -------------------------------------------------------------------------------- /tests/fixtures/complex/.libraries.json: -------------------------------------------------------------------------------- 1 | { 2 | "alibabacloud:Import:*": "libraries" 3 | } -------------------------------------------------------------------------------- /tests/fixtures/complex/Darafile: -------------------------------------------------------------------------------- 1 | { 2 | "scope": "alibabacloud", 3 | "name": "main", 4 | "version": "0.0.1", 5 | "main": "./main.dara", 6 | "libraries": { 7 | "Source": "alibabacloud:Import:*" 8 | } 9 | } -------------------------------------------------------------------------------- /tests/fixtures/complex/libraries/Darafile: -------------------------------------------------------------------------------- 1 | { 2 | "scope": "alibabacloud", 3 | "name": "import", 4 | "version": "0.0.1", 5 | "main": "./import.dara", 6 | "java": { 7 | "package": "com.import", 8 | "baseClient": "com.import.baseclient.BaseClient" 9 | }, 10 | "csharp": { 11 | "namespace": "AlibabaCloud.import" 12 | }, 13 | "go": { 14 | "baseClient": "gitlab.alibaba-inc.com/alicloud-sdk/import/baseclient" 15 | }, 16 | "typescript": { 17 | "baseClient": "@ali/import-baseclient" 18 | }, 19 | "php": { 20 | "package": "Source", 21 | "clientName": "SourceClient", 22 | "modelDirName": "Models" 23 | }, 24 | "python": { 25 | "package": "Source", 26 | "clientName": "source_client" 27 | }, 28 | "python2": { 29 | "package": "Source", 30 | "clientName": "source_client" 31 | }, 32 | "releases": { 33 | "ts": "@scope/name:*" 34 | } 35 | } -------------------------------------------------------------------------------- /tests/fixtures/complex/libraries/import.dara: -------------------------------------------------------------------------------- 1 | model RuntimeObject = {} 2 | 3 | type @protocol = string 4 | type @pathname = string 5 | 6 | init(config: Config); 7 | model Config = {} 8 | 9 | function printData(runtime: object, str: string): void { 10 | return; 11 | } 12 | 13 | async function printDataAsync(runtime: object, str: string): void { 14 | return; 15 | } 16 | 17 | @sse(true) 18 | async function printDataSSE(runtime: object, str: string): void { 19 | return; 20 | } 21 | 22 | 23 | static function judgeStr(a: string): boolean { 24 | return true; 25 | } 26 | 27 | static function query(q: object): map[string]string; 28 | static function body(): readable; 29 | static function parse(c: class): void; 30 | static async function asyncFunc(): void; 31 | 32 | model Request = { 33 | accesskey?: string(name='accesskey', description='accesskey'), 34 | region?: string(name='region', description='region'), 35 | instance: { 36 | instanceId: string(name='instanceId', description='instanceId'), 37 | }(name='instance', description='instance'), 38 | configs: { 39 | key: string, 40 | value: [ string ], 41 | extra: map[string] string 42 | }, 43 | } 44 | 45 | static function array(request: object, str: string): [ any ]; 46 | 47 | exception Err3 = { 48 | accessErrMessage: string 49 | } -------------------------------------------------------------------------------- /tests/fixtures/complex/main.dara: -------------------------------------------------------------------------------- 1 | import Source; 2 | 3 | extends Source; 4 | 5 | type @protocol = string 6 | type @pathname = string 7 | type @Strs = [ string ] 8 | type @compleList = [[string]] 9 | type @endpointMap = map[string]string 10 | type @configs = [ Source.Config ]; 11 | 12 | init(sourceConfig: Source.Config){ 13 | super(sourceConfig); 14 | @configs[0] = sourceConfig; 15 | var test : Source = new Source(sourceConfig); 16 | printData(sourceConfig, 'test'); 17 | } 18 | 19 | exception Err1 = { 20 | data: map[string]string 21 | } 22 | 23 | exception Err2 = { 24 | accessErrMessage: string 25 | } 26 | 27 | 28 | model ComplexRequest = { 29 | accessKey: string, 30 | body: readable(name='Body', example='Body', description='Body'), 31 | strs: [ string ](name='Strs', example='Strs', description='Strs'), 32 | mapList: [ map[string]any ](name='mapList', example='mapList', description='mapList', deprecated=false), 33 | header: { 34 | content: string(name='Content', example='Content 35 | 36 | test example 37 | test example11', signed='true', description='The ID of the security group to which you want to assign the instance. Instances in the same security group can communicate with each other. The maximum number of instances that a security group can contain depends on the type of the security group. For more information, see the "Security group limits" section in [Limits](https://help.aliyun.com/document_detail/25412.html#SecurityGroupQuota). 38 | 39 | >Notice: The network type of the new instance must be the same as that of the security group specified by the `SecurityGroupId` parameter. For example, if the specified security group is of the VPC type, the new instance is also of the VPC type and you must specify `VSwitchId`. 40 | 41 | If you do not use `LaunchTemplateId` or `LaunchTemplateName` to specify a launch template, you must specify SecurityGroupId. Take note of the following items: 42 | 43 | * You can set `SecurityGroupId` to specify a single security group or set `SecurityGroupIds.N` to specify one or more security groups. However, you cannot specify both `SecurityGroupId` and `SecurityGroupIds.N`. 44 | * If `NetworkInterface.N.InstanceType` is set to `Primary`, you cannot specify `SecurityGroupId` or `SecurityGroupIds.N` but can specify `NetworkInterface.N.SecurityGroupId` or `NetworkInterface.N.SecurityGroupIds.N`.', nullable=true, checkBlank=true, sensitive=false) 45 | }(description='header', name='header'), 46 | configs: { 47 | key: string, 48 | value: [ string ], 49 | extra: map[string] string 50 | }, 51 | num: number(name='num', nullable=false, checkBlank=false, sensitive=true), 52 | i64: int64, 53 | f64: double, 54 | b: boolean, 55 | f32: float, 56 | f64List: [ double ], 57 | floatList: [ float ], 58 | booleantList: [ boolean ], 59 | i32: int32, 60 | stringList: [ string ], 61 | intList: [ integer ], 62 | int32List: [ int32 ], 63 | int16List: [ int16 ], 64 | int64List: [ int64 ], 65 | longList: [ long ], 66 | uint64List: [ uint64 ], 67 | uint32List: [ uint32 ], 68 | uint16List: [ uint16 ], 69 | u64: uint64, 70 | u32: uint32, 71 | u16: uint16, 72 | obj: object, 73 | any: any, 74 | byt: bytes, 75 | req: $Request, 76 | resp: $Response, 77 | map: map[string]string, 78 | numMap: map[string]number, 79 | modelMap: map[string]Source.Request, 80 | request: Source.Request, 81 | client: Source, 82 | instance: Source.Request.instance, 83 | from: string(name='from', description='test keywords'), 84 | self: string(name='self', description='test keywords'), 85 | print: string(name='print', description='test keywords'), 86 | exec: string(name='exec', description='test keywords'), 87 | str: string(name='srt', description='test keywords'), 88 | part?: [ 89 | { 90 | partNumber?: string(description='PartNumber', name='PartNumber') 91 | } 92 | ](description='Part', name='Part', deprecated=true), 93 | } 94 | 95 | model Response { 96 | instance: ComplexRequest.part, 97 | } 98 | 99 | async function hello(request: object, strs: [ string ], complexList: [[string]]): [ string ] { 100 | var a : [[string]] = null; 101 | return array1(); 102 | } 103 | 104 | static async function print(reqeust: $Request, reqs: [ ComplexRequest ], response: $Response, val: map[string]string): Source.Request; 105 | 106 | static function intToInt32(a: int32):void; 107 | api Complex1(request: ComplexRequest, sourceClient: Source): Source.RuntimeObject { 108 | var name = 'complex'; 109 | var read : readable = null; 110 | var byt : bytes = null; 111 | var moduleModelMapVal: map[string] Source.RuntimeObject = {}; 112 | var moduleMapVal: map[string] Source = {}; 113 | var modelMapVal: map[string] ComplexRequest = {}; 114 | var subModelMapVal: map[string] ComplexRequest.header = {}; 115 | var reqMap : map[string]ComplexRequest = null; 116 | var mapString = { 117 | str = request.accessKey, 118 | }; 119 | var inte : integer = 1; 120 | var a : integer = 1; 121 | var b : int32 = null; 122 | b = a; 123 | var c : int32 = a; 124 | intToInt32(a); 125 | var mapVal = { 126 | read = read, 127 | test = '{"test":"ok"}', 128 | b = request.b, 129 | num = request.num, 130 | u16 = request.u16, 131 | u32 = request.u32, 132 | u64 = request.u64, 133 | u16List = request.uint16List, 134 | u32List = request.uint32List, 135 | u64List = request.uint64List, 136 | i64List = request.int64List, 137 | i16List = request.int16List, 138 | i32List = request.int32List, 139 | intList = request.intList, 140 | stringList = request.stringList, 141 | i32 = request.i32, 142 | booleantList = request.booleantList, 143 | floatList = request.floatList, 144 | float64List = request.f64List, 145 | f32 = request.f32, 146 | f64 = request.f64, 147 | i64 = request.i64, 148 | }; 149 | var abool = true; 150 | var req = new ComplexRequest{ 151 | b = false, 152 | num = 10, 153 | i32 = a, 154 | intList = [10,11], 155 | int16List = [10, 11], 156 | int32List = [10, 11], 157 | int64List = [10, 11], 158 | longList = [10L, 11L], 159 | floatList = [ 0.1f, 0.2f ], 160 | stringList = ['10','11'], 161 | booleantList = [ true, false ], 162 | }; 163 | var longList : [long] = [ 164 | 432435L 165 | ]; 166 | var anyList : [any] = [ 167 | 432435L, 168 | "str", 169 | true, 170 | 10, 171 | 0.1f 172 | ]; 173 | var floatMap : map[string]float = { 174 | key1 = 0.1f, 175 | key2 = 0.2 176 | }; 177 | var doubleMap : map[string]double = { 178 | key1 = 0.1d, 179 | key2 = 0.2d 180 | }; 181 | var intMap : map[string]integer = { 182 | key1 = 1, 183 | key2 = 2 184 | }; 185 | var longMap : map[string]long = { 186 | key1 = 1, 187 | key2 = 2 188 | }; 189 | var int16Map : map[string]int16 = { 190 | key1 = 1, 191 | key2 = 2 192 | }; 193 | var int32Map : map[string]int32 = { 194 | key1 = 1, 195 | key2 = 2 196 | }; 197 | var int64Map : map[string]int64 = { 198 | key1 = 1, 199 | key2 = 2 200 | }; 201 | var anyMap : map[string]any = { 202 | key1 = 0.1, 203 | key2 = 1, 204 | key3 = 'test', 205 | key4 = true, 206 | key5 = ['test', 1, true, ['test']], 207 | key6 = [ 208 | { 209 | a = "test", 210 | b = 1, 211 | c = true, 212 | d = ['test'], 213 | } 214 | ], 215 | }; 216 | 217 | for (var itemTmp : anyList) { 218 | $Logger.info(`${itemTmp}`); 219 | } 220 | 221 | for (var item : ["1","2"]) { 222 | var anyMap : map[string]string = {}; 223 | anyMap[item] = 'test'; 224 | break; 225 | } 226 | @Strs = request.strs; 227 | @protocol = 'test'; 228 | @endpointMap[@protocol]; 229 | @endpointMap['test'] = 'ok'; 230 | request.strs = @Strs; 231 | __request.protocol = @protocol; 232 | __request.port = request.num; 233 | __request.method = 'GET'; 234 | __request.pathname = `/${@pathname}`; 235 | __request.query = { 236 | date = '2019', 237 | name = __request.method, 238 | }; 239 | var tmp = { 240 | ...__request.query, 241 | ...__request.headers, 242 | ...__request, 243 | }; 244 | } returns { 245 | if (true && true){ 246 | return null; 247 | } else if(Source.judgeStr("test") || false){ 248 | return new Source.RuntimeObject{}; 249 | } 250 | sourceClient.printDataAsync(request, '1'); 251 | hello(request, ["1","2"], null); 252 | hello(null, null, null); 253 | return {}; 254 | Complex3(null, 'test'); 255 | return null; 256 | } runtime { 257 | timeouted = 'retry' 258 | } 259 | 260 | api Complex2(request: ComplexRequest, str: [ string ], val: map[string]string): object { 261 | var name = 'complex'; 262 | var config = new Source.Config{}; 263 | var sourceClient = new Source(config); 264 | var configArray : [Source.Config] = [config]; 265 | sourceClient.printDataSSE(request, '1'); 266 | __request.protocol = 'HTTP'; 267 | __request.port = 80; 268 | __request.method = 'GET'; 269 | __request.pathname = '/'; 270 | __request.query = { 271 | date = '2019', 272 | protocol = __request.protocol, 273 | }; 274 | } 275 | 276 | api ComplexMap(): map[string]any { 277 | } runtime { 278 | 279 | } 280 | 281 | api Complex3(request: ComplexRequest, name: string): ComplexRequest { 282 | name = 'complex'; 283 | __request.protocol = templateString(); 284 | __request.port = 80; 285 | __request.method = 'GET'; 286 | __request.pathname = '/'; 287 | __request.body = 'body'; 288 | __request.query = { 289 | date = '2019', 290 | }; 291 | var tmp : ComplexRequest = null; 292 | tmp = returnModel(); 293 | name = @protocol; 294 | } returns { 295 | var x = false; 296 | var y = true; 297 | var z = false; 298 | if (x && y || !z) { 299 | x = y; 300 | } 301 | var resp = __response; 302 | var req = new Source.Request{ 303 | accesskey = request.accessKey, 304 | region = resp.statusMessage 305 | }; 306 | array0(request); 307 | req.accesskey = 'accesskey'; 308 | req.accesskey = request.accessKey; 309 | printNull(); 310 | throwsFunc(); 311 | __response.statusCode; 312 | Source.array(request, '1'); 313 | return { 314 | ...__request.query 315 | }; 316 | } 317 | 318 | static function assignWithArray() throws: void { 319 | var list : [ string ] = null; 320 | list = [ "test" ]; 321 | 322 | var str : string = null; 323 | str = throwsFunc(); 324 | } 325 | 326 | function mapAcess(): any { 327 | var tmp : map[string]any = { 328 | protocol = @endpointMap[@protocol] 329 | }; 330 | return; 331 | } 332 | 333 | 334 | async function exprFunc(): [ string ] { 335 | if (!true) { 336 | 337 | } 338 | var num = 10; 339 | var req = new ComplexRequest{}; 340 | var mapVal : map[string]any = { 341 | num = 10, 342 | client = Source, 343 | strs = array1(), 344 | str = `string${num}`, 345 | str1 = `string${req.accessKey}`, 346 | }; 347 | return null; 348 | } 349 | 350 | static async function printNull(): void { 351 | try { 352 | var str = templateString(); 353 | } catch(e) { 354 | 355 | } finally { 356 | var final = 'ok'; 357 | } 358 | } 359 | 360 | static async function testTryWithComplexReturnType(): Source.Request { 361 | try { 362 | var str = templateString(); 363 | } catch(e) { 364 | 365 | } finally { 366 | var final = 'ok'; 367 | } 368 | return null; 369 | } 370 | 371 | static async function testTryWithComplexReturnTypeWithOutCat(): Source.Request { 372 | try { 373 | var str = templateString(); 374 | } catch(e) { 375 | var sim = 'a'; 376 | } finally { 377 | var final = 'ok'; 378 | } 379 | return null; 380 | } 381 | 382 | static function array0(req: object): [ any ] { 383 | return []; 384 | } 385 | 386 | static function array1(): [ string ] { 387 | return ["1"]; 388 | } 389 | 390 | async function templateString(): string { 391 | return `/${@protocol}`; 392 | } 393 | 394 | function intOp(a: integer): void { 395 | var b = a; 396 | var tmp: map[string]integer = { 397 | first = a 398 | }; 399 | b++; 400 | ++b; 401 | b--; 402 | --b; 403 | tmp.a++; 404 | ++tmp.a; 405 | tmp.a--; 406 | --tmp.a; 407 | } 408 | 409 | function throwsFunc() throws: string { 410 | return `/${@protocol}`; 411 | } 412 | 413 | function throwsFunc1() throws: string { 414 | return ''; 415 | } 416 | 417 | function throwsFunc2() throws: void { 418 | throw { 419 | code = '', 420 | }; 421 | } 422 | 423 | function throwsFunc3() throws: string { 424 | throw { 425 | code = '', 426 | }; 427 | } 428 | 429 | function getInt(num: int32): int32 { 430 | return num; 431 | } 432 | 433 | function returnFunc(): string { 434 | var index: int32 = 0; 435 | var i = getInt(index); 436 | return null; 437 | } 438 | 439 | function returnFunc1(cfg: Source.Config): Source { 440 | var config = new Source.Config{}; 441 | return new Source(config); 442 | } 443 | 444 | function returnFunc2(): map[string]any { 445 | var tmp = { 446 | subMap = 'ok', 447 | }; 448 | var mapVal = { 449 | test = tmp, 450 | }; 451 | if (Source.judgeStr("test")) { 452 | return mapVal['test']; 453 | } else { 454 | var body : readable = null; 455 | return { 456 | body = body, 457 | ...tmp 458 | }; 459 | } 460 | } 461 | 462 | function returnModel(): ComplexRequest { 463 | return new ComplexRequest{}; 464 | } 465 | 466 | function emptyFunc(): void; 467 | 468 | api noReturn(): void { 469 | } 470 | 471 | function Error(e: $Error): $Error { 472 | var tmp : $Error = null; 473 | var c : class = null; 474 | return e; 475 | } 476 | 477 | static function arrayAccess(): string { 478 | var configs = ['a', 'b', 'c']; 479 | var config = configs[0]; 480 | return config; 481 | } 482 | 483 | static function arrayAccess2(): string { 484 | var data = { 485 | configs = ['a', 'b', 'c'] 486 | }; 487 | var config = data.configs[0]; 488 | return config; 489 | } 490 | 491 | static function arrayAccess3(request: ComplexRequest): string { 492 | var req = new Source.Request{}; 493 | arrayAccess4([req]); 494 | var configVal = request.configs.value[0]; 495 | return configVal; 496 | } 497 | 498 | static function arrayAccess4(requests: [ Source.Request ]): string { 499 | return ''; 500 | } 501 | 502 | static function arrayAssign(config: string): [ string ] { 503 | var configs = ['a', 'b', 'c']; 504 | configs[3] = config; 505 | return configs; 506 | } 507 | 508 | static function arrayAssign2(config: string): [ string ] { 509 | var data = { 510 | configs = ['a', 'b', 'c'] 511 | }; 512 | data.configs[3] = config; 513 | return data.configs; 514 | } 515 | 516 | static function arrayAssign3(request: ComplexRequest, config: string): void { 517 | request.configs.value[0] = config; 518 | } 519 | 520 | static function mapAccess(request: ComplexRequest): string { 521 | var configInfo = request.configs.extra['name']; 522 | return configInfo; 523 | } 524 | 525 | static function mapAccess2(request: Source.Request): string { 526 | var configInfo = request.configs.extra['name']; 527 | return configInfo; 528 | } 529 | 530 | static function mapAccess3(): string { 531 | var data = { 532 | configs = { 533 | value = 'string' 534 | } 535 | }; 536 | return data.configs['value']; 537 | } 538 | 539 | static function mapAccess4(request: ComplexRequest): string { 540 | var key : string = 'name'; 541 | var model = request.modelMap[key]; 542 | var configInfo = request.configs.extra[key]; 543 | return configInfo; 544 | } 545 | 546 | static function mapAssign(request: ComplexRequest, name: string): void { 547 | request.configs.extra['name'] = name; 548 | var key : string = 'name'; 549 | name = key; 550 | request.configs.extra[key] = name; 551 | name = request.configs.extra['name']; 552 | request.map[key] = name; 553 | request.numMap[key] = 1; 554 | } 555 | 556 | static function arrayimport2(request: [ Source.Request ]): string { 557 | return ''; 558 | } 559 | 560 | static async function defaultReturn(): void { 561 | if (true) { 562 | 563 | } else { 564 | 565 | } 566 | } 567 | 568 | static function strFmt(): void { 569 | var s = 'strtest'; 570 | var s1 = ` % 1${s}`; 571 | var s2 = ` "hello" 'world' ${s}`; 572 | var s3 = `hello world`; 573 | var s4 = `{ 574 | "json": "json val", 575 | "key": "value" 576 | }`; 577 | var s5 = ` %s str:${s}`; 578 | var s6 = ` %%s str`; 579 | var fs1 = `{"key": "${s}"}`; 580 | var fs2 = `{{"key": "${s}"}}`; 581 | var fs3 = `${} ${s}`; 582 | } 583 | 584 | async function multiTryCatch(a: number): void { 585 | try { 586 | if(a > 0) { 587 | throw new Err1 { 588 | name = "str", 589 | code = "str", 590 | data = { 591 | key1 = "str", 592 | } 593 | }; 594 | } else if(a == 0) { 595 | throw new Err2 { 596 | name = "str", 597 | code = "str", 598 | accessErrMessage = "str2", 599 | }; 600 | } else if(a == -10) { 601 | throw new Source.Err3 { 602 | name = "str", 603 | code = "str", 604 | }; 605 | } else { 606 | throw new $Error{ 607 | name = "str", 608 | code = "str", 609 | } 610 | } 611 | } catch(err1: Err1) { 612 | $Logger.log(err1.name); 613 | } catch(err2: Err2) { 614 | $Logger.log(err2.name); 615 | } catch(err3: Source.Err3) { 616 | $Logger.log(err3.name); 617 | } catch(err) { 618 | $Logger.log(err.name); 619 | } finally { 620 | var final = 'ok'; 621 | } 622 | } 623 | -------------------------------------------------------------------------------- /tests/fixtures/const/Darafile: -------------------------------------------------------------------------------- 1 | { 2 | "scope": "alibabacloud", 3 | "name": "main", 4 | "version": "0.0.1", 5 | "main": "./main.dara" 6 | } -------------------------------------------------------------------------------- /tests/fixtures/const/main.dara: -------------------------------------------------------------------------------- 1 | const world = "World!"; 2 | 3 | static function hello(): string { 4 | return `'Hello' ${__module.world}`; 5 | } 6 | -------------------------------------------------------------------------------- /tests/fixtures/empty/Darafile: -------------------------------------------------------------------------------- 1 | { 2 | "scope": "alibabacloud", 3 | "name": "main", 4 | "version": "0.0.1", 5 | "main": "./main.dara" 6 | } -------------------------------------------------------------------------------- /tests/fixtures/empty/main.dara: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/fixtures/exec/Darafile: -------------------------------------------------------------------------------- 1 | { 2 | "scope": "alibabacloud", 3 | "name": "main", 4 | "version": "0.0.1", 5 | "main": "./main.dara" 6 | } -------------------------------------------------------------------------------- /tests/fixtures/exec/main.dara: -------------------------------------------------------------------------------- 1 | static function main(args: [string]): void {} -------------------------------------------------------------------------------- /tests/fixtures/function/Darafile: -------------------------------------------------------------------------------- 1 | { 2 | "scope": "alibabacloud", 3 | "name": "main", 4 | "version": "0.0.1", 5 | "main": "./main.dara" 6 | } -------------------------------------------------------------------------------- /tests/fixtures/function/main.dara: -------------------------------------------------------------------------------- 1 | init(){ 2 | } 3 | 4 | static function hello(): void { 5 | return; 6 | } 7 | 8 | static function helloMap(): map[string]string { 9 | var m: map[string]string = {}; 10 | return { 11 | key = 'value', 12 | key-1 = 'value-1', 13 | 'key-2' = 'value-2', 14 | '""' = 'value-3', 15 | ...m, 16 | }; 17 | } 18 | 19 | static function helloArrayMap(): [map[string]string] { 20 | return [ 21 | { 22 | key = 'value', 23 | } 24 | ]; 25 | } 26 | 27 | static async function helloParams(a: string, b: string): void { 28 | helloInterface(); 29 | helloArrayMap(); 30 | } 31 | 32 | // interface mode 33 | static async function helloInterface(): void; 34 | 35 | async function aParams(): void { 36 | helloParams("a", "b"); 37 | } -------------------------------------------------------------------------------- /tests/fixtures/import/.libraries.json: -------------------------------------------------------------------------------- 1 | { 2 | "alibabacloud:Import:*": "./libraries", 3 | "Local": "./pack/" 4 | } -------------------------------------------------------------------------------- /tests/fixtures/import/Darafile: -------------------------------------------------------------------------------- 1 | { 2 | "scope": "alibabacloud", 3 | "name": "main", 4 | "version": "0.0.1", 5 | "main": "./main.dara", 6 | "libraries": { 7 | "Source": "alibabacloud:Import:*", 8 | "Local": "./pack/" 9 | } 10 | } -------------------------------------------------------------------------------- /tests/fixtures/import/libraries/Darafile: -------------------------------------------------------------------------------- 1 | { 2 | "scope": "alibabacloud", 3 | "name": "import", 4 | "version": "0.0.1", 5 | "main": "./import.dara", 6 | "java": { 7 | "package": "com.import", 8 | "baseClient": "com.import.baseclient.BaseClient" 9 | }, 10 | "csharp": { 11 | "namespace": "AlibabaCloud.import" 12 | }, 13 | "go": { 14 | "baseClient": "gitlab.alibaba-inc.com/alicloud-sdk/import/baseclient" 15 | }, 16 | "typescript": { 17 | "baseClient": "@ali/import-baseclient" 18 | }, 19 | "php": { 20 | "package": "Source", 21 | "clientName": "SourceClient", 22 | "modelDirName": "Models" 23 | }, 24 | "python": { 25 | "package": "Source", 26 | "clientName": "source_client" 27 | }, 28 | "python2": { 29 | "package": "Source", 30 | "clientName": "source_client" 31 | }, 32 | "releases": { 33 | "python": "alibabacloud_import:0.0.1rc1", 34 | "python2": "alibabacloud_import_py2:0.0.1" 35 | } 36 | } -------------------------------------------------------------------------------- /tests/fixtures/import/libraries/import.dara: -------------------------------------------------------------------------------- 1 | model RuntimeObject = {} 2 | 3 | init(); 4 | 5 | function print(runtime: RuntimeObject): void { 6 | return; 7 | } 8 | 9 | model Request = { 10 | accesskey?: string(name='accesskey', description='accesskey'), 11 | region?: string(name='region', description='region'), 12 | } 13 | -------------------------------------------------------------------------------- /tests/fixtures/import/main.dara: -------------------------------------------------------------------------------- 1 | import Source; 2 | import Local; 3 | 4 | type @id = [ string ]; 5 | type @str = string; 6 | type @model = Local.Local; 7 | 8 | 9 | static function Sample(client: Source): void { 10 | var runtime = new Source.RuntimeObject{}; 11 | var request = new Source.Request{ 12 | accesskey = "accesskey", 13 | region = "region", 14 | }; 15 | client.print(runtime); 16 | } 17 | -------------------------------------------------------------------------------- /tests/fixtures/import/pack/Darafile: -------------------------------------------------------------------------------- 1 | { 2 | "scope": "alibabacloud", 3 | "name": "local", 4 | "version": "0.0.1", 5 | "main": "./local.dara", 6 | "python": { 7 | "package": "Local" 8 | }, 9 | "releases": { 10 | "python": "alibabacloud_local:0.0.1", 11 | "python2": "alibabacloud_local_py2:0.0.1" 12 | } 13 | } -------------------------------------------------------------------------------- /tests/fixtures/import/pack/local.dara: -------------------------------------------------------------------------------- 1 | init(); 2 | 3 | model Local = { 4 | test?: string(name='test'), 5 | } 6 | -------------------------------------------------------------------------------- /tests/fixtures/map/.libraries.json: -------------------------------------------------------------------------------- 1 | { 2 | "alibabacloud:Import:*": "libraries" 3 | } -------------------------------------------------------------------------------- /tests/fixtures/map/Darafile: -------------------------------------------------------------------------------- 1 | { 2 | "scope": "tests", 3 | "name": "super", 4 | "version": "0.0.1", 5 | "main": "./main.dara", 6 | "libraries": { 7 | "Source": "alibabacloud:Import:*" 8 | } 9 | } -------------------------------------------------------------------------------- /tests/fixtures/map/libraries/Darafile: -------------------------------------------------------------------------------- 1 | { 2 | "scope": "alibabacloud", 3 | "name": "import", 4 | "version": "0.0.1", 5 | "main": "./import.dara", 6 | "releases": { 7 | "ts": "@scope/name:*" 8 | }, 9 | "php": { 10 | "package": "Source", 11 | "clientName": "SourceClient", 12 | "modelDirName": "Models" 13 | }, 14 | "python": { 15 | "package": "Source", 16 | "clientName": "source_client" 17 | }, 18 | "python2": { 19 | "package": "Source", 20 | "clientName": "source_client" 21 | } 22 | } -------------------------------------------------------------------------------- /tests/fixtures/map/libraries/import.dara: -------------------------------------------------------------------------------- 1 | type @endpointRule = string 2 | type @endpointMap = map[string]string 3 | 4 | init(config: Config); 5 | model Config = { 6 | strValue:string 7 | } 8 | 9 | static function hello(): string { 10 | return 'str'; 11 | } 12 | -------------------------------------------------------------------------------- /tests/fixtures/map/main.dara: -------------------------------------------------------------------------------- 1 | import Source; 2 | 3 | extends Source; 4 | 5 | init(config: Source.Config){ 6 | super(config); 7 | var a = { 8 | "test" = "test", 9 | }; 10 | var c = { 11 | "test" = "test", 12 | }; 13 | @endpointRule = 'central'; 14 | @endpointMap = { 15 | "ap-northeast-1" = 'cusanalytic.aliyuncs.com', 16 | "ap-south-1" = 'cusanalytic.aliyuncs.com', 17 | ...a, 18 | ...c, 19 | ap-south-2-test = Source.hello(), 20 | }; 21 | var b = { 22 | "ap-northeast-1" = { 23 | "ap-south-1" = 'cusanalytic.aliyuncs.com', 24 | }, 25 | "ap-south-2" = Source.hello(), 26 | }; 27 | @endpointMap['ap-northeast-1']; 28 | @endpointMap['ap-northeast-1'] = ""; 29 | @endpointMap[config.strValue] = 'str'; 30 | @endpointMap[config.strValue]; 31 | } -------------------------------------------------------------------------------- /tests/fixtures/model/.libraries.json: -------------------------------------------------------------------------------- 1 | { 2 | "darabonba:Import:*": "libraries" 3 | } -------------------------------------------------------------------------------- /tests/fixtures/model/Darafile: -------------------------------------------------------------------------------- 1 | { 2 | "scope": "darabonba", 3 | "name": "main", 4 | "version": "0.0.1", 5 | "main": "./main.dara", 6 | "libraries": { 7 | "Source": "darabonba:Import:*" 8 | } 9 | } -------------------------------------------------------------------------------- /tests/fixtures/model/libraries/Darafile: -------------------------------------------------------------------------------- 1 | { 2 | "scope": "darabonba", 3 | "name": "import", 4 | "version": "0.0.1", 5 | "main": "./import.dara", 6 | "java": { 7 | "package": "com.import" 8 | }, 9 | "csharp": { 10 | "namespace": "Darabonba.import" 11 | }, 12 | "python": { 13 | "package": "Source", 14 | "clientName": "client", 15 | "modelDirName": "Models" 16 | }, 17 | "releases": { 18 | "php": "scope/name:1.0.0" 19 | } 20 | } -------------------------------------------------------------------------------- /tests/fixtures/model/libraries/import.dara: -------------------------------------------------------------------------------- 1 | model RuntimeObject = {} 2 | 3 | static function array(request: object, str: string): [ any ]; 4 | 5 | static function query(q: object): map[string]string; 6 | static function body(): readable; 7 | static function parse(c: class): void; 8 | static async function asyncFunc(): void; 9 | 10 | type @protocol = string 11 | type @pathname = string 12 | type @API = map[string]string 13 | 14 | init(config: Config); 15 | model Config = {} 16 | function print(runtime: object, str: string): void { 17 | return; 18 | } 19 | 20 | async function printAsync(runtime: object, str: string): void { 21 | return; 22 | } 23 | 24 | model Request = { 25 | accesskey?: string(name='accesskey', description='accesskey'), 26 | region?: string(name='region', description='region'), 27 | } 28 | -------------------------------------------------------------------------------- /tests/fixtures/model/main.dara: -------------------------------------------------------------------------------- 1 | import Source; 2 | 3 | model M = { 4 | subM: {} 5 | }; 6 | 7 | model Class = {}; 8 | 9 | model model = { 10 | str: string 11 | } 12 | 13 | exception MainFile extends $Error { 14 | size: number, 15 | data: map[string]model, 16 | model: { 17 | str: string, 18 | model: { 19 | str: string 20 | }, 21 | } 22 | } 23 | 24 | model MyModel = { 25 | model: { 26 | str: string, 27 | model: { 28 | str: string 29 | }, 30 | }, 31 | stringfield: string, 32 | bytesfield: bytes, 33 | stringarrayfield: [ string ], 34 | mapfield: map[string]string, 35 | name: string(name='realName'), 36 | submodel: { 37 | stringfield: string, 38 | model: { 39 | str: string 40 | }, 41 | }, 42 | submodelMap: map[string]MyModel.submodel, 43 | mapModel: map[string]M, 44 | subarraymodel: [ {} ], 45 | subarray: [ M ], 46 | ssubarray: [[ M ]], 47 | ssubmarray: [[ Source ]], 48 | sssubmarray: [[ Source ]], 49 | ssubmmarray: [[ Source.Request ]], 50 | sssubmmarray: [[[ Source.Request ]]], 51 | maparray: [ map[string]any ], 52 | mapsubmarray: [ map[string]Source ], 53 | moduleModelMap: map[string]Source.Request, 54 | arrModuleModelMap: [ map[string]Source.Request ], 55 | arrsModuleModelMap: [[ map[string]Source.Request ]], 56 | subModelMap: map[string]M.subM, 57 | modelMap: map[string]M, 58 | moduleMap: map[string]Source, 59 | object: object, 60 | readable: readable, 61 | writable: writable, 62 | existModel: M, 63 | request: $Request, 64 | complexList: [ [ string ] ], 65 | numberfield: number, 66 | integerField: integer, 67 | floatField: float, 68 | doubleField: double, 69 | longField: long, 70 | ulongField: ulong, 71 | int8Field: int8, 72 | int16Field: int16, 73 | int32Field: int32, 74 | int64Field: int64, 75 | uint8Field: uint8, 76 | uint16Field: uint16, 77 | uint32Field: uint32, 78 | uint64Field: uint64, 79 | link?: string(name='link', example='http://*/*.png'), 80 | }; 81 | 82 | -------------------------------------------------------------------------------- /tests/fixtures/modelConfig/.libraries.json: -------------------------------------------------------------------------------- 1 | { 2 | "darabonba:Import:*": "libraries" 3 | } -------------------------------------------------------------------------------- /tests/fixtures/modelConfig/Darafile: -------------------------------------------------------------------------------- 1 | { 2 | "scope": "darabonba", 3 | "name": "main", 4 | "version": "0.0.1", 5 | "main": "./main.dara", 6 | "libraries": { 7 | "Source": "darabonba:Import:*" 8 | }, 9 | "python": { 10 | "noneEmpty": true, 11 | "strictModel": true 12 | } 13 | } -------------------------------------------------------------------------------- /tests/fixtures/modelConfig/libraries/Darafile: -------------------------------------------------------------------------------- 1 | { 2 | "scope": "darabonba", 3 | "name": "import", 4 | "version": "0.0.1", 5 | "main": "./import.dara", 6 | "java": { 7 | "package": "com.import" 8 | }, 9 | "csharp": { 10 | "namespace": "Darabonba.import" 11 | }, 12 | "python": { 13 | "package": "Source", 14 | "clientName": "client", 15 | "modelDirName": "Models" 16 | }, 17 | "releases": { 18 | "php": "scope/name:1.0.0" 19 | } 20 | } -------------------------------------------------------------------------------- /tests/fixtures/modelConfig/libraries/import.dara: -------------------------------------------------------------------------------- 1 | model RuntimeObject = {} 2 | 3 | static function array(request: object, str: string): [ any ]; 4 | 5 | static function query(q: object): map[string]string; 6 | static function body(): readable; 7 | static function parse(c: class): void; 8 | static async function asyncFunc(): void; 9 | 10 | type @protocol = string 11 | type @pathname = string 12 | type @API = map[string]string 13 | 14 | init(config: Config); 15 | model Config = {} 16 | function print(runtime: object, str: string): void { 17 | return; 18 | } 19 | 20 | async function printAsync(runtime: object, str: string): void { 21 | return; 22 | } 23 | 24 | model Request = { 25 | accesskey?: string(name='accesskey', description='accesskey'), 26 | region?: string(name='region', description='region'), 27 | } 28 | -------------------------------------------------------------------------------- /tests/fixtures/modelConfig/main.dara: -------------------------------------------------------------------------------- 1 | import Source; 2 | 3 | model M = { 4 | subM: {} 5 | }; 6 | 7 | model Class = {}; 8 | 9 | model model = { 10 | str: string 11 | } 12 | 13 | exception MainFile extends $Error { 14 | size: number, 15 | data: map[string]model, 16 | model: { 17 | str: string, 18 | model: { 19 | str: string 20 | }, 21 | } 22 | } 23 | 24 | model MyModel = { 25 | model: { 26 | str: string, 27 | model: { 28 | str: string 29 | }, 30 | }, 31 | stringfield: string, 32 | bytesfield: bytes, 33 | stringarrayfield: [ string ], 34 | mapfield: map[string]string, 35 | name: string(name='realName'), 36 | submodel: { 37 | stringfield: string, 38 | model: { 39 | str: string 40 | }, 41 | }, 42 | submodelMap: map[string]MyModel.submodel, 43 | mapModel: map[string]M, 44 | subarraymodel: [ {} ], 45 | subarray: [ M ], 46 | ssubarray: [[ M ]], 47 | ssubmarray: [[ Source ]], 48 | sssubmarray: [[ Source ]], 49 | ssubmmarray: [[ Source.Request ]], 50 | sssubmmarray: [[[ Source.Request ]]], 51 | maparray: [ map[string]any ], 52 | mapsubmarray: [ map[string]Source ], 53 | moduleModelMap: map[string]Source.Request, 54 | arrModuleModelMap: [ map[string]Source.Request ], 55 | arrsModuleModelMap: [[ map[string]Source.Request ]], 56 | subModelMap: map[string]M.subM, 57 | modelMap: map[string]M, 58 | moduleMap: map[string]Source, 59 | object: object, 60 | readable: readable, 61 | writable: writable, 62 | existModel: M, 63 | request: $Request, 64 | complexList: [ [ string ] ], 65 | numberfield: number, 66 | integerField: integer, 67 | floatField: float, 68 | doubleField: double, 69 | longField: long, 70 | ulongField: ulong, 71 | int8Field: int8, 72 | int16Field: int16, 73 | int32Field: int32, 74 | int64Field: int64, 75 | uint8Field: uint8, 76 | uint16Field: uint16, 77 | uint32Field: uint32, 78 | uint64Field: uint64, 79 | link?: string(name='link', example='http://*/*.png'), 80 | }; 81 | 82 | -------------------------------------------------------------------------------- /tests/fixtures/multi/.libraries.json: -------------------------------------------------------------------------------- 1 | { 2 | "darabonba:Util:*": "libraries/darabonba_Util_0.2.11" 3 | } -------------------------------------------------------------------------------- /tests/fixtures/multi/Darafile: -------------------------------------------------------------------------------- 1 | { 2 | "scope": "darabonba", 3 | "name": "Util", 4 | "version": "0.2.10", 5 | "main": "./main.dara", 6 | "releases": { 7 | "go": "darabonba.com/multi/client:v1.0.0" 8 | }, 9 | "libraries": { 10 | "DARAUtil": "darabonba:Util:*" 11 | } 12 | } -------------------------------------------------------------------------------- /tests/fixtures/multi/api.dara: -------------------------------------------------------------------------------- 1 | import "./model/user" User; 2 | import "./lib/util" Util; 3 | 4 | model TestModelDir2 { 5 | test: number, 6 | } 7 | 8 | init(){ 9 | } 10 | 11 | api test3(): number { 12 | __request.protocol = "https"; 13 | __request.method = 'DELETE'; 14 | __request.pathname = "/"; 15 | __request.headers = { 16 | host = "test.aliyun.com", 17 | accept = 'application/json', 18 | }; 19 | __request.query = Util.getQuery(); 20 | } returns { 21 | return __response.statusCode; 22 | } runtime { 23 | timeouted = 'retry' 24 | } 25 | -------------------------------------------------------------------------------- /tests/fixtures/multi/lib/util.dara: -------------------------------------------------------------------------------- 1 | @clientName("Util"); 2 | 3 | static function test1(): iterator[string]; 4 | 5 | static function getQuery(): map[string]string; -------------------------------------------------------------------------------- /tests/fixtures/multi/libraries/darabonba_Util_0.2.11/Teafile: -------------------------------------------------------------------------------- 1 | { 2 | "scope": "darabonba", 3 | "name": "Util", 4 | "version": "0.2.11", 5 | "main": "./main.tea", 6 | "exports": { 7 | "Util": "./util.tea" 8 | }, 9 | "releases": { 10 | "go": "github.com/alibabacloud-go/tea-utils/v2/service:v2.0.4", 11 | "ts": "@alicloud/tea-util:^1.4.7", 12 | "csharp": "AlibabaCloud.TeaUtil:0.1.17", 13 | "java": "com.aliyun:tea-util:0.2.21", 14 | "php": "alibabacloud/tea-utils:^0.2.19", 15 | "python": "alibabacloud_tea_util:0.3.11", 16 | "python2": "alibabacloud_tea_util_py2:0.0.9", 17 | "swift": "alibabacloud-sdk-swift/tea-utils:1.0.3", 18 | "cpp": "alibabacloud-sdk-cpp/dara-util:master" 19 | }, 20 | "java": { 21 | "package": "com.aliyun.teautil", 22 | "className": "Common" 23 | }, 24 | "csharp": { 25 | "namespace": "AlibabaCloud.TeaUtil", 26 | "className": "Common" 27 | }, 28 | "php": { 29 | "package": "AlibabaCloud.Tea.Utils", 30 | "clientName": "Utils", 31 | "modelDirName": "Utils" 32 | }, 33 | "python": { 34 | "package": "alibabacloud_tea_util", 35 | "clientName": "client", 36 | "exports": { 37 | "Util": "Utils" 38 | } 39 | }, 40 | "python2": { 41 | "package": "alibabacloud_tea_util", 42 | "clientName": "client" 43 | }, 44 | "cpp": { 45 | "packageInfo": { 46 | "git": { 47 | "scope": "alibabacloud-sdk-cpp", 48 | "project": "dara-util" 49 | } 50 | } 51 | }, 52 | "swift": { 53 | "clientName": "Client", 54 | "packageInfo": { 55 | "name": "TeaUtils", 56 | "desc": "Alibaba Cloud Tea Util for Swift", 57 | "github": "https://github.com/alibabacloud-sdk-swift/tea-utils", 58 | "author": "Alibaba Cloud SDK", 59 | "email": "sdk-team@alibabacloud.com" 60 | } 61 | }, 62 | "releaselog": { 63 | "changelog": [ 64 | "[java]fix: enable getNonce() on Android platform." 65 | ], 66 | "compatible": true 67 | } 68 | } -------------------------------------------------------------------------------- /tests/fixtures/multi/libraries/darabonba_Util_0.2.11/main.tea: -------------------------------------------------------------------------------- 1 | /** 2 | * This is a utility module 3 | */ 4 | 5 | /** 6 | * The common runtime options model 7 | */ 8 | model RuntimeOptions { 9 | autoretry?: boolean(description='whether to try again', name='autoretry'), 10 | ignoreSSL?: boolean(description='ignore SSL validation', name='ignoreSSL'), 11 | key?: string(description='privite key for client certificate', name='key'), 12 | cert?: string(description='client certificate', name='cert'), 13 | ca?: string(description='server certificate', name='ca'), 14 | maxAttempts?: number(description='maximum number of retries', name='max_attempts'), 15 | backoffPolicy?: string(description='backoff policy', name='backoff_policy'), 16 | backoffPeriod?: number(description='backoff period', name='backoff_period'), 17 | readTimeout?: number(description='read timeout', name='readTimeout'), 18 | connectTimeout?: number(description='connect timeout', name='connectTimeout'), 19 | httpProxy?: string(description='http proxy url', name='httpProxy'), 20 | httpsProxy?: string(description='https Proxy url', name='httpsProxy'), 21 | noProxy?: string(description='agent blacklist', name='noProxy'), 22 | maxIdleConns?: number(description='maximum number of connections', name='maxIdleConns'), 23 | localAddr?: string(description='local addr', name='localAddr'), 24 | socks5Proxy?: string(description='SOCKS5 proxy', name='socks5Proxy'), 25 | socks5NetWork?: string(description='SOCKS5 netWork', name='socks5NetWork'), 26 | keepAlive?: boolean(description='whether to enable keep-alive', name='keepAlive'), 27 | } 28 | 29 | /** 30 | * Convert a string(utf8) to bytes 31 | * @return the return bytes 32 | */ 33 | static function toBytes(val: string): bytes; 34 | 35 | /** 36 | * Convert a bytes to string(utf8) 37 | * @return the return string 38 | */ 39 | static function toString(val: bytes): string; 40 | 41 | /** 42 | * Parse it by JSON format 43 | * @return the parsed result 44 | */ 45 | static function parseJSON(val: string): any; 46 | 47 | /** 48 | * Read data from a readable stream, and compose it to a bytes 49 | * @param stream the readable stream 50 | * @return the bytes result 51 | */ 52 | static async function readAsBytes(stream: readable): bytes; 53 | 54 | /** 55 | * Read data from a readable stream, and compose it to a string 56 | * @param stream the readable stream 57 | * @return the string result 58 | */ 59 | static async function readAsString(stream: readable): string { 60 | var buff = readAsBytes(stream); 61 | return toString(buff); 62 | } 63 | 64 | /** 65 | * Read data from a readable stream, and parse it by JSON format 66 | * @param stream the readable stream 67 | * @return the parsed result 68 | */ 69 | static async function readAsJSON(stream: readable): any { 70 | return parseJSON(readAsString(stream)); 71 | } 72 | 73 | /** 74 | * Generate a nonce string 75 | * @return the nonce string 76 | */ 77 | static function getNonce(): string; 78 | 79 | /** 80 | * Get an UTC format string by current date, e.g. 'Thu, 06 Feb 2020 07:32:54 GMT' 81 | * @return the UTC format string 82 | */ 83 | static function getDateUTCString(): string; 84 | 85 | /** 86 | * If not set the real, use default value 87 | * @return the return string 88 | */ 89 | static function defaultString(real: string, default: string): string; 90 | 91 | /** 92 | * If not set the real, use default value 93 | * @return the return number 94 | */ 95 | static function defaultNumber(real: number, default: number): number; 96 | 97 | /** 98 | * Format a map to form string, like a=a%20b%20c 99 | * @return the form string 100 | */ 101 | static function toFormString(val: object): string; 102 | 103 | /** 104 | * Stringify a value by JSON format 105 | * @return the JSON format string 106 | */ 107 | static function toJSONString(val: any): string; 108 | 109 | /** 110 | * Check the string is empty? 111 | * @return if string is null or zero length, return true 112 | */ 113 | static function empty(val: string): boolean; 114 | 115 | /** 116 | * Check one string equals another one? 117 | * @return if equals, return true 118 | */ 119 | static function equalString(val1: string, val2: string): boolean; 120 | 121 | /** 122 | * Check one number equals another one? 123 | * @return if equals, return true 124 | */ 125 | static function equalNumber(val1: number, val2: number): boolean; 126 | 127 | /** 128 | * Check one value is unset 129 | * @return if unset, return true 130 | */ 131 | static function isUnset(value: any): boolean; 132 | 133 | /** 134 | * Stringify the value of map 135 | * @return the new stringified map 136 | */ 137 | static function stringifyMapValue(m: map[string]any): map[string]string; 138 | 139 | /** 140 | * Anyify the value of map 141 | * @return the new anyfied map 142 | */ 143 | static function anyifyMapValue(m: map[string]string): map[string]any; 144 | 145 | /** 146 | * Assert a value, if it is a boolean, return it, otherwise throws 147 | * @return the boolean value 148 | */ 149 | static function assertAsBoolean(value: any)throws : boolean; 150 | 151 | /** 152 | * Assert a value, if it is a string, return it, otherwise throws 153 | * @return the string value 154 | */ 155 | static function assertAsString(value: any)throws : string; 156 | 157 | /** 158 | * Assert a value, if it is a bytes, return it, otherwise throws 159 | * @return the bytes value 160 | */ 161 | static function assertAsBytes(value: any)throws : bytes; 162 | 163 | /** 164 | * Assert a value, if it is a number, return it, otherwise throws 165 | * @return the number value 166 | */ 167 | static function assertAsNumber(value: any)throws : number; 168 | 169 | /** 170 | * Assert a value, if it is a integer, return it, otherwise throws 171 | * @return the integer value 172 | */ 173 | static function assertAsInteger(value: any)throws : integer; 174 | 175 | /** 176 | * Assert a value, if it is a map, return it, otherwise throws 177 | * @return the map value 178 | */ 179 | static function assertAsMap(value: any)throws : map[string]any; 180 | 181 | /** 182 | * Assert a value, if it is a array, return it, otherwise throws 183 | * @return the array value 184 | */ 185 | static function assertAsArray(value: any)throws : [ any ]; 186 | 187 | /** 188 | * Get user agent, if it userAgent is not null, splice it with defaultUserAgent and return, otherwise return defaultUserAgent 189 | * @return the string value 190 | */ 191 | static function getUserAgent(userAgent: string): string; 192 | 193 | /** 194 | * If the code between 200 and 300, return true, or return false 195 | * @return boolean 196 | */ 197 | static function is2xx(code: number): boolean; 198 | 199 | /** 200 | * If the code between 300 and 400, return true, or return false 201 | * @return boolean 202 | */ 203 | static function is3xx(code: number): boolean; 204 | 205 | /** 206 | * If the code between 400 and 500, return true, or return false 207 | * @return boolean 208 | */ 209 | static function is4xx(code: number): boolean; 210 | 211 | /** 212 | * If the code between 500 and 600, return true, or return false 213 | * @return boolean 214 | */ 215 | static function is5xx(code: number): boolean; 216 | 217 | /** 218 | * Validate model 219 | * @return void 220 | */ 221 | static function validateModel(m: $Model) throws: void; 222 | 223 | /** 224 | * Model transforms to map[string]any 225 | * @return map[string]any 226 | */ 227 | static function toMap(in: $Model): map[string]any; 228 | 229 | 230 | /** 231 | * Suspends the current thread for the specified number of milliseconds. 232 | */ 233 | static async function sleep(millisecond: number): void; 234 | 235 | /** 236 | * Transform input as array. 237 | */ 238 | static function toArray(input: any): [ map[string]any ]; 239 | 240 | /** 241 | * Assert a value, if it is a readable, return it, otherwise throws 242 | * @return the readable value 243 | */ 244 | static function assertAsReadable(value: any)throws : readable; -------------------------------------------------------------------------------- /tests/fixtures/multi/libraries/darabonba_Util_0.2.11/util.tea: -------------------------------------------------------------------------------- 1 | @clientName("Utils") 2 | static function test(): void; -------------------------------------------------------------------------------- /tests/fixtures/multi/main.dara: -------------------------------------------------------------------------------- 1 | import "./model/user" User; 2 | import "./lib/util" Util; 3 | import "./api" API; 4 | 5 | type @user = User.Info 6 | 7 | model TestModelDir { 8 | test: number, 9 | m: User.Info 10 | } 11 | 12 | model TestModelDIR { 13 | test: string, 14 | a: any, 15 | } 16 | 17 | exception err { 18 | test: string, 19 | } 20 | 21 | exception ERR { 22 | test: number, 23 | } 24 | 25 | init(){ 26 | @user = new User.Info{ 27 | name = 'test', 28 | age = 124, 29 | maxAttemp = 3, 30 | autoretry = true, 31 | }; 32 | 33 | } 34 | 35 | async function test3(): asyncIterator[string]{ 36 | var it:iterator[string] = Util.test1(); 37 | for(var test : it) { 38 | yield test; 39 | } 40 | } 41 | 42 | 43 | async function test4(): number{ 44 | var api = new API(); 45 | var status = api.test3(); 46 | return status; 47 | } 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /tests/fixtures/multi/model/user.dara: -------------------------------------------------------------------------------- 1 | import DARAUtil; 2 | import DARAUtil.Util as Utils; 3 | import "../lib/util" Util; 4 | 5 | 6 | model BaseInfo extends DARAUtil.RuntimeOptions { 7 | maxAttemp: number, 8 | } 9 | 10 | model Info extends BaseInfo { 11 | name: string, 12 | age: integer, 13 | } 14 | 15 | 16 | static async function test(): asyncIterator[string]{ 17 | Utils.test(); 18 | var it:iterator[string] = Util.test1(); 19 | for(var test : it) { 20 | yield test; 21 | } 22 | 23 | } 24 | 25 | exception Err { 26 | msg: string, 27 | } 28 | 29 | exception Err1 extends BaseInfo { 30 | msg: string, 31 | } 32 | 33 | exception Err2 extends Err { 34 | msg2: string, 35 | } -------------------------------------------------------------------------------- /tests/fixtures/statements/Darafile: -------------------------------------------------------------------------------- 1 | { 2 | "scope": "alibabacloud", 3 | "name": "main", 4 | "version": "0.0.1", 5 | "main": "./main.dara" 6 | } -------------------------------------------------------------------------------- /tests/fixtures/statements/main.dara: -------------------------------------------------------------------------------- 1 | static function helloIf(): void { 2 | if (true) { 3 | } 4 | 5 | if (true) { 6 | 7 | } else if (true) { 8 | 9 | } else { 10 | 11 | } 12 | } 13 | 14 | static function helloThrow() : void { 15 | throw {}; 16 | } 17 | 18 | static function helloForBreak() : void { 19 | for (var item : []) { 20 | break; 21 | } 22 | } 23 | 24 | static function helloWhile() : void { 25 | while (true) { 26 | break; 27 | } 28 | } 29 | 30 | static function helloDeclare() : void { 31 | var hello = "world"; 32 | var helloNull: string = null; 33 | hello = "hehe"; 34 | } 35 | 36 | init(); 37 | 38 | api hello(): void { 39 | __request.method = 'GET'; 40 | __request.pathname = '/'; 41 | __request.headers = { 42 | host = 'www.test.com', 43 | }; 44 | if (true) { 45 | __request.headers.host = 'www.test2.com'; 46 | } 47 | } returns { 48 | if (true) { 49 | retry; 50 | } else { 51 | true; 52 | } 53 | 54 | helloIf(); 55 | !false; 56 | 57 | var a: string = null; 58 | a = 'string'; 59 | 60 | return; 61 | } 62 | -------------------------------------------------------------------------------- /tests/fixtures/super/.libraries.json: -------------------------------------------------------------------------------- 1 | { 2 | "alibabacloud:Import:*": "libraries" 3 | } -------------------------------------------------------------------------------- /tests/fixtures/super/Darafile: -------------------------------------------------------------------------------- 1 | { 2 | "scope": "tests", 3 | "name": "super", 4 | "version": "0.0.1", 5 | "main": "./main.dara", 6 | "libraries": { 7 | "Source": "alibabacloud:Import:*" 8 | } 9 | } -------------------------------------------------------------------------------- /tests/fixtures/super/libraries/Darafile: -------------------------------------------------------------------------------- 1 | { 2 | "scope": "alibabacloud", 3 | "name": "import", 4 | "version": "0.0.1", 5 | "main": "./import.dara", 6 | "php": { 7 | "package": "Source", 8 | "clientName": "SourceClient", 9 | "modelDirName": "Models" 10 | }, 11 | "python": { 12 | "package": "Source", 13 | "clientName": "source_client" 14 | }, 15 | "python2": { 16 | "package": "Source", 17 | "clientName": "source_client" 18 | } 19 | } -------------------------------------------------------------------------------- /tests/fixtures/super/libraries/import.dara: -------------------------------------------------------------------------------- 1 | type @endpointRule = string 2 | type @endpointMap = map[string]string 3 | 4 | init(config: Config); 5 | model Config = {} 6 | -------------------------------------------------------------------------------- /tests/fixtures/super/main.dara: -------------------------------------------------------------------------------- 1 | import Source; 2 | 3 | extends Source; 4 | 5 | init(config: Source.Config){ 6 | super(config); 7 | } -------------------------------------------------------------------------------- /tests/fixtures/typedef/.libraries.json: -------------------------------------------------------------------------------- 1 | { 2 | "alibabacloud:OSS:*": "libraries/alibabacloud-OSS-0.0.1" 3 | } -------------------------------------------------------------------------------- /tests/fixtures/typedef/Darafile: -------------------------------------------------------------------------------- 1 | { 2 | "scope": "darabonba", 3 | "name": "main", 4 | "version": "0.0.1", 5 | "main": "./main.dara", 6 | "libraries": { 7 | "OSS": "alibabacloud:OSS:*" 8 | }, 9 | "python": { 10 | "package": "tea_python_tests", 11 | "clientName": "client", 12 | "typedef": { 13 | "HttpResponse": { 14 | "import": "requests", 15 | "type": "Response", 16 | "package": "requests:2.21.0" 17 | }, 18 | "HttpHeader": { 19 | "import": null, 20 | "type": "Dict[str, Any]", 21 | "package": null 22 | }, 23 | "TeaModel": { 24 | "import": "Tea.model", 25 | "type": "TeaModel", 26 | "package": "alibabacloud-tea:0.2.9" 27 | }, 28 | "TeaException": { 29 | "import": "Tea.exceptions", 30 | "type": "TeaException", 31 | "package": "alibabacloud-tea:0.2.9" 32 | } 33 | } 34 | }, 35 | "python2": { 36 | "package": "tea_python_tests", 37 | "clientName": "client", 38 | "typedef": { 39 | "HttpResponse": { 40 | "import": "requests", 41 | "type": "Response", 42 | "package": "requests:2.21.0" 43 | }, 44 | "HttpHeader": { 45 | "import": null, 46 | "type": "Dict[str, Any]", 47 | "package": null 48 | }, 49 | "TeaModel": { 50 | "import": "Tea.model", 51 | "type": "TeaModel", 52 | "package": "alibabacloud-tea-py2:0.0.4" 53 | }, 54 | "TeaException": { 55 | "import": "Tea.exceptions", 56 | "type": "TeaException", 57 | "package": "alibabacloud-tea-py2:0.0.4" 58 | } 59 | } 60 | } 61 | } -------------------------------------------------------------------------------- /tests/fixtures/typedef/libraries/alibabacloud-OSS-0.0.1/Darafile: -------------------------------------------------------------------------------- 1 | { 2 | "name": "OSS", 3 | "main": "./oss.dara", 4 | "libraries": {}, 5 | "releases": { 6 | "go": "github.com/aliyun/darabonba-go-generator" 7 | }, 8 | "python": { 9 | "package": "Source", 10 | "clientName": "source_client", 11 | "typedef": { 12 | "HttpRequest": { 13 | "import": "requests", 14 | "type": "Request", 15 | "package": "requests:2.21.0" 16 | }, 17 | "HttpHeader": { 18 | "import": null, 19 | "type": "Dict[str, Any]", 20 | "package": null 21 | } 22 | } 23 | }, 24 | "python2": { 25 | "package": "Source", 26 | "clientName": "source_client", 27 | "typedef": { 28 | "HttpRequest": { 29 | "import": "requests", 30 | "type": "Request", 31 | "package": "requests:2.21.0" 32 | }, 33 | "HttpHeader": { 34 | "import": null, 35 | "type": "Dict[str, Any]", 36 | "package": null 37 | } 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /tests/fixtures/typedef/libraries/alibabacloud-OSS-0.0.1/oss.dara: -------------------------------------------------------------------------------- 1 | typedef HttpRequest 2 | type @vid=HttpRequest 3 | 4 | init(test: HttpRequest){ 5 | @vid = test; 6 | } -------------------------------------------------------------------------------- /tests/fixtures/typedef/main.dara: -------------------------------------------------------------------------------- 1 | import OSS 2 | 3 | typedef HttpResponse; 4 | typedef HttpHeader; 5 | typedef TeaModel; 6 | // useless 7 | typedef TeaException; 8 | 9 | type @vid=OSS.HttpRequest; 10 | type @model=TeaModel; 11 | 12 | init(request: OSS.HttpRequest, model: TeaModel){ 13 | @vid = request; 14 | @model = model; 15 | } 16 | 17 | model M { 18 | a?: OSS.HttpRequest, 19 | b?: TeaModel 20 | } 21 | 22 | async function main(test1: OSS.HttpRequest, test2: TeaModel) : void { 23 | var oss = new OSS(test1); 24 | var m = new M { 25 | a = test1, 26 | b = test2 27 | }; 28 | @vid = test1; 29 | @model = test2; 30 | } 31 | 32 | async function testHttpRequest(req: OSS.HttpRequest): HttpResponse { 33 | return testHttpRequestWith("test", req); 34 | } 35 | 36 | static function testHttpRequestWith(method: string, req: OSS.HttpRequest): HttpResponse 37 | 38 | static function testHttpHeader(method: string, headers: HttpHeader): HttpResponse 39 | -------------------------------------------------------------------------------- /tests/main.tests.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const path = require('path'); 4 | const fs = require('fs'); 5 | const assert = require('assert'); 6 | 7 | const DSL = require('@darabonba/parser'); 8 | 9 | let Generator = require('../lib/generator'); 10 | 11 | const lang = 'python'; 12 | 13 | const expectedDir = path.join(__dirname, 'expected/'); 14 | const fixturesDir = path.join(__dirname, 'fixtures/'); 15 | const outputDir = path.join(__dirname, 'output/'); 16 | 17 | function compareDirectories(expectedDir, outputDir) { 18 | const expectedFiles = fs.readdirSync(expectedDir); 19 | const outputFiles = fs.readdirSync(outputDir); 20 | for (let fileName of expectedFiles) { 21 | if (!outputFiles.includes(fileName)) { 22 | assert.ok(false); 23 | } 24 | const expectedPath = path.join(outputDir, fileName); 25 | const actualPath = path.join(expectedDir, fileName); 26 | const expectedStat = fs.statSync(expectedPath); 27 | const actualStat = fs.statSync(actualPath); 28 | 29 | // 如果两个文件都是文件夹,则递归进行比较 30 | if (expectedStat.isDirectory() && actualStat.isDirectory()) { 31 | compareDirectories(expectedPath, actualPath); 32 | } 33 | // 如果是文件,则比较文件内容 34 | else if (expectedStat.isFile() && actualStat.isFile()) { 35 | const expectedContent = fs.readFileSync(expectedPath, 'utf8'); 36 | const acutalContent = fs.readFileSync(actualPath, 'utf8'); 37 | 38 | assert.deepStrictEqual(expectedContent, acutalContent); 39 | } 40 | } 41 | } 42 | 43 | function check(moduleName, expectedDir, option = {}) { 44 | const mainFilePath = path.join(fixturesDir, moduleName, 'main.dara') ? path.join(fixturesDir, moduleName, 'main.dara') : path.join(fixturesDir, moduleName, 'main.tea'); 45 | const moduleOutputDir = path.join(outputDir, moduleName); 46 | const prefixDir = path.join(fixturesDir, moduleName); 47 | const pkgContent = fs.readFileSync( 48 | fs.existsSync(path.join(prefixDir, 'Darafile')) ? path.join(prefixDir, 'Darafile') : path.join(prefixDir, 'Teafile'), 'utf8'); 49 | const pkgInfo = JSON.parse(pkgContent); 50 | const config = { 51 | package: 'tea_python_tests', 52 | outputDir: moduleOutputDir, 53 | pkgDir: path.join(fixturesDir, moduleName), 54 | ...pkgInfo, 55 | ...pkgInfo[lang], 56 | ...option 57 | }; 58 | const generator = new Generator(config, lang); 59 | 60 | const dsl = fs.readFileSync(mainFilePath, 'utf8'); 61 | const ast = DSL.parse(dsl, mainFilePath); 62 | generator.visit(ast); 63 | compareDirectories(path.join(__dirname, 'expected', moduleName, expectedDir), path.join(moduleOutputDir, expectedDir)); 64 | } 65 | 66 | describe('Python Generator', function () { 67 | 68 | it('multi should ok', function () { 69 | check('multi', 'tea_python_tests', 70 | { 71 | python: { 72 | package: 'tea_python_tests', 73 | clientName: 'client' 74 | } 75 | }); 76 | }); 77 | 78 | 79 | it('complex should ok', function () { 80 | check('complex', 'tea_python_tests', 81 | { 82 | python: { 83 | package: 'tea_python_tests', 84 | clientName: 'client' 85 | } 86 | }); 87 | }); 88 | 89 | it('model should ok', function () { 90 | check('model', 'tea_python_tests', 91 | { 92 | python: { 93 | package: 'tea_python_tests', 94 | clientName: 'client', 95 | additionalPackage: [ 96 | { 97 | from: '__future__', 98 | import: 'annotations' 99 | } 100 | ] 101 | } 102 | }); 103 | }); 104 | 105 | it('model config should ok', function () { 106 | check('modelConfig', 'tea_python_tests', 107 | { 108 | python: { 109 | package: 'tea_python_tests', 110 | clientName: 'client', 111 | noneEmpty: true, 112 | strictModel: true, 113 | additionalPackage: [ 114 | { 115 | from: '__future__', 116 | import: 'annotations' 117 | } 118 | ] 119 | } 120 | }); 121 | }); 122 | 123 | it('map should ok', function () { 124 | check('map', 'tea_python_tests', 125 | { 126 | python: { 127 | package: 'tea_python_tests', 128 | clientName: 'client' 129 | } 130 | }); 131 | }); 132 | 133 | it('builtin should ok', function () { 134 | check('builtin', 'tea_python_tests', 135 | { 136 | exec: true, 137 | python: { 138 | package: 'tea_python_tests', 139 | clientName: 'client' 140 | } 141 | }); 142 | }); 143 | 144 | it('exec should ok', function () { 145 | check('exec', 'tea_python_tests', 146 | { 147 | exec: true, 148 | python: { 149 | package: 'tea_python_tests', 150 | clientName: 'exec_client' 151 | } 152 | }); 153 | }); 154 | 155 | it('alias should ok', function () { 156 | check('alias', 'tea_python_tests', 157 | { 158 | python: { 159 | package: 'tea_python_tests', 160 | clientName: 'client', 161 | packageInfo: { 162 | name: 'tea-python-tests', 163 | desc: 'Generate setup.py', 164 | github: 'https://github.com/dara', 165 | author: 'AlibabaCloud SDK Team', 166 | email: 'sdkteam@alibabacloud.com', 167 | require: ['xxx>=0.0.1, <1.0.0', 'xxx>=0.0.1, <1.0.0'] 168 | } 169 | } 170 | }); 171 | const expectedContent = fs.readFileSync(path.join(__dirname, 'expected', 'alias', 'setup.py'), 'utf8'); 172 | const acutalContent = fs.readFileSync(path.join(__dirname, 'output', 'alias', 'setup.py'), 'utf8'); 173 | 174 | assert.deepStrictEqual(expectedContent, acutalContent.replace(new RegExp('\\d{2}\\/\\d{2}\\/\\d{4}'), '*')); 175 | }); 176 | 177 | it('const should ok', function () { 178 | check('const', 'tea_python_tests', 179 | { 180 | python: { 181 | package: 'tea_python_tests', 182 | clientName: 'client' 183 | } 184 | }); 185 | }); 186 | 187 | it('statements should ok', function () { 188 | check('statements', 'tea_python_tests', 189 | { 190 | python: { 191 | package: 'tea_python_tests', 192 | clientName: 'client' 193 | } 194 | }); 195 | }); 196 | 197 | it('function should ok', function () { 198 | check('function', 'tea_python_tests', 199 | { 200 | python: { 201 | package: 'tea_python_tests', 202 | clientName: 'client' 203 | } 204 | }); 205 | }); 206 | 207 | it('api should ok', function () { 208 | check('api', 'tea_python_tests', 209 | { 210 | python: { 211 | package: 'tea_python_tests', 212 | clientName: 'client' 213 | } 214 | }); 215 | }); 216 | 217 | it('import should ok', function () { 218 | check('import', 'tea_python_tests', 219 | { 220 | python: { 221 | package: 'tea_python_tests', 222 | clientName: 'client', 223 | packageInfo: { 224 | name: 'tea_python_tests', 225 | desc: 'Generate setup.py', 226 | github: 'https://github.com/', 227 | author: 'Alibaba', 228 | email: 'sdk-team@alibabacloud.com' 229 | }, 230 | additionalPackage: [ 231 | { 232 | from: '__future__', 233 | import: 'annotations' 234 | } 235 | ] 236 | } 237 | }); 238 | const expected = fs.readFileSync(path.join(expectedDir, 'import', 'setup.py'), 'utf8'); 239 | const output = fs.readFileSync(path.join(outputDir, 'import', 'setup.py'), 'utf8'); 240 | assert.deepStrictEqual(output.replace(new RegExp('\\d{2}\\/\\d{2}\\/\\d{4}'), '*'), expected); 241 | }); 242 | 243 | 244 | 245 | it('add annotation should ok', function () { 246 | check('annotation', 'tea_python_tests', 247 | { 248 | python: { 249 | package: 'tea_python_tests', 250 | clientName: 'client' 251 | } 252 | }); 253 | }); 254 | 255 | it('add comments should ok', function () { 256 | check('comment', 'tea_python_tests', 257 | { 258 | python: { 259 | package: 'tea_python_tests', 260 | clientName: 'client' 261 | } 262 | }); 263 | }); 264 | 265 | 266 | 267 | it('empty should ok', function () { 268 | check('empty', 'tea_python_tests', 269 | { 270 | python: { 271 | package: 'tea_python_tests', 272 | clientName: 'client', 273 | packageInfo: { 274 | name: 'tea_python_tests', 275 | desc: 'Generate setup.py', 276 | github: 'https://github.com/', 277 | author: 'Alibaba', 278 | email: 'sdk-team@alibabacloud.com' 279 | } 280 | } 281 | }); 282 | }); 283 | 284 | it('super should ok', function () { 285 | check('super', 'tea_python_tests', 286 | { 287 | python: { 288 | package: 'tea_python_tests', 289 | clientName: 'client' 290 | } 291 | }); 292 | }); 293 | 294 | 295 | it('typedef should ok', function () { 296 | check('typedef', 'tea_python_tests', 297 | { 298 | python: { 299 | package: 'tea_python_tests', 300 | clientName: 'client', 301 | packageInfo: { 302 | name: 'tea_python_tests', 303 | desc: 'Generate setup.py', 304 | github: 'https://github.com/', 305 | author: 'Alibaba', 306 | email: 'sdk-team@alibabacloud.com' 307 | }, 308 | typedef: { 309 | HttpResponse: { 310 | import: 'requests', 311 | type: 'Response', 312 | package: 'requests:2.21.0' 313 | }, 314 | HttpHeader: { 315 | import: null, 316 | type: 'Dict[str, Any]', 317 | package: null 318 | }, 319 | TeaModel: { 320 | import: 'Tea.model', 321 | type: 'TeaModel', 322 | package: 'alibabacloud-tea:0.2.9' 323 | }, 324 | TeaException: { 325 | import: 'Tea.exceptions', 326 | type: 'TeaException', 327 | package: 'alibabacloud-tea:0.2.9' 328 | } 329 | } 330 | } 331 | }); 332 | }); 333 | }); --------------------------------------------------------------------------------