Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/typespec-ts/src/modular/emitModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ export function normalizeModelName(
: "";
const internalModelPrefix =
isPagedResultModel(context, type) || type.isGeneratedName ? "_" : "";
return `${internalModelPrefix}${normalizeName(namespacePrefix + type.name + unionSuffix, nameType, true)}`;
return `${internalModelPrefix}${normalizeName(namespacePrefix + type.name, nameType, true)}${unionSuffix}`;
}

function buildModelPolymorphicType(context: SdkContext, type: SdkModelType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,33 @@ model SimpleModel {
propArrayOfRecordOfUnionOptional?: Record<string | boolean | int32>[];
@encodedName("application/json", "prop_encoded")
propEncoded: string;
propNotNormalizeModel: FOO;
propNormalizeModel: FOOBAR;
propRecordOfUnionArrayNotNormalize: Record<NFVIs[]>;
Copy link
Copy Markdown
Member

@MaryGao MaryGao Dec 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

propRecordOfUnionArrayNotNormalize: NFVIs[];
propRecordOfUnionArrayNotNormalize: Record<NFVIs>;

}

@discriminator("nfviType")
model NFVIs {
name?: string;
nfviType: string;
}

model AzureCoreNFVIDetails extends NFVIs {
location?: string;
nfviType: "AzureCore";
}

model AzureArcK8sClusterNFVIDetails extends NFVIs {
customLocationId?: string;
nfviType: "AzureArcKubernetes";
}

model FOOBAR{
name?: Record<NFVIs[]>;
}

model FOO {
param?: FOOBAR;
}

@route("/serialize")
Expand Down Expand Up @@ -105,6 +132,9 @@ export interface SimpleModel {
propArrayOfRecordOfUnion: Record<string, string | boolean | number>[];
propArrayOfRecordOfUnionOptional?: Record<string, string | boolean | number>[];
propEncoded: string;
propNotNormalizeModel: FOO;
propNormalizeModel: Foobar;
propRecordOfUnionArrayNotNormalize: Record<string, NFVIsUnion[]>;
}

export function simpleModelSerializer(item: SimpleModel): any {
Expand Down Expand Up @@ -186,6 +216,11 @@ export function simpleModelSerializer(item: SimpleModel): any {
item["propArrayOfRecordOfUnionOptional"],
),
prop_encoded: item["propEncoded"],
propNotNormalizeModel: fooSerializer(item["propNotNormalizeModel"]),
propNormalizeModel: foobarSerializer(item["propNormalizeModel"]),
propRecordOfUnionArrayNotNormalize: nfvIsUnionArrayRecordSerializer(
item["propRecordOfUnionArrayNotNormalize"],
),
};
}

Expand Down Expand Up @@ -382,4 +417,88 @@ export function _simpleModelPropArrayOfRecordOfUnionOptionalSerializer(
): any {
return item;
}

/** model interface FOO */
export interface FOO {
param?: Foobar;
}

export function fooSerializer(item: FOO): any {
return { param: !item["param"] ? item["param"] : foobarSerializer(item["param"]) };
}

/** model interface Foobar */
export interface Foobar {
name?: Record<string, NFVIsUnion[]>;
}

export function foobarSerializer(item: Foobar): any {
return { name: !item["name"] ? item["name"] : nfvIsUnionArrayRecordSerializer(item["name"]) };
}

export function nfvIsUnionArrayRecordSerializer(
item: Record<string, Array<NFVIsUnion>>,
): Record<string, any> {
const result: Record<string, any> = {};
Object.keys(item).map((key) => {
result[key] = !item[key] ? item[key] : nfvIsUnionArraySerializer(item[key]);
});
return result;
}

export function nfvIsUnionArraySerializer(result: Array<NFVIsUnion>): any[] {
return result.map((item) => {
return nfvIsUnionSerializer(item);
});
}

/** model interface NFVIs */
export interface NFVIs {
name?: string;
nfviType: string;
}

export function nfvIsSerializer(item: NFVIs): any {
return { name: item["name"], nfviType: item["nfviType"] };
}

/** Alias for NFVIsUnion */
export type NFVIsUnion = AzureCoreNfviDetails | AzureArcK8SClusterNfviDetails | NFVIs;

export function nfvIsUnionSerializer(item: NFVIsUnion): any {
switch (item.nfviType) {
case "AzureCore":
return azureCoreNfviDetailsSerializer(item as AzureCoreNfviDetails);

case "AzureArcKubernetes":
return azureArcK8SClusterNfviDetailsSerializer(item as AzureArcK8SClusterNfviDetails);

default:
return nfvIsSerializer(item);
}
}

/** model interface AzureCoreNfviDetails */
export interface AzureCoreNfviDetails extends NFVIs {
location?: string;
nfviType: "AzureCore";
}

export function azureCoreNfviDetailsSerializer(item: AzureCoreNfviDetails): any {
return { name: item["name"], nfviType: item["nfviType"], location: item["location"] };
}

/** model interface AzureArcK8SClusterNfviDetails */
export interface AzureArcK8SClusterNfviDetails extends NFVIs {
customLocationId?: string;
nfviType: "AzureArcKubernetes";
}

export function azureArcK8SClusterNfviDetailsSerializer(item: AzureArcK8SClusterNfviDetails): any {
return {
name: item["name"],
nfviType: item["nfviType"],
customLocationId: item["customLocationId"],
};
}
```
Loading