Skip to content

Commit e39ad19

Browse files
authored
tsp - add support for anonymous object/dicts (#1517)
* tsp - use schema description if property comment is not specified * tsp - Add support for anonymous object/dict
1 parent 9da9d91 commit e39ad19

File tree

783 files changed

+21154
-5232
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

783 files changed

+21154
-5232
lines changed

packages/typespec-powershell/src/convertor/convertor.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ function getSchemas(program: Program, client: SdkClient, psContext: SdkContext,
6868
schema.language.default.description = "Anything";
6969
schemas["any"] = schemas["any"] || [];
7070
schemas["any"].push(schema);
71+
} else if (schema.type === SchemaType.Dictionary && !schema.language) {
72+
// skip anonymous dictionary schema
73+
continue;
7174
} else {
7275
if (schema.type === SchemaType.Array && (<any>schema).delayType) {
7376
(<ArraySchema>schema).elementType = getSchemaForType(psContext, (<any>schema).delayType as Type);

packages/typespec-powershell/src/utils/modelUtils.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ export function getSchemaForType(
222222
propertySchema.language.default.description = getDoc(program, type) || "";
223223
schemaCache.set(type, <Schema>propertySchema);
224224
return propertySchema;
225+
} else if (type.type.kind === "Model" && isRecordModelType(program, type.type) && type.type.name === "Record") {
226+
const propertySchema = { ...typeSchema };
227+
schemaCache.set(type, <Schema>propertySchema);
228+
return propertySchema;
225229
} else {
226230
return typeSchema;
227231
}
@@ -933,7 +937,7 @@ function getSchemaForModel(
933937
(<Schema>propSchema).language = (<Schema>propSchema).language || {};
934938
(<Schema>propSchema).language.default = (<Schema>propSchema).language.default || {};
935939
(<Schema>propSchema).language.default.description = (<Schema>propSchema).language.default.description || propertyDescription || "";
936-
(<Schema>propSchema).language.default.name = (<Schema>propSchema).language.default.name || name;
940+
(<Schema>propSchema).language.default.name = (<Schema>propSchema).language.default.name || modelSchema.language.default.name + '-' + name;
937941
}
938942
// ToDo: need to confirm there is no duplicated properties.
939943
const property = new Property(name, getDoc(program, prop) || propSchema.language.default.description || "", propSchema || new ObjectSchema(name, ""));
@@ -1315,8 +1319,12 @@ function getSchemaForRecordModel(
13151319
schema = {
13161320
type: "dictionary",
13171321
elementType: valueType,
1318-
description: getDoc(program, type)
1322+
description: getDoc(program, type),
13191323
};
1324+
// If name is Record, it is an anonymous dict. And for anonymous dict, we will create schema in each used property and let `default` created later.
1325+
if (type.name !== "Record") {
1326+
schema.default = { name: type.name, description: getDoc(program, type) };
1327+
}
13201328
if (
13211329
!program.checker.isStdType(indexer.value) &&
13221330
!isUnknownType(indexer.value!) &&

tests-upgrade/tests-emitter/AppComplianceAutomation.Management/target/generated/api/Models/ErrorResponse.PowerShell.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,6 @@ internal ErrorResponse(global::System.Collections.IDictionary content)
106106
{
107107
((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorResponseInternal)this).Error = (Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorDetail) content.GetValueForProperty("Error",((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorResponseInternal)this).Error, Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.ErrorDetailTypeConverter.ConvertFrom);
108108
}
109-
if (content.Contains("Detail"))
110-
{
111-
((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorResponseInternal)this).Detail = (System.Collections.Generic.List<Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorDetail>) content.GetValueForProperty("Detail",((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorResponseInternal)this).Detail, __y => TypeConverterExtensions.SelectToList<Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorDetail>(__y, Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.ErrorDetailTypeConverter.ConvertFrom));
112-
}
113-
if (content.Contains("AdditionalInfo"))
114-
{
115-
((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorResponseInternal)this).AdditionalInfo = (System.Collections.Generic.List<Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorAdditionalInfo>) content.GetValueForProperty("AdditionalInfo",((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorResponseInternal)this).AdditionalInfo, __y => TypeConverterExtensions.SelectToList<Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorAdditionalInfo>(__y, Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.ErrorAdditionalInfoTypeConverter.ConvertFrom));
116-
}
117109
if (content.Contains("Code"))
118110
{
119111
((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorResponseInternal)this).Code = (string) content.GetValueForProperty("Code",((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorResponseInternal)this).Code, global::System.Convert.ToString);
@@ -126,6 +118,14 @@ internal ErrorResponse(global::System.Collections.IDictionary content)
126118
{
127119
((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorResponseInternal)this).Target = (string) content.GetValueForProperty("Target",((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorResponseInternal)this).Target, global::System.Convert.ToString);
128120
}
121+
if (content.Contains("Detail"))
122+
{
123+
((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorResponseInternal)this).Detail = (System.Collections.Generic.List<Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorDetail>) content.GetValueForProperty("Detail",((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorResponseInternal)this).Detail, __y => TypeConverterExtensions.SelectToList<Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorDetail>(__y, Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.ErrorDetailTypeConverter.ConvertFrom));
124+
}
125+
if (content.Contains("AdditionalInfo"))
126+
{
127+
((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorResponseInternal)this).AdditionalInfo = (System.Collections.Generic.List<Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorAdditionalInfo>) content.GetValueForProperty("AdditionalInfo",((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorResponseInternal)this).AdditionalInfo, __y => TypeConverterExtensions.SelectToList<Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorAdditionalInfo>(__y, Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.ErrorAdditionalInfoTypeConverter.ConvertFrom));
128+
}
129129
AfterDeserializeDictionary(content);
130130
}
131131

@@ -147,14 +147,6 @@ internal ErrorResponse(global::System.Management.Automation.PSObject content)
147147
{
148148
((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorResponseInternal)this).Error = (Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorDetail) content.GetValueForProperty("Error",((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorResponseInternal)this).Error, Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.ErrorDetailTypeConverter.ConvertFrom);
149149
}
150-
if (content.Contains("Detail"))
151-
{
152-
((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorResponseInternal)this).Detail = (System.Collections.Generic.List<Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorDetail>) content.GetValueForProperty("Detail",((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorResponseInternal)this).Detail, __y => TypeConverterExtensions.SelectToList<Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorDetail>(__y, Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.ErrorDetailTypeConverter.ConvertFrom));
153-
}
154-
if (content.Contains("AdditionalInfo"))
155-
{
156-
((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorResponseInternal)this).AdditionalInfo = (System.Collections.Generic.List<Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorAdditionalInfo>) content.GetValueForProperty("AdditionalInfo",((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorResponseInternal)this).AdditionalInfo, __y => TypeConverterExtensions.SelectToList<Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorAdditionalInfo>(__y, Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.ErrorAdditionalInfoTypeConverter.ConvertFrom));
157-
}
158150
if (content.Contains("Code"))
159151
{
160152
((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorResponseInternal)this).Code = (string) content.GetValueForProperty("Code",((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorResponseInternal)this).Code, global::System.Convert.ToString);
@@ -167,6 +159,14 @@ internal ErrorResponse(global::System.Management.Automation.PSObject content)
167159
{
168160
((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorResponseInternal)this).Target = (string) content.GetValueForProperty("Target",((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorResponseInternal)this).Target, global::System.Convert.ToString);
169161
}
162+
if (content.Contains("Detail"))
163+
{
164+
((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorResponseInternal)this).Detail = (System.Collections.Generic.List<Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorDetail>) content.GetValueForProperty("Detail",((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorResponseInternal)this).Detail, __y => TypeConverterExtensions.SelectToList<Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorDetail>(__y, Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.ErrorDetailTypeConverter.ConvertFrom));
165+
}
166+
if (content.Contains("AdditionalInfo"))
167+
{
168+
((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorResponseInternal)this).AdditionalInfo = (System.Collections.Generic.List<Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorAdditionalInfo>) content.GetValueForProperty("AdditionalInfo",((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorResponseInternal)this).AdditionalInfo, __y => TypeConverterExtensions.SelectToList<Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IErrorAdditionalInfo>(__y, Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.ErrorAdditionalInfoTypeConverter.ConvertFrom));
169+
}
170170
AfterDeserializePSObject(content);
171171
}
172172

0 commit comments

Comments
 (0)