Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: internal
packages:
- "@typespec/versioning"
---

Fix versioning validation regression
3 changes: 2 additions & 1 deletion packages/versioning/src/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,12 +535,13 @@ function validateReference(program: Program, source: Type | Type[], target: Type
}
}

const sources = Array.isArray(source) ? source : [source];
switch (target.kind) {
case "Model":
// For anonymous model expressions (inline models), validate their properties
if (!target.name) {
for (const prop of target.properties.values()) {
validateReference(program, source, prop.type);
validateReference(program, [prop, ...sources], prop.type);
}
}
break;
Expand Down
17 changes: 13 additions & 4 deletions packages/versioning/test/incompatible-versioning.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ describe("versioning: validate incompatible references", () => {
});

describe("operation", () => {
// TODO See: https://github.com/microsoft/typespec/issues/2695
it.skip("emit diagnostic when unversioned op has a versioned model as a parameter", async () => {
it("emit diagnostic when unversioned op has a versioned model as a parameter", async () => {
const diagnostics = await runner.diagnose(`
@added(Versions.v2)
model Foo {}
Expand Down Expand Up @@ -111,8 +110,7 @@ describe("versioning: validate incompatible references", () => {
});
});

// TODO See: https://github.com/microsoft/typespec/issues/2695
it.skip("emit diagnostic when unversioned op based on a template has a versioned model as a parameter", async () => {
it("emit diagnostic when unversioned op based on a template has a versioned model as a parameter", async () => {
const diagnostics = await runner.diagnose(`
@added(Versions.v2)
model Foo {}
Expand Down Expand Up @@ -1095,6 +1093,17 @@ describe("versioning: validate incompatible references", () => {
});
});

describe("succeed when annotations are correctly defined", () => {
it("on property inside model expression", async () => {
const diagnostics = await runner.diagnose(`
@added(Versions.v3)
model A {}
model B { prop: { @added(Versions.v3) a: A }}
`);
expectDiagnosticEmpty(diagnostics);
});
});

describe("report issues inside model expression under model", () => {
it("when base model is added before", async () => {
const diagnostics = await runner.diagnose(
Expand Down
Loading