Skip to content

Commit

Permalink
Revert "Fix typeChangedFrom of template/union to catch invalid versio…
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisradek authored Dec 3, 2024
1 parent ee359ef commit 968f9c9
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 119 deletions.

This file was deleted.

12 changes: 0 additions & 12 deletions packages/versioning/src/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,18 +226,6 @@ function validateMultiTypeReference(program: Program, source: Type, options?: Ty
const availMap = getAvailabilityMap(program, type);
const availability = availMap?.get(version.name) ?? Availability.Available;
if ([Availability.Added, Availability.Available].includes(availability)) {
// Check if there are any indexed/template arguments that are validated...
if (isTemplateInstance(type)) {
for (const arg of type.templateMapper.args) {
if (isType(arg)) {
validateReference(program, source, arg);
}
}
} else if (type.kind === "Union") {
for (const variant of type.variants.values()) {
validateReference(program, source, variant.type);
}
}
continue;
}
reportDiagnostic(program, {
Expand Down
100 changes: 0 additions & 100 deletions packages/versioning/test/incompatible-versioning.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,106 +387,6 @@ describe("versioning: validate incompatible references", () => {
});
});

it("emit diagnostic when using @typeChangedFrom with a type parameter that does not yet exist in arrays", async () => {
const diagnostics = await runner.diagnose(`
@test
@added(Versions.v2)
model Original {}
@test
@added(Versions.v2)
model Updated {}
@test
model Test {
@typeChangedFrom(Versions.v2, Original[])
prop: Updated;
}
`);
expectDiagnostics(diagnostics, {
code: "@typespec/versioning/incompatible-versioned-reference",
severity: "error",
message:
"'TestService.Test.prop' was added in version 'v1' but referencing type 'TestService.Original' added in version 'v2'.",
});
});

it("emit diagnostic when using @typeChangedFrom with a type parameter that does not yet exist in records", async () => {
const diagnostics = await runner.diagnose(`
@test
@added(Versions.v2)
model Original {}
@test
@added(Versions.v2)
model Updated {}
@test
model Test {
@typeChangedFrom(Versions.v2, Record<Original>)
prop: Updated;
}
`);
expectDiagnostics(diagnostics, {
code: "@typespec/versioning/incompatible-versioned-reference",
severity: "error",
message:
"'TestService.Test.prop' was added in version 'v1' but referencing type 'TestService.Original' added in version 'v2'.",
});
});

it("emit diagnostic when using @typeChangedFrom with a type parameter that does not yet exist in unions", async () => {
const diagnostics = await runner.diagnose(`
@test
@added(Versions.v2)
model Original {}
@test
@added(Versions.v2)
model Updated {}
@test
model Test {
@typeChangedFrom(Versions.v2, Original | string)
prop: Updated;
}
`);
expectDiagnostics(diagnostics, {
code: "@typespec/versioning/incompatible-versioned-reference",
severity: "error",
message:
"'TestService.Test.prop' was added in version 'v1' but referencing type 'TestService.Original' added in version 'v2'.",
});
});

it("emit diagnostic when using @typeChangedFrom with a type parameter that does not yet exist in template", async () => {
const diagnostics = await runner.diagnose(`
@test
@added(Versions.v2)
model Original {}
@test
@added(Versions.v2)
model Updated {}
model Template<T> {
prop: T;
}
@test
model Test {
@typeChangedFrom(Versions.v2, Template<Original>)
prop: Updated;
}
`);
expectDiagnostics(diagnostics, {
code: "@typespec/versioning/incompatible-versioned-reference",
severity: "error",
message:
"'TestService.Test.prop' was added in version 'v1' but referencing type 'TestService.Original' added in version 'v2'.",
});
});

it("succeed if version are compatible in model", async () => {
const diagnostics = await runner.diagnose(`
@added(Versions.v2)
Expand Down

0 comments on commit 968f9c9

Please sign in to comment.