give a default value if identity type is required (#1330)

* give a default value if identity type is required

* fix rush lint
This commit is contained in:
Beisi Zhou 2024-04-11 13:53:26 +08:00 коммит произвёл GitHub
Родитель d34091366f
Коммит 030855d0a0
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
1 изменённых файлов: 5 добавлений и 2 удалений

Просмотреть файл

@ -1181,10 +1181,13 @@ export class CmdletClass extends Class {
const preProcessManagedIdentityParameters = function* () {
yield $this.ManagedUserAssignedIdentityPreProcess($this);
yield '// calculate IdentityType';
if ($this.operation.details.csharp.virtualParameters?.body?.filter(p => p.name === 'IdentityType')[0]?.required) {
yield If(`null == ${$this.bodyParameter?.value}.IdentityType`, `${$this.bodyParameter?.value}.IdentityType = "None";`);
}
// if UserAssignedIdentity is a string array or string, use Length. Otherwise, use Count
yield If(`this.UserAssignedIdentity?.${!$this.flattenUserAssignedIdentity && $this.GetUserAssignedIdentityParameterTypeDefinition() === 'dictionary' ? 'Count' : 'Length'} > 0`,
function* () {
yield '// calculate IdentityType';
yield If(`"SystemAssigned".Equals(${$this.bodyParameter?.value}.IdentityType, StringComparison.InvariantCultureIgnoreCase)`, `${$this.bodyParameter?.value}.IdentityType = "SystemAssigned,UserAssigned";`);
yield Else(`${$this.bodyParameter?.value}.IdentityType = "UserAssigned";`);
});
@ -1837,7 +1840,7 @@ export class CmdletClass extends Class {
set: operation.details.csharp.verb.toLowerCase() === 'new' ? toExpression(`${expandedBodyParameter.value}.${getVirtualPropertyName((<any>vParam.origin)) || vParam.origin.name} = value.IsPresent ? "SystemAssigned": null `) : undefined
});
enableSystemAssignedIdentity.description = 'Decides if enable a system assigned identity for the resource.';
enableSystemAssignedIdentity.add(new Attribute(ParameterAttribute, { parameters: [new LiteralExpression(`Mandatory = ${vParam.required ? 'true' : 'false'}`), new LiteralExpression(`HelpMessage = "${escapeString(enableSystemAssignedIdentity.description || '.')}"`)] }));
enableSystemAssignedIdentity.add(new Attribute(ParameterAttribute, { parameters: [new LiteralExpression(`Mandatory = ${vParam.required && operation.details.csharp.verb.toLowerCase() !== 'new' ? 'true' : 'false'}`), new LiteralExpression(`HelpMessage = "${escapeString(enableSystemAssignedIdentity.description || '.')}"`)] }));
if (length(vParam.alias) > 0) {
enableSystemAssignedIdentity.add(new Attribute(Alias, { parameters: vParam.alias.map(x => '"' + x + '"') }));
}