Skip to content

Commit

Permalink
Add support for secret and double, fixed related test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
dolauli committed Dec 13, 2024
1 parent 74242d7 commit a938906
Show file tree
Hide file tree
Showing 48 changed files with 234 additions and 233 deletions.
29 changes: 15 additions & 14 deletions packages/typespec-powershell/src/utils/modelUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ export function getSchemaForType(
if (type.kind === "ModelProperty") {
const typeSchema: Schema = getSchemaForType(dpgContext, type.type, options);
if (isStringType(program, type.type) || isNumericType(program, type.type)) {
// add in validation elements for string and numeric types
// unlike m4, min/max length and pattern are not part of the schema
const propertySchema = { ...typeSchema };
addValidation(<Schema>propertySchema, type);
// applyIntrinsicDecorators for string and numeric types
// unlike m4, min/max length and pattern, secrets, etc. are not part of the schema
let propertySchema = { ...typeSchema };
propertySchema = applyIntrinsicDecorators(program, type, propertySchema);
propertySchema.language.default.name = type.name;
propertySchema.language.default.description = getDoc(program, type) || "";
schemaCache.set(type, <Schema>propertySchema);
Expand Down Expand Up @@ -928,12 +928,12 @@ function getSchemaForModel(
// }

// Apply decorators on the property to the type's schema
const newPropSchema = applyIntrinsicDecorators(program, prop, propSchema);
if (newPropSchema === undefined) {
continue;
}
// const newPropSchema = applyIntrinsicDecorators(program, prop, propSchema);
// if (newPropSchema === undefined) {
// continue;
// }
// Use the description from ModelProperty not devired from Model Type
newPropSchema.description = propertyDescription;
// newPropSchema.description = propertyDescription;

// Should the property be marked as readOnly?
// const vis = getVisibility(program, prop);
Expand Down Expand Up @@ -1048,8 +1048,9 @@ function applyIntrinsicDecorators(
}

if (isSecret(program, type)) {
newTarget.format = "password";
newTarget["x-ms-secret"] = true;
newTarget.type = "credential";
newTarget["extensions"] = newTarget["extensions"] || {};
newTarget["extensions"]["x-ms-secret"] = true;
}

return newTarget;
Expand Down Expand Up @@ -1360,17 +1361,17 @@ function getSchemaForStdScalar(
case "float64":
return applyIntrinsicDecorators(program, type, {
type: "number",
format: "float64"
precision: 64
});
case "float32":
return applyIntrinsicDecorators(program, type, {
type: "number",
format: "float32"
precision: 32
});
case "float":
return applyIntrinsicDecorators(program, type, {
type: "number",
format: "float"
precision: 32
});
case "decimal":
reportDiagnostic(program, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ internal AdditionalUnattendContent(global::System.Collections.IDictionary conten
}
if (content.Contains("Content"))
{
((Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Models.IAdditionalUnattendContentInternal)this).Content = (string) content.GetValueForProperty("Content",((Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Models.IAdditionalUnattendContentInternal)this).Content, global::System.Convert.ToString);
((Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Models.IAdditionalUnattendContentInternal)this).Content = (System.Security.SecureString) content.GetValueForProperty("Content",((Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Models.IAdditionalUnattendContentInternal)this).Content, (object ss) => (System.Security.SecureString)ss);
}
AfterDeserializeDictionary(content);
}
Expand Down Expand Up @@ -125,7 +125,7 @@ internal AdditionalUnattendContent(global::System.Management.Automation.PSObject
}
if (content.Contains("Content"))
{
((Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Models.IAdditionalUnattendContentInternal)this).Content = (string) content.GetValueForProperty("Content",((Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Models.IAdditionalUnattendContentInternal)this).Content, global::System.Convert.ToString);
((Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Models.IAdditionalUnattendContentInternal)this).Content = (System.Security.SecureString) content.GetValueForProperty("Content",((Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Models.IAdditionalUnattendContentInternal)this).Content, (object ss) => (System.Security.SecureString)ss);
}
AfterDeserializePSObject(content);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ public partial class AdditionalUnattendContent :
public string ComponentName { get => this._componentName; set => this._componentName = value; }

/// <summary>Backing field for <see cref="Content" /> property.</summary>
private string _content;
private System.Security.SecureString _content;

/// <summary>
/// Specifies the XML formatted content that is added to the unattend.xml file for
/// the specified path and component. The XML must be less than 4KB and must
/// include the root element for the setting or feature that is being inserted.
/// </summary>
[Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Origin(Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.PropertyOrigin.Owned)]
public string Content { get => this._content; set => this._content = value; }
public System.Security.SecureString Content { get => this._content; set => this._content = value; }

/// <summary>Backing field for <see cref="PassName" /> property.</summary>
private string _passName;
Expand Down Expand Up @@ -95,8 +95,8 @@ public partial interface IAdditionalUnattendContent :
the specified path and component. The XML must be less than 4KB and must
include the root element for the setting or feature that is being inserted.",
SerializedName = @"content",
PossibleTypes = new [] { typeof(string) })]
string Content { get; set; }
PossibleTypes = new [] { typeof(System.Security.SecureString) })]
System.Security.SecureString Content { get; set; }
/// <summary>The pass name. Currently, the only allowable value is OobeSystem.</summary>
[Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Runtime.Info(
Required = false,
Expand Down Expand Up @@ -142,7 +142,7 @@ internal partial interface IAdditionalUnattendContentInternal
/// the specified path and component. The XML must be less than 4KB and must
/// include the root element for the setting or feature that is being inserted.
/// </summary>
string Content { get; set; }
System.Security.SecureString Content { get; set; }
/// <summary>The pass name. Currently, the only allowable value is OobeSystem.</summary>
string PassName { get; set; }
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ internal AdditionalUnattendContent(Microsoft.Azure.PowerShell.Cmdlets.ComputeFle
{_passName = If( json?.PropertyT<Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Runtime.Json.JsonString>("passName"), out var __jsonPassName) ? (string)__jsonPassName : (string)_passName;}
{_componentName = If( json?.PropertyT<Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Runtime.Json.JsonString>("componentName"), out var __jsonComponentName) ? (string)__jsonComponentName : (string)_componentName;}
{_settingName = If( json?.PropertyT<Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Runtime.Json.JsonString>("settingName"), out var __jsonSettingName) ? (string)__jsonSettingName : (string)_settingName;}
{_content = If( json?.PropertyT<Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Runtime.Json.JsonString>("content"), out var __jsonContent) ? (string)__jsonContent : (string)_content;}
{_content = If( json?.PropertyT<Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Runtime.Json.JsonString>("content"), out var __jsonContent) ? new System.Net.NetworkCredential("",(string)__jsonContent).SecurePassword : _content;}
AfterFromJson(json);
}

Expand Down Expand Up @@ -108,7 +108,7 @@ public Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Runtime.Json.JsonNode ToJ
AddIf( null != (((object)this._passName)?.ToString()) ? (Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Runtime.Json.JsonNode) new Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Runtime.Json.JsonString(this._passName.ToString()) : null, "passName" ,container.Add );
AddIf( null != (((object)this._componentName)?.ToString()) ? (Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Runtime.Json.JsonNode) new Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Runtime.Json.JsonString(this._componentName.ToString()) : null, "componentName" ,container.Add );
AddIf( null != (((object)this._settingName)?.ToString()) ? (Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Runtime.Json.JsonNode) new Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Runtime.Json.JsonString(this._settingName.ToString()) : null, "settingName" ,container.Add );
AddIf( null != (((object)this._content)?.ToString()) ? (Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Runtime.Json.JsonNode) new Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Runtime.Json.JsonString(this._content.ToString()) : null, "content" ,container.Add );
AddIf( null != (((object)this._content)?.ToString()) ? (Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Runtime.Json.JsonNode) new Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Runtime.Json.JsonString(System.Runtime.InteropServices.Marshal.PtrToStringBSTR(System.Runtime.InteropServices.Marshal.SecureStringToBSTR(this._content))) : null, "content" ,container.Add );
AfterToJson(ref container);
return container;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ internal VMAttributeMinMaxDouble(global::System.Collections.IDictionary content)
// actually deserialize
if (content.Contains("Min"))
{
((Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Models.IVMAttributeMinMaxDoubleInternal)this).Min = (float?) content.GetValueForProperty("Min",((Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Models.IVMAttributeMinMaxDoubleInternal)this).Min, (__y)=> (float) global::System.Convert.ChangeType(__y, typeof(float)));
((Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Models.IVMAttributeMinMaxDoubleInternal)this).Min = (double?) content.GetValueForProperty("Min",((Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Models.IVMAttributeMinMaxDoubleInternal)this).Min, (__y)=> (double) global::System.Convert.ChangeType(__y, typeof(double)));
}
if (content.Contains("Max"))
{
((Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Models.IVMAttributeMinMaxDoubleInternal)this).Max = (float?) content.GetValueForProperty("Max",((Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Models.IVMAttributeMinMaxDoubleInternal)this).Max, (__y)=> (float) global::System.Convert.ChangeType(__y, typeof(float)));
((Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Models.IVMAttributeMinMaxDoubleInternal)this).Max = (double?) content.GetValueForProperty("Max",((Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Models.IVMAttributeMinMaxDoubleInternal)this).Max, (__y)=> (double) global::System.Convert.ChangeType(__y, typeof(double)));
}
AfterDeserializeDictionary(content);
}
Expand All @@ -151,11 +151,11 @@ internal VMAttributeMinMaxDouble(global::System.Management.Automation.PSObject c
// actually deserialize
if (content.Contains("Min"))
{
((Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Models.IVMAttributeMinMaxDoubleInternal)this).Min = (float?) content.GetValueForProperty("Min",((Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Models.IVMAttributeMinMaxDoubleInternal)this).Min, (__y)=> (float) global::System.Convert.ChangeType(__y, typeof(float)));
((Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Models.IVMAttributeMinMaxDoubleInternal)this).Min = (double?) content.GetValueForProperty("Min",((Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Models.IVMAttributeMinMaxDoubleInternal)this).Min, (__y)=> (double) global::System.Convert.ChangeType(__y, typeof(double)));
}
if (content.Contains("Max"))
{
((Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Models.IVMAttributeMinMaxDoubleInternal)this).Max = (float?) content.GetValueForProperty("Max",((Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Models.IVMAttributeMinMaxDoubleInternal)this).Max, (__y)=> (float) global::System.Convert.ChangeType(__y, typeof(float)));
((Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Models.IVMAttributeMinMaxDoubleInternal)this).Max = (double?) content.GetValueForProperty("Max",((Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Models.IVMAttributeMinMaxDoubleInternal)this).Max, (__y)=> (double) global::System.Convert.ChangeType(__y, typeof(double)));
}
AfterDeserializePSObject(content);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ public partial class VMAttributeMinMaxDouble :
{

/// <summary>Backing field for <see cref="Max" /> property.</summary>
private float? _max;
private double? _max;

/// <summary>Maximum value. Double.MaxValue(1.7976931348623157E+308)</summary>
[Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Origin(Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.PropertyOrigin.Owned)]
public float? Max { get => this._max; set => this._max = value; }
public double? Max { get => this._max; set => this._max = value; }

/// <summary>Backing field for <see cref="Min" /> property.</summary>
private float? _min;
private double? _min;

/// <summary>Minimum value. default 0. Double.MinValue()</summary>
[Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Origin(Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.PropertyOrigin.Owned)]
public float? Min { get => this._min; set => this._min = value; }
public double? Min { get => this._min; set => this._min = value; }

/// <summary>Creates an new <see cref="VMAttributeMinMaxDouble" /> instance.</summary>
public VMAttributeMinMaxDouble()
Expand All @@ -44,8 +44,8 @@ public partial interface IVMAttributeMinMaxDouble :
Update = true,
Description = @"Maximum value. Double.MaxValue(1.7976931348623157E+308)",
SerializedName = @"max",
PossibleTypes = new [] { typeof(float) })]
float? Max { get; set; }
PossibleTypes = new [] { typeof(double) })]
double? Max { get; set; }
/// <summary>Minimum value. default 0. Double.MinValue()</summary>
[Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Runtime.Info(
Required = false,
Expand All @@ -55,18 +55,18 @@ public partial interface IVMAttributeMinMaxDouble :
Update = true,
Description = @"Minimum value. default 0. Double.MinValue()",
SerializedName = @"min",
PossibleTypes = new [] { typeof(float) })]
float? Min { get; set; }
PossibleTypes = new [] { typeof(double) })]
double? Min { get; set; }

}
/// VMAttributes using double values.
internal partial interface IVMAttributeMinMaxDoubleInternal

{
/// <summary>Maximum value. Double.MaxValue(1.7976931348623157E+308)</summary>
float? Max { get; set; }
double? Max { get; set; }
/// <summary>Minimum value. default 0. Double.MinValue()</summary>
float? Min { get; set; }
double? Min { get; set; }

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Runtime.Json.JsonNode ToJ
{
return container;
}
AddIf( null != this._min ? (Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Runtime.Json.JsonNode)new Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Runtime.Json.JsonNumber((float)this._min) : null, "min" ,container.Add );
AddIf( null != this._max ? (Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Runtime.Json.JsonNode)new Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Runtime.Json.JsonNumber((float)this._max) : null, "max" ,container.Add );
AddIf( null != this._min ? (Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Runtime.Json.JsonNode)new Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Runtime.Json.JsonNumber((double)this._min) : null, "min" ,container.Add );
AddIf( null != this._max ? (Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Runtime.Json.JsonNode)new Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Runtime.Json.JsonNumber((double)this._max) : null, "max" ,container.Add );
AfterToJson(ref container);
return container;
}
Expand All @@ -100,8 +100,8 @@ internal VMAttributeMinMaxDouble(Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet
{
return;
}
{_min = If( json?.PropertyT<Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Runtime.Json.JsonNumber>("min"), out var __jsonMin) ? (float?)__jsonMin : _min;}
{_max = If( json?.PropertyT<Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Runtime.Json.JsonNumber>("max"), out var __jsonMax) ? (float?)__jsonMax : _max;}
{_min = If( json?.PropertyT<Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Runtime.Json.JsonNumber>("min"), out var __jsonMin) ? (double?)__jsonMin : _min;}
{_max = If( json?.PropertyT<Microsoft.Azure.PowerShell.Cmdlets.ComputeFleet.Runtime.Json.JsonNumber>("max"), out var __jsonMax) ? (double?)__jsonMax : _max;}
AfterFromJson(json);
}
}
Expand Down
Loading

0 comments on commit a938906

Please sign in to comment.