in powershell/sdk/utility.ts [217:264]
public ValidateType(schema: Schema, scope: any, valueReference: string, isNullable: boolean, indentation = 3): string {
const indentationSpaces = ' '.repeat(indentation);
const sb = new Array<string>();
if (!scope) {
throw new Error('scope is null');
}
if (!!schema && isObjectSchema(schema) && this.ShouldValidateChain(schema)) {
sb.push(`${valueReference}.Validate();`);
}
if (this.HasConstrains(schema)) {
this.appendConstraintValidations(valueReference, sb, schema);
}
if (schema && this.isArraySchema(schema) && this.ShouldValidateChain(schema)) {
// ToDo: Should try to get a unique name instead of element
let elementVar = 'element';
if (valueReference.startsWith(elementVar)) {
elementVar = valueReference + '1';
}
const innerValidation = this.ValidateType((<ArraySchema>schema).elementType, scope, elementVar, true, 1);
if (innerValidation) {
sb.push(`foreach (var ${elementVar} in ${valueReference})`);
sb.push('{');
innerValidation.split('\r\n').map(str => sb.push(str));
sb.push('}');
}
} else if (schema && this.isDictionarySchema(schema) && this.ShouldValidateChain(schema)) {
// ToDo: Should try to get a unique name instead of valueElement
let valueVar = 'valueElement';
if (valueReference.startsWith(valueVar)) {
valueVar = valueReference + '1';
}
const innerValidation = this.ValidateType((<DictionarySchema>schema).elementType, scope, valueVar, true, 1);
if (innerValidation) {
sb.push(`foreach (var ${valueVar} in ${valueReference}.Values)`);
sb.push('{');
innerValidation.split('\r\n').map(str => sb.push(str));
sb.push('}');
}
}
if (sb.length > 0) {
if (this.IsValueType(schema.type) && !isNullable) {
return sb.map(str => indentationSpaces + str).join('\r\n');
} else {
return `${indentationSpaces}if (${valueReference} != null)\r\n${indentationSpaces}{\r\n${sb.map(str => indentationSpaces + ' ' + str).join('\r\n')}\r\n${indentationSpaces}}`;
}
}
return '';
}