Skip to content

Commit

Permalink
Project source models (#4445)
Browse files Browse the repository at this point in the history
fix [#4280](#4280)

---------

Co-authored-by: Christopher Radek <[email protected]>
  • Loading branch information
timotheeguerin and chrisradek authored Oct 7, 2024
1 parent 0defe8f commit aaae51a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- "@typespec/compiler"
---

[API] model `sourceModels` property are now projected correctly
4 changes: 4 additions & 0 deletions packages/compiler/src/core/projector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ export function createProjector(
projectedModel.sourceModel = projectType(model.sourceModel) as Model;
}

projectedModel.sourceModels = model.sourceModels.map((source) => {
return { ...source, model: projectType(source.model) as Model };
});

if (model.indexer) {
const projectedValue = projectType(model.indexer.value);
projectedModel.indexer = {
Expand Down
16 changes: 16 additions & 0 deletions packages/compiler/test/projection/projector-identity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,22 @@ describe("compiler: projector: Identity", () => {
strictEqual(projectResult.type.properties.get("name")?.model, projectResult.type);
});

it("link projected model with sourceModels", async () => {
const code = `
@test("target") model Foo is Bar {
...Spreadable
}
model Bar {}
model Spreadable {}
`;
const projectResult = await projectWithNoChange(code, "Model");
const [sourceBar, sourceSpreadable] = projectResult.type.sourceModels.map((x) => x.model);
const Spreadable = projectResult.globalNamespace.models.get("Spreadable")!;
const Bar = projectResult.globalNamespace.models.get("Bar")!;
strictEqual(sourceBar, Bar);
strictEqual(sourceSpreadable, Spreadable);
});

it("link projected property with sourceProperty", async () => {
const code = `
@test("target") model Foo {
Expand Down

0 comments on commit aaae51a

Please sign in to comment.