Skip to content
This repository was archived by the owner on Jun 30, 2026. It is now read-only.

Commit e8b5a80

Browse files
maorlegerCopilot
andcommitted
fix(typespec-ts): emit models from filtered IR, drop TCGC import from models renderer
The new pipeline's models renderer was still walking the legacy global emit queue, so it bypassed the adapter's filtered TSCodeModel.models/enums/unions set and reintroduced paging result types like *ListResult onto the public surface. Switch file selection to the filtered IR and look raw sdk types up only for the legacy declaration/serializer helpers that are still shared with src/modular/emitModels.ts. The production path remains src/codegen/models.ts; the legacy file stays as a rendering helper while this removes the direct TCGC dependency from the codegen layer. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent e35c324 commit e8b5a80

1 file changed

Lines changed: 63 additions & 27 deletions

File tree

packages/typespec-ts/src/codegen/models.ts

Lines changed: 63 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
1-
import {
2-
SdkArrayType,
3-
SdkDictionaryType,
4-
SdkNullableType,
5-
SdkType
6-
} from "@azure-tools/typespec-client-generator-core";
71
import { Project, SourceFile } from "ts-morph";
82
import type { TSCodeModel } from "../codemodel/index.js";
93
import type { SdkContext } from "../utils/interfaces.js";
10-
import {
11-
flattenPropertyModelMap,
12-
emitQueue
13-
} from "../framework/hooks/sdkTypes.js";
4+
import { flattenPropertyModelMap } from "../framework/hooks/sdkTypes.js";
145
import {
156
addSerializationFunctions,
167
emitType,
@@ -21,28 +12,69 @@ import {
2112
/**
2213
* Emit model, enum, and union files from the code model.
2314
*
24-
* Serializers stay on the legacy helpers for now, but file selection and the
25-
* declaration walk come from the new code model.
15+
* Serializers stay on the legacy helpers for now, but model selection comes
16+
* from the filtered IR rather than the global TCGC emit queue.
2617
*/
2718
export function emitModelFiles(
2819
project: Project,
2920
codeModel: TSCodeModel,
3021
sdkContext: SdkContext
3122
): SourceFile[] {
32-
for (const type of emitQueue) {
33-
if (!isGenerableType(type)) {
23+
const rawModelLookup = buildRawTypeLookup(sdkContext.sdkPackage.models, sdkContext);
24+
const rawEnumLookup = buildRawTypeLookup(sdkContext.sdkPackage.enums, sdkContext);
25+
const rawUnionLookup = buildRawTypeLookup(sdkContext.sdkPackage.unions, sdkContext);
26+
const includedModelKeys = new Set<string>();
27+
28+
for (const model of codeModel.models) {
29+
const rawModel = rawModelLookup.get(getTypeKey(model.name, model.namespace));
30+
if (!rawModel) {
31+
continue;
32+
}
33+
34+
includedModelKeys.add(getRawTypeKey(rawModel, sdkContext));
35+
const sourceFile = getOrCreateModelsFile(
36+
project,
37+
codeModel.settings.sourceRoot,
38+
model.namespace
39+
);
40+
emitType(sdkContext, rawModel, sourceFile);
41+
}
42+
43+
for (const enumType of codeModel.enums) {
44+
const rawEnum = rawEnumLookup.get(getTypeKey(enumType.name, enumType.namespace));
45+
if (!rawEnum) {
46+
continue;
47+
}
48+
49+
const sourceFile = getOrCreateModelsFile(
50+
project,
51+
codeModel.settings.sourceRoot,
52+
enumType.namespace
53+
);
54+
emitType(sdkContext, rawEnum, sourceFile);
55+
}
56+
57+
for (const unionType of codeModel.unions) {
58+
const rawUnion = rawUnionLookup.get(
59+
getTypeKey(unionType.name, unionType.namespace)
60+
);
61+
if (!rawUnion) {
3462
continue;
3563
}
3664

3765
const sourceFile = getOrCreateModelsFile(
3866
project,
3967
codeModel.settings.sourceRoot,
40-
getModelNamespaces(sdkContext, type)
68+
unionType.namespace
4169
);
42-
emitType(sdkContext, type, sourceFile);
70+
emitType(sdkContext, rawUnion, sourceFile);
4371
}
4472

45-
for (const [property] of flattenPropertyModelMap) {
73+
for (const [property, baseModel] of flattenPropertyModelMap) {
74+
if (!includedModelKeys.has(getRawTypeKey(baseModel, sdkContext))) {
75+
continue;
76+
}
77+
4678
const sourceFile = getOrCreateModelsFile(
4779
project,
4880
codeModel.settings.sourceRoot,
@@ -54,19 +86,23 @@ export function emitModelFiles(
5486
return cleanupEmptyModelFiles(project, codeModel.settings.sourceRoot);
5587
}
5688

57-
function isGenerableType(
58-
type: SdkType
59-
): type is SdkArrayType | SdkDictionaryType | SdkNullableType | SdkType {
60-
return (
61-
type.kind === "model" ||
62-
type.kind === "enum" ||
63-
type.kind === "union" ||
64-
type.kind === "dict" ||
65-
type.kind === "array" ||
66-
type.kind === "nullable"
89+
function buildRawTypeLookup<T extends { name: string }>(
90+
types: readonly T[],
91+
sdkContext: SdkContext
92+
): Map<string, T> {
93+
return new Map(
94+
types.map((type) => [getRawTypeKey(type, sdkContext), type] as const)
6795
);
6896
}
6997

98+
function getRawTypeKey(type: { name: string }, sdkContext: SdkContext): string {
99+
return getTypeKey(type.name, getModelNamespaces(sdkContext, type as any));
100+
}
101+
102+
function getTypeKey(name: string, namespace: string[]): string {
103+
return `${namespace.join("/")}:${name}`;
104+
}
105+
70106
function getOrCreateModelsFile(
71107
project: Project,
72108
sourceRoot: string,

0 commit comments

Comments
 (0)