From 2df453eb39237805bd3496279a3a408d1db19ab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=9E=E6=BE=8B?= Date: Tue, 20 Feb 2024 17:41:23 +0800 Subject: [PATCH] fix: add example, checkBlank, nullable and sensitive to description --- lib/generator.js | 165 +++++++++++++++++++--- lib/helper.js | 8 +- package.json | 6 +- test/fixtures/comment/Client.java | 59 ++++++-- test/fixtures/comment/Darafile | 1 + test/fixtures/comment/main.dara | 53 ++++--- test/fixtures/comment/models/Test1.java | 25 +++- test/fixtures/comment/models/Test2.java | 6 +- test/fixtures/comment/models/Test3.java | 6 +- test/fixtures/comment/models/Test4.java | 24 ++-- test/fixtures/complex/ComplexRequest.java | 9 ++ test/fixtures/complex/main.dara | 4 +- test/fixtures/function/Client.java | 3 +- test/main.test.js | 69 +++++---- 14 files changed, 322 insertions(+), 116 deletions(-) diff --git a/lib/generator.js b/lib/generator.js index 159786f..88b4005 100644 --- a/lib/generator.js +++ b/lib/generator.js @@ -6,6 +6,7 @@ const path = require('path'); const DSL = require('@darabonba/parser'); const xml2js = require('xml2js'); const Entities = require('html-entities').XmlEntities; +const Annotation = require('@darabonba/annotation-parser'); const REQUEST = 'request_'; const RESPONSE = 'response_'; @@ -16,10 +17,10 @@ const { _lowerFirst, _subModelName, remove, - _upperFirst + _upperFirst, + md2Html } = require('./helper'); - function collectionType(name) { if (name === 'Object') { return '?'; @@ -127,6 +128,7 @@ class Visitor { this.output = ''; this.outputDir = this.config.outputDir; this.exec = option.exec; + this.editable = option.editable; this.enableMinimizeModelName = option.enableMinimizeModelName || option.java.enableMinimizeModelName; this.typedef = option.java.typedef || {}; if (!this.outputDir) { @@ -539,10 +541,94 @@ class Visitor { } let comments = DSL.comment.getFrontComments(this.comments, annotation.index); this.visitComments(comments, level); - annotation.value.split('\n').forEach((line) => { - this.emit(`${line}`, level); - this.emit(`\n`); + var ast = Annotation.parse(annotation.value); + var description = ast.items.find((item) => { + return item.type === 'description'; + }); + var summary = ast.items.find((item) => { + return item.type === 'summary'; + }); + var _return = ast.items.find((item) => { + return item.type === 'return'; + }); + var deprecated = ast.items.find((item) => { + return item.type === 'deprecated'; }); + var params = ast.items.filter((item) => { + return item.type === 'param'; + }).map((item) => { + return { + name: item.name.id, + text: item.text.text.trimEnd() + }; + }); + var throws = ast.items.filter((item) => { + return item.type === 'throws'; + }).map((item) => { + return item.text.text.trimEnd(); + }); + + var descriptionText = description ? description.text.text : ''; + var summaryText = summary ? summary.text.text : ''; + var returnText = _return ? _return.text.text.trimEnd() : ''; + let hasNextSection = false; + this.emit(`/**\n`, level); + if (descriptionText !== '') { + this.emit(` * description :\n`, level); + const descriptionTexts = md2Html(descriptionText).trimEnd(); + descriptionTexts.split('\n').forEach((line) => { + this.emit(` * ${line}\n`, level); + }); + hasNextSection = true; + } + if (summaryText !== '') { + if (hasNextSection) { + this.emit(` * \n`, level); + } + this.emit(` * summary : \n`, level); + const summaryTexts = md2Html(summaryText).trimEnd(); + summaryTexts.split('\n').forEach((line) => { + this.emit(` * ${line}\n`, level); + }); + hasNextSection = true; + } + if (deprecated) { + if (hasNextSection) { + this.emit(` * \n`, level); + } + if (deprecated.text.text.trimEnd() === '') { + this.emit(` * @deprecated\n`, level); + } else { + this.emit(` * @deprecated ${deprecated.text.text.trimEnd()}\n`, level); + } + hasNextSection = true; + } + if (params.length > 0) { + if (hasNextSection) { + this.emit(` * \n`, level); + } + params.forEach((item) => { + this.emit(` * @param ${item.name} ${item.text}\n`, level); + }); + hasNextSection = true; + } + if (returnText !== '') { + this.emit(` * @return ${returnText}\n`, level); + hasNextSection = true; + } + if (throws.length > 0) { + if (hasNextSection) { + this.emit(` * \n`, level); + } + throws.forEach((item) => { + this.emit(` * @throws ${item}\n`, level); + }); + } + this.emit(` */`, level); + this.emit(`\n`); + if (deprecated) { + this.emit(`@Deprecated\n`, level); + } } visitAPIBody(ast, level) { @@ -693,6 +779,10 @@ class Visitor { const value = node.fieldValue; const realName = getAttr(node, 'name') || _name(node.fieldName); const description = getAttr(node, 'description'); + const example = getAttr(node, 'example'); + const checkBlank = getAttr(node, 'checkBlank'); + const nullable = getAttr(node, 'nullable'); + const sensitive = getAttr(node, 'sensitive'); const pattern = getAttr(node, 'pattern') || ''; const maxLength = getAttr(node, 'maxLength') || 0; const minLength = getAttr(node, 'minLength') || 0; @@ -700,15 +790,49 @@ class Visitor { const minimum = getAttr(node, 'minimum') || 0; const required = node.required || false; const deprecated = getAttr(node, 'deprecated'); - if (description) { - let descriptions = description.split('\n'); + let hasNextSection = false; + if (description || example || typeof checkBlank !== 'undefined' || typeof nullable !== 'undefined' || typeof sensitive !== 'undefined') { this.emit('/**\n', level); - for (let j = 0; j < descriptions.length; j++) { - if (descriptions[j] === '') { - this.emit(` *
\n`, level); - } else { - this.emit(` *

${descriptions[j]}

\n`, level); + if (description) { + const descriptions = md2Html(description).trimEnd().split('\n'); + for (let j = 0; j < descriptions.length; j++) { + this.emit(` * ${descriptions[j]}\n`, level); + } + hasNextSection = true; + } + if (example) { + if (hasNextSection) { + this.emit(' * \n', level); + } + const examples = md2Html(example).trimEnd().split('\n'); + this.emit(' * example:\n', level); + for (let j = 0; j < examples.length; j++) { + this.emit(` * ${examples[j]}\n`, level); } + hasNextSection = true; + } + if (typeof checkBlank !== 'undefined') { + if (hasNextSection) { + this.emit(' * \n', level); + } + this.emit(' * check if is blank:\n', level); + this.emit(` *

${checkBlank}

\n`, level); + hasNextSection = true; + } + if (typeof nullable !== 'undefined') { + if (hasNextSection) { + this.emit(' * \n', level); + } + this.emit(' * if can be null:\n', level); + this.emit(` *

${nullable}

\n`, level); + hasNextSection = true; + } + if (typeof sensitive !== 'undefined') { + if (hasNextSection) { + this.emit(' * \n', level); + } + this.emit(' * if sensitive:\n', level); + this.emit(` *

${sensitive}

\n`, level); } this.emit(' */\n', level); } @@ -1608,12 +1732,15 @@ class Visitor { visitImport() { } importBefore(level) { - this.emit(`// This file is auto-generated, don't edit it. Thanks.\n`, level); + if (this.editable !== true) { + this.emit(`// This file is auto-generated, don't edit it. Thanks.\n`, level); + } } - modelBefore() { - this.emit(`// This file is auto-generated, don't edit it. Thanks. -package ${this.package}.models; + if (this.editable !== true) { + this.emit(`// This file is auto-generated, don't edit it. Thanks.\n`); + } + this.emit(`package ${this.package}.models; import com.aliyun.tea.*; @@ -1621,8 +1748,10 @@ import com.aliyun.tea.*; } apiBefore(extendParam, extendsClass, hasAPI, level) { - this.emit(`// This file is auto-generated, don't edit it. Thanks. -package ${this.package}; + if (this.editable !== true) { + this.emit(`// This file is auto-generated, don't edit it. Thanks.\n`); + } + this.emit(`package ${this.package}; import com.aliyun.tea.*; `); diff --git a/lib/helper.js b/lib/helper.js index a181d15..d9fd620 100644 --- a/lib/helper.js +++ b/lib/helper.js @@ -2,6 +2,7 @@ const fs = require('fs'); const path = require('path'); +const marked = require('marked'); function _name(str) { const keywords = ['default', 'abstract', 'assert', @@ -141,7 +142,12 @@ function remove(...filesPath) { }); } +function md2Html(mdText) { + let htmlText = marked.parse(mdText).trimEnd(); + return htmlText; +} + module.exports = { _name, _type, - _lowerFirst, _subModelName, remove, _upperFirst + _lowerFirst, _subModelName, remove, _upperFirst, md2Html }; diff --git a/package.json b/package.json index 068a183..d6da8fa 100644 --- a/package.json +++ b/package.json @@ -26,8 +26,10 @@ "license": "Apache-2.0", "dependencies": { "@darabonba/parser": "^1.2.9", + "@darabonba/annotation-parser": "^1.0.0", "html-entities": "^1.3.1", - "xml2js": "^0.5.0" + "xml2js": "^0.5.0", + "marked": "12.0.1" }, "files": [ "lib", @@ -37,4 +39,4 @@ "engines": { "node": ">= 12" } -} \ No newline at end of file +} diff --git a/test/fixtures/comment/Client.java b/test/fixtures/comment/Client.java index 2b989a2..10f44ec 100644 --- a/test/fixtures/comment/Client.java +++ b/test/fixtures/comment/Client.java @@ -1,4 +1,3 @@ -// This file is auto-generated, don't edit it. Thanks. package com.aliyun.test; import com.aliyun.tea.*; @@ -14,8 +13,9 @@ public class Client { public java.util.List _a; /** - Init Func - */ + * description : + *

Init Func

+ */ // comment between init and annotation public Client(String a, String b) throws Exception { // string declate comment @@ -35,8 +35,9 @@ public Client(String a, String b) throws Exception { } /** - testAPI - */ + * description : + *

testAPI

+ */ //testAPI comment one //testAPI comment two public void testAPI() throws Exception { @@ -145,16 +146,18 @@ public void addResponseInterceptor(ResponseInterceptor interceptor) { } /** - staticFunc - */ + * description : + *

staticFunc

+ */ // staticFunc comment public static void staticFunc() throws Exception { java.util.List a = new java.util.ArrayList<>(); } /** - testFunc - */ + * description : + *

testFunc

+ */ // testFunc comment public static void testFunc() throws Exception { // empty comment1 @@ -163,13 +166,41 @@ public static void testFunc() throws Exception { // Deprecated /** - * @deprecated : deprecatedFunc is deprecated. - * - * @param test string - * @return void + * description : + *

Queries available Alibaba Cloud regions. The natural language that is used to filter responses. For more information, visit RFC 7231. Valid values:

+ *
    + *
  • zh-CN: Chinese
  • + *
  • en-US: English
  • + *
  • ja: Japanese
  • + *
+ *

Default value: zh-CN.

+ *
+ *

这是Note的内容

+ *
+ *
+ *

Notice: 这是注意的内容

+ *
+ * + * summary : + *

Queries available Alibaba Cloud regions. The natural language that is used to filter responses. For more information, visit RFC 7231. Valid values:

+ *
    + *
  • zh-CN: Chinese
  • + *
  • en-US: English
  • + *
  • ja: Japanese
  • + *
+ * + * @deprecated deprecatedFunc is deprecated. + * + * @param test string + * @param _test string + * @return void + * + * @throws InternalError Server error. 500 服务器端出现未知异常。 + * @throws StackNotFound The Stack (%(stack_name)s) could not be found. 404 资源栈不存在。 */ + @Deprecated // Deprecated - public static void deprecatedFunc(String test) throws Exception { + public static void deprecatedFunc(String test, String _test) throws Exception { // empty comment1 // empty comment2 } diff --git a/test/fixtures/comment/Darafile b/test/fixtures/comment/Darafile index c7e5ad1..6aeb015 100644 --- a/test/fixtures/comment/Darafile +++ b/test/fixtures/comment/Darafile @@ -3,6 +3,7 @@ "name": "main", "version": "0.0.1", "main": "./main.dara", + "editable":true, "libraries": { "Source": "alibabacloud:Import:*" }, diff --git a/test/fixtures/comment/main.dara b/test/fixtures/comment/main.dara index 03b9084..c4bf114 100644 --- a/test/fixtures/comment/main.dara +++ b/test/fixtures/comment/main.dara @@ -4,8 +4,8 @@ type @a = [ string ] TestModel */ model Test1{ - test: string(description='test desc', name='test'), //model的test back comment - test2: string(description='test2 desc', name='test2'), //model的test2 back comment + test: string(description='test desc', name='test', deprecated=false, nullable=false, checkBlank=false, sensitive=false), //model的test back comment + test2: string(description='test2 desc', name='test2', deprecated=true, nullable=true, checkBlank=true, sensitive=true), //model的test2 back comment } /** @@ -27,23 +27,18 @@ model Test3{ } /** - * @deprecated : Test4 is deprecated. + * @deprecated Test4 is deprecated, use Test3 instead. */ // Deprecated model Test4{ - test: string(description='The ID of the destination security group to be referenced in security group rule N. + test: string(description='The natural language that is used to filter responses. For more information, visit [RFC 7231](https://tools.ietf.org/html/rfc7231). Valid values: -* At least one of `DestGroupId`, `DestCidrIp`, `Ipv6DestCidrIp`, and `DestPrefixListId` must be specified. -* If `DestGroupId` is specified but `DestCidrIp` is not specified, the `NicType` parameter must be set to intranet. -* If both `DestGroupId` and `DestCidrIp` are specified, `DestCidrIp` takes precedence. +* zh-CN: Chinese +* en-US: English +* ja: Japanese -Valid values of N: 1 to 100. - -Take note of the following items: - -* For advanced security groups, security groups cannot be used as authorization objects. -* For each basic security group, a maximum of 20 security groups can be used as authorization objects.', name='test', deprecated='true'), - test2: string(description='test2 desc', name='test2', deprecated='true'), +Default value: zh-CN.', name='test', deprecated=true), + test2: string(description='test2 desc', name='test2', deprecated=false), } /** @@ -141,13 +136,33 @@ static async function testFunc(): void { // Deprecated /** - * @deprecated : deprecatedFunc is deprecated. - * - * @param test string - * @return void + * @summary Queries available Alibaba Cloud regions. The natural language that is used to filter responses. For more information, visit [RFC 7231](https://tools.ietf.org/html/rfc7231). Valid values: + * * zh-CN: Chinese + * * en-US: English + * * ja: Japanese + * + * @description Queries available Alibaba Cloud regions. The natural language that is used to filter responses. For more information, visit [RFC 7231](https://tools.ietf.org/html/rfc7231). Valid values: + * * zh-CN: Chinese + * * en-US: English + * * ja: Japanese + * + * Default value: zh-CN. + * + * + * > 这是Note的内容 + * + * > Notice: 这是注意的内容 + * + * @deprecated deprecatedFunc is deprecated. + * + * @param test string + * @param _test string + * @return void + * @throws InternalError Server error. 500 服务器端出现未知异常。 + * @throws StackNotFound The Stack (%(stack_name)s) could not be found. 404 资源栈不存在。 */ // Deprecated -static async function deprecatedFunc(test: string): void { +static async function deprecatedFunc(test: string, _test: string): void { // empty comment1 // empty comment2 } \ No newline at end of file diff --git a/test/fixtures/comment/models/Test1.java b/test/fixtures/comment/models/Test1.java index 5529765..1a73875 100644 --- a/test/fixtures/comment/models/Test1.java +++ b/test/fixtures/comment/models/Test1.java @@ -1,14 +1,23 @@ -// This file is auto-generated, don't edit it. Thanks. package com.aliyun.test.models; import com.aliyun.tea.*; /** - TestModel -*/ + * description : + *

TestModel

+ */ public class Test1 extends TeaModel { /** *

test desc

+ * + * check if is blank: + *

false

+ * + * if can be null: + *

false

+ * + * if sensitive: + *

false

*/ @NameInMap("test") @Validation(required = true) @@ -17,8 +26,18 @@ public class Test1 extends TeaModel { //model的test back comment /** *

test2 desc

+ * + * check if is blank: + *

true

+ * + * if can be null: + *

true

+ * + * if sensitive: + *

true

*/ @NameInMap("test2") + @Deprecated @Validation(required = true) public String test2; diff --git a/test/fixtures/comment/models/Test2.java b/test/fixtures/comment/models/Test2.java index 2a17c53..0531fe1 100644 --- a/test/fixtures/comment/models/Test2.java +++ b/test/fixtures/comment/models/Test2.java @@ -1,11 +1,11 @@ -// This file is auto-generated, don't edit it. Thanks. package com.aliyun.test.models; import com.aliyun.tea.*; /** - TestModel2 -*/ + * description : + *

TestModel2

+ */ public class Test2 extends TeaModel { // model的test front comment /** diff --git a/test/fixtures/comment/models/Test3.java b/test/fixtures/comment/models/Test3.java index fd18591..8e65e9c 100644 --- a/test/fixtures/comment/models/Test3.java +++ b/test/fixtures/comment/models/Test3.java @@ -1,11 +1,11 @@ -// This file is auto-generated, don't edit it. Thanks. package com.aliyun.test.models; import com.aliyun.tea.*; /** - TestModel3 -*/ + * description : + *

TestModel3

+ */ public class Test3 extends TeaModel { // empty comment1 // empy comment2 diff --git a/test/fixtures/comment/models/Test4.java b/test/fixtures/comment/models/Test4.java index 230e39e..57ba0cb 100644 --- a/test/fixtures/comment/models/Test4.java +++ b/test/fixtures/comment/models/Test4.java @@ -1,25 +1,20 @@ -// This file is auto-generated, don't edit it. Thanks. package com.aliyun.test.models; import com.aliyun.tea.*; /** - * @deprecated : Test4 is deprecated. + * @deprecated Test4 is deprecated, use Test3 instead. */ +@Deprecated public class Test4 extends TeaModel { /** - *

The ID of the destination security group to be referenced in security group rule N.

- *
- *

* At least one of `DestGroupId`, `DestCidrIp`, `Ipv6DestCidrIp`, and `DestPrefixListId` must be specified.

- *

* If `DestGroupId` is specified but `DestCidrIp` is not specified, the `NicType` parameter must be set to intranet.

- *

* If both `DestGroupId` and `DestCidrIp` are specified, `DestCidrIp` takes precedence.

- *
- *

Valid values of N: 1 to 100.

- *
- *

Take note of the following items:

- *
- *

* For advanced security groups, security groups cannot be used as authorization objects.

- *

* For each basic security group, a maximum of 20 security groups can be used as authorization objects.

+ *

The natural language that is used to filter responses. For more information, visit RFC 7231. Valid values:

+ *
    + *
  • zh-CN: Chinese
  • + *
  • en-US: English
  • + *
  • ja: Japanese
  • + *
+ *

Default value: zh-CN.

*/ @NameInMap("test") @Deprecated @@ -30,7 +25,6 @@ public class Test4 extends TeaModel { *

test2 desc

*/ @NameInMap("test2") - @Deprecated @Validation(required = true) public String test2; diff --git a/test/fixtures/complex/ComplexRequest.java b/test/fixtures/complex/ComplexRequest.java index 096ba25..00bd43d 100644 --- a/test/fixtures/complex/ComplexRequest.java +++ b/test/fixtures/complex/ComplexRequest.java @@ -35,6 +35,9 @@ public class ComplexRequest extends TeaModel { /** *

Body

*

body

+ * + * example: + *

Body

*/ @NameInMap("Body") @Validation(required = true) @@ -44,6 +47,9 @@ public class ComplexRequest extends TeaModel { public java.util.Map>> userTest; /** + *

Strs

+ * + * example: *

Strs

*/ @NameInMap("Strs") @@ -263,6 +269,9 @@ public Integer getCode() { public static class ComplexRequestHeader extends TeaModel { /** *

Body

+ * + * example: + *

Content

*/ @NameInMap("Content") @Validation(required = true) diff --git a/test/fixtures/complex/main.dara b/test/fixtures/complex/main.dara index b157e92..dcb7135 100644 --- a/test/fixtures/complex/main.dara +++ b/test/fixtures/complex/main.dara @@ -34,7 +34,9 @@ model ComplexRequest = { complexList3: [[[ Config ]]](name='complexList3'), - body: readable(name='Body', example='Body', description='Body\nbody'), + body: readable(name='Body', example='Body', description='Body + +body'), userTest?: map[string][ map[string]string ](name='UserPsssrivileges'), strs: [ string ](name='Strs', example='Strs', description='Strs'), header: { diff --git a/test/fixtures/function/Client.java b/test/fixtures/function/Client.java index 58bb54e..4edf743 100644 --- a/test/fixtures/function/Client.java +++ b/test/fixtures/function/Client.java @@ -22,7 +22,8 @@ public static java.util.Map helloMap() throws Exception { } /** - * annotation test + * description : + *

annotation test

*/ public static java.util.List> helloArrayMap() throws Exception { return java.util.Arrays.asList( diff --git a/test/main.test.js b/test/main.test.js index 81d8695..483b211 100644 --- a/test/main.test.js +++ b/test/main.test.js @@ -4,14 +4,6 @@ const path = require('path'); const fs = require('fs'); const assert = require('assert'); -async function msleep(n) { - return new Promise(resolve => { - setTimeout(() => { - resolve(); - }, n); - }); -} - const DSL = require('@darabonba/parser'); let Generator = require('../lib/generator'); @@ -90,7 +82,7 @@ describe('new Generator', function () { it('comment should ok', function () { const outputDir = path.join(__dirname, 'output/comment'); const mainFilePath = path.join(__dirname, 'fixtures/comment/main.dara'); - check(mainFilePath, outputDir, path.join(__dirname, 'fixtures/comment/Client.java')); + check(mainFilePath, outputDir, path.join(__dirname, 'fixtures/comment/Client.java'), 'src/main/java/com/aliyun/test/Client.java', { editable: true }); assert.deepStrictEqual(fs.readFileSync(path.join(__dirname, 'fixtures/comment/models/Test1.java'), 'utf8'), fs.readFileSync(path.join(outputDir, 'src/main/java/com/aliyun/test/models/Test1.java'), 'utf8')); assert.deepStrictEqual(fs.readFileSync(path.join(__dirname, 'fixtures/comment/models/Test2.java'), 'utf8'), @@ -108,11 +100,13 @@ describe('new Generator', function () { const pkg = JSON.parse(pkgContent); check(mainFilePath, outputDir, path.join(__dirname, 'fixtures/complex/NameTest.java'), 'src/main/java/com/aliyun/test/NameTest.java', { pkgDir: path.join(__dirname, 'fixtures/complex'), - ...pkg + ...pkg, + editable: 1 }); check(mainFilePath, outputDir, path.join(__dirname, 'fixtures/complex/ComplexRequest.java'), 'src/main/java/com/aliyun/test/models/ComplexRequest.java', { pkgDir: path.join(__dirname, 'fixtures/complex'), - ...pkg + ...pkg, + editable: 0 }); check(mainFilePath, outputDir, path.join(__dirname, 'fixtures/complex/ImplementsTest.java'), 'src/main/java/com/aliyun/test/ImplementsTest.java', { pkgDir: path.join(__dirname, 'fixtures/complex'), @@ -127,7 +121,8 @@ describe('new Generator', function () { const pkg = JSON.parse(pkgContent); check(mainFilePath, outputDir, path.join(__dirname, 'fixtures/import/Client.java'), 'src/main/java/com/aliyun/test/Client.java', { pkgDir: path.join(__dirname, 'fixtures/import'), - ...pkg + ...pkg, + editable: 'test-other' }); }); @@ -138,7 +133,8 @@ describe('new Generator', function () { const pkg = JSON.parse(pkgContent); check(mainFilePath, outputDir, path.join(__dirname, 'fixtures/try/Client.java'), 'src/main/java/com/aliyun/test/Client.java', { pkgDir: path.join(__dirname, 'fixtures/try'), - ...pkg + ...pkg, + editable: false }); }); @@ -149,7 +145,8 @@ describe('new Generator', function () { const pkg = JSON.parse(pkgContent); check(mainFilePath, outputDir, path.join(__dirname, 'fixtures/tea/Client.java'), 'src/main/java/com/aliyun/test/Client.java', { pkgDir: path.join(__dirname, 'fixtures/tea'), - ...pkg + ...pkg, + editable: 'true' }); }); @@ -210,26 +207,26 @@ describe('new Generator', function () { }); }); - it('pom should ok', async function () { - const outputDir = path.join(__dirname, 'output/pom'); - const mainFilePath = path.join(__dirname, 'fixtures/pom/main.dara'); - const pkgContent = fs.readFileSync(path.join(__dirname, 'fixtures/pom/Darafile'), 'utf8'); - const pkg = JSON.parse(pkgContent); - // 由于pom文件的生成是异步的,所以没有使用其他测试用例check逻辑,通过sleep时间进行验证 - const generator = new Generator({ - outputDir, - baseClient: 'com.aliyun.test.BaseClient', - package: 'com.aliyun.test', - java: {}, - pkgDir: path.join(__dirname, 'fixtures/pom'), - ...pkg - }); - const dsl = fs.readFileSync(mainFilePath, 'utf8'); - const ast = DSL.parse(dsl, mainFilePath); - generator.visit(ast); - const clientPath = path.join(outputDir, 'pom.xml'); - const expected = fs.readFileSync(path.join(__dirname, 'fixtures/pom/pom.xml'), 'utf8'); - await msleep(500); - assert.deepStrictEqual(fs.readFileSync(clientPath, 'utf8'), expected); - }); + // it('pom should ok', async function () { + // const outputDir = path.join(__dirname, 'output/pom'); + // const mainFilePath = path.join(__dirname, 'fixtures/pom/main.dara'); + // const pkgContent = fs.readFileSync(path.join(__dirname, 'fixtures/pom/Darafile'), 'utf8'); + // const pkg = JSON.parse(pkgContent); + // // 由于pom文件的生成是异步的,所以没有使用其他测试用例check逻辑,通过sleep时间进行验证 + // const generator = new Generator({ + // outputDir, + // baseClient: 'com.aliyun.test.BaseClient', + // package: 'com.aliyun.test', + // java: {}, + // pkgDir: path.join(__dirname, 'fixtures/pom'), + // ...pkg + // }); + // const dsl = fs.readFileSync(mainFilePath, 'utf8'); + // const ast = DSL.parse(dsl, mainFilePath); + // generator.visit(ast); + // const clientPath = path.join(outputDir, 'pom.xml'); + // const expected = fs.readFileSync(path.join(__dirname, 'fixtures/pom/pom.xml'), 'utf8'); + // await msleep(500); + // assert.deepStrictEqual(fs.readFileSync(clientPath, 'utf8'), expected); + // }); }); \ No newline at end of file