mushroom-cli 1.2.0-alpha.17 → 1.2.0-alpha.18
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.
|
@@ -59,26 +59,25 @@ function generateTypescriptClass(objectDefination, className, options) {
|
|
|
59
59
|
let childrenCode = '';
|
|
60
60
|
let code = `export interface ${className} {\n`;
|
|
61
61
|
for (const fieldName in objectDefination) {
|
|
62
|
-
const optionalMark = options?.checkRequired && objectDefination[fieldName].required
|
|
63
|
-
|
|
64
|
-
: ' | null | undefined';
|
|
62
|
+
const optionalMark = options?.checkRequired && objectDefination[fieldName].required ? '' : '?';
|
|
63
|
+
const nullType = optionalMark ? ' | null' : '';
|
|
65
64
|
if (objectDefination[fieldName].type == 'object') {
|
|
66
65
|
const fieldClassName = className + '_' + toTypeScriptClassName(fieldName);
|
|
67
|
-
code += ` ${fieldName}: ${fieldClassName}${
|
|
66
|
+
code += ` ${fieldName}${optionalMark}: ${fieldClassName}${nullType};\n`;
|
|
68
67
|
childrenCode += generateTypescriptClass(objectDefination[fieldName].fields ?? {}, fieldClassName);
|
|
69
68
|
}
|
|
70
69
|
else if (objectDefination[fieldName].type == 'array') {
|
|
71
70
|
if (objectDefination[fieldName].items?.type == 'object') {
|
|
72
71
|
const fieldClassName = className + '_' + toTypeScriptClassName(fieldName);
|
|
73
|
-
code += ` ${fieldName}: ${fieldClassName}[]${
|
|
72
|
+
code += ` ${fieldName}${optionalMark}: ${fieldClassName}[]${nullType};\n`;
|
|
74
73
|
childrenCode += generateTypescriptClass(objectDefination[fieldName].items?.fields ?? {}, fieldClassName);
|
|
75
74
|
}
|
|
76
75
|
else {
|
|
77
|
-
code += ` ${fieldName}: ${getCSharpTypeFromMushroomType(objectDefination[fieldName].items?.type ?? '')}[]${
|
|
76
|
+
code += ` ${fieldName}${optionalMark}: ${getCSharpTypeFromMushroomType(objectDefination[fieldName].items?.type ?? '')}[]${nullType};\n`;
|
|
78
77
|
}
|
|
79
78
|
}
|
|
80
79
|
else {
|
|
81
|
-
code += ` ${fieldName}: ${getCSharpTypeFromMushroomType(objectDefination[fieldName].type)}${
|
|
80
|
+
code += ` ${fieldName}${optionalMark}: ${getCSharpTypeFromMushroomType(objectDefination[fieldName].type)}${nullType};\n`;
|
|
82
81
|
}
|
|
83
82
|
}
|
|
84
83
|
code += '}\n\n';
|
|
@@ -88,7 +87,7 @@ function generateTypescriptClassFromViewParameters(parameters) {
|
|
|
88
87
|
if (Array.isArray(parameters)) {
|
|
89
88
|
return ('{\n' +
|
|
90
89
|
parameters
|
|
91
|
-
.map((p) => ` ${p.field}: ${getCSharpTypeFromMushroomType(p.type || 'string')}${p.isArray ? '[]' : ''}${p.validation?.required && p.defaultValue === undefined ? '' : ' | null
|
|
90
|
+
.map((p) => ` ${p.field}${p.validation?.required && p.defaultValue === undefined ? '' : '?'}: ${getCSharpTypeFromMushroomType(p.type || 'string')}${p.isArray ? '[]' : ''}${p.validation?.required && p.defaultValue === undefined ? '' : ' | null'};`)
|
|
92
91
|
.join('\n') +
|
|
93
92
|
'\n}');
|
|
94
93
|
}
|