@cnbcool/cnb-api-generate 2.8.1 → 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { removeSlashes } from 'slashes';
|
|
1
2
|
import { helpData } from './help-data';
|
|
2
3
|
import { tryParseJSON, readFileContent } from './parsers';
|
|
3
4
|
import { buildNestedFieldMap } from '../utils/build-nested-field-map';
|
|
@@ -17,8 +18,13 @@ export function getToolParamDefs(moduleName: string, toolName: string) {
|
|
|
17
18
|
/**
|
|
18
19
|
* 将 body 字段值按 schema 类型写入 target。
|
|
19
20
|
* - array 值:原样保留
|
|
20
|
-
* - string
|
|
21
|
+
* - string 字段:还原 shell 字面转义(如 --body "a\n b" 中的 \n → 真换行),
|
|
22
|
+
* 并保留原始字符串(避免纯数字字符串被转 number)
|
|
21
23
|
* - 其他字段:走 tryParseJSON 以兼容嵌套 JSON
|
|
24
|
+
*
|
|
25
|
+
* 说明:shell 在单/双引号下不解释 `\n`,外部程序(包括本 CLI 经 commander)
|
|
26
|
+
* 收到的是字面的反斜杠 + n。这里用 slashes.removeSlashes 做一次反解析,
|
|
27
|
+
* 让 `--body "a\n b"` 与 `echo -e` 体验一致,正确还原为真实换行/制表符等。
|
|
22
28
|
*/
|
|
23
29
|
function assignBodyValue(
|
|
24
30
|
target: Record<string, any>,
|
|
@@ -29,7 +35,7 @@ function assignBodyValue(
|
|
|
29
35
|
if (Array.isArray(value)) {
|
|
30
36
|
target[key] = value;
|
|
31
37
|
} else if (propType === 'string') {
|
|
32
|
-
target[key] = value;
|
|
38
|
+
target[key] = typeof value === 'string' ? removeSlashes(value) : value;
|
|
33
39
|
} else {
|
|
34
40
|
target[key] = tryParseJSON(value as string);
|
|
35
41
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cnbcool/cnb-api-generate",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.0",
|
|
4
4
|
"main": "./built/index.js",
|
|
5
5
|
"module": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"ora": "5.4.1",
|
|
46
46
|
"prettier": "3.4.2",
|
|
47
47
|
"rimraf": "6.0.1",
|
|
48
|
+
"slashes": "^3.0.12",
|
|
48
49
|
"typescript": "5.9.3"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|