Skip to content

Commit b0f7b53

Browse files
Fix versioning validation regression (#9454)
#9444 introduced a regression in reporting things that are valid Typespec azure check PR with integration tests runnign Azure/typespec-azure#3832
1 parent 2d781df commit b0f7b53

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
3+
changeKind: internal
4+
packages:
5+
- "@typespec/versioning"
6+
---
7+
8+
Fix versioning validation regression

packages/versioning/src/validate.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,12 +535,13 @@ function validateReference(program: Program, source: Type | Type[], target: Type
535535
}
536536
}
537537

538+
const sources = Array.isArray(source) ? source : [source];
538539
switch (target.kind) {
539540
case "Model":
540541
// For anonymous model expressions (inline models), validate their properties
541542
if (!target.name) {
542543
for (const prop of target.properties.values()) {
543-
validateReference(program, source, prop.type);
544+
validateReference(program, [prop, ...sources], prop.type);
544545
}
545546
}
546547
break;

packages/versioning/test/incompatible-versioning.test.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ describe("versioning: validate incompatible references", () => {
6868
});
6969

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

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

1096+
describe("succeed when annotations are correctly defined", () => {
1097+
it("on property inside model expression", async () => {
1098+
const diagnostics = await runner.diagnose(`
1099+
@added(Versions.v3)
1100+
model A {}
1101+
model B { prop: { @added(Versions.v3) a: A }}
1102+
`);
1103+
expectDiagnosticEmpty(diagnostics);
1104+
});
1105+
});
1106+
10981107
describe("report issues inside model expression under model", () => {
10991108
it("when base model is added before", async () => {
11001109
const diagnostics = await runner.diagnose(

0 commit comments

Comments
 (0)