Skip to content

Commit a0746c6

Browse files
authored
[TSP] Support number union (#1530)
* support number union * remove redundant reference * add storagemover as tsp test case * try fix storage mover test * fix1 * fix2 * fix3
1 parent 0f5fe0e commit a0746c6

File tree

696 files changed

+144133
-312
lines changed

Some content is hidden

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

696 files changed

+144133
-312
lines changed

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

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -550,19 +550,59 @@ function getSchemaForUnion(
550550
const values = [];
551551
const [asEnum, _] = getUnionAsEnum(union);
552552
if (asEnum) {
553-
schema = new SealedChoiceSchema(union.name || "", getDoc(dpgContext.program, union) || "");
554553
for (const [name, member] of asEnum.flattenedMembers.entries()) {
555554
values.push(getChoiceValueForUnionVariant(dpgContext, member.type, member.value));
556555
}
557-
schema.choices = values;
558556
// ToDo: by xiaogang, add support for other types of enum except string
559-
schema.choiceType = new StringSchema("enum", "string schema for enum");
557+
switch (asEnum.kind) {
558+
case "number":
559+
schema = new SealedChoiceSchema<NumberSchema>(union.name || "", getDoc(dpgContext.program, union) || "");
560+
schema.choiceType = new NumberSchema("enum", "number schema for enum", ...getPrecisionForNumberUnion(union));
561+
break;
562+
case "string":
563+
default:
564+
schema = new SealedChoiceSchema(union.name || "", getDoc(dpgContext.program, union) || "");
565+
schema.choiceType = new StringSchema("enum", "string schema for enum");
566+
break;
567+
}
568+
schema.choices = values;
560569
}
561570
//Yabo: if not able to flatten as enum, return empty
562571
}
563572
return schema;
564573
}
565574

575+
function getPrecisionForNumberUnion(union: Union): [SchemaType.Number|SchemaType.Integer, number] {
576+
if (union && union.variants) {
577+
for (const variant of union.variants.values()) {
578+
if (variant.type.kind === "Scalar") {
579+
const scalar = variant.type.name;
580+
switch (scalar) {
581+
case "int8":
582+
case "uint8":
583+
return [SchemaType.Integer, 8];
584+
case "int16":
585+
case "uint16":
586+
return [SchemaType.Integer, 16];
587+
case "int32":
588+
case "uint32":
589+
case "integer":
590+
return [SchemaType.Integer, 32];
591+
case "int64":
592+
case "uint64":
593+
return [SchemaType.Integer, 64];
594+
case "float":
595+
case "float32":
596+
return [SchemaType.Number, 32];
597+
case "float64":
598+
return [SchemaType.Number, 64];
599+
}
600+
}
601+
}
602+
}
603+
return [SchemaType.Number, 64];
604+
}
605+
566606
function getSchemaForUnionVariant(
567607
dpgContext: SdkContext,
568608
variant: UnionVariant,

tests-upgrade/tests-emitter/AzureAI.Assets/target/.gitignore

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests-upgrade/tests-emitter/AzureFleet.Management/target/.gitignore

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests-upgrade/tests-emitter/CodeSigning.Management/target/.gitignore

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests-upgrade/tests-emitter/ComputeSchedule.Management/target/.gitignore

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests-upgrade/tests-emitter/DeviceRegistry.Management/target/.gitignore

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests-upgrade/tests-emitter/DocumentDB.MongoCluster.Management/target/.gitignore

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests-upgrade/tests-emitter/EdgeZones.Management/target/.gitignore

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests-upgrade/tests-emitter/HealthDataAIServices.Management/target/.gitignore

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests-upgrade/tests-emitter/Informatica.DataManagement.Management/target/.gitignore

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)