Skip to content

Commit

Permalink
Fix issue with operation parameter versioning (#2691)
Browse files Browse the repository at this point in the history
Fixes #2688.
  • Loading branch information
tjprescott authored Nov 22, 2023
1 parent cc03604 commit b3075f0
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@typespec/versioning",
"comment": "",
"type": "none"
}
],
"packageName": "@typespec/versioning"
}
18 changes: 0 additions & 18 deletions packages/versioning/src/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,24 +532,6 @@ function validateOperationParameter(
return;
}
}

if (paramAvailability !== undefined) {
validateAvailabilityForContains(
program,
operationAvailability,
paramAvailability,
operation,
parameter
);
} else if (paramTypeAvailability !== undefined) {
validateAvailabilityForRef(
program,
operationAvailability,
paramTypeAvailability,
operation,
parameter.type
);
}
}

/**
Expand Down
46 changes: 0 additions & 46 deletions packages/versioning/test/incompatible-versioning.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,52 +146,6 @@ describe("versioning: validate incompatible references", () => {
});
});

it("emit diagnostic when when op was added before parameter type", async () => {
const diagnostics = await runner.diagnose(`
@added(Versions.v2)
model Foo {}
@added(Versions.v1)
op test(param: Foo): void;
`);
expectDiagnostics(diagnostics, {
code: "@typespec/versioning/incompatible-versioned-reference",
message:
"'TestService.test' was added in version 'v1' but referencing type 'TestService.Foo' added in version 'v2'.",
});
});

it("emit diagnostic when op based on a template was added before parameter type", async () => {
const diagnostics = await runner.diagnose(`
@added(Versions.v2)
model Foo {}
op Template<T>(param: T): void;
@added(Versions.v1)
op test is Template<Foo>;
`);
expectDiagnostics(diagnostics, {
code: "@typespec/versioning/incompatible-versioned-reference",
message:
"'TestService.test' was added in version 'v1' but referencing type 'TestService.Foo' added in version 'v2'.",
});
});

it("emit diagnostic when when parameter was added before op", async () => {
const diagnostics = await runner.diagnose(`
model Foo {}
@added(Versions.v2)
op test(@added(Versions.v1) param: Foo): void;
`);
expectDiagnostics(diagnostics, {
code: "@typespec/versioning/incompatible-versioned-reference",
message:
"'TestService.test' was added in version 'v2' but contains type 'TestService.(anonymous model).param' added in version 'v1'.",
});
});

it("emit diagnostic when type changed to types that don't exist", async () => {
const diagnostics = await runner.diagnose(`
@added(Versions.v3)
Expand Down
28 changes: 28 additions & 0 deletions packages/versioning/test/versioning.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,34 @@ describe("versioning: logic", () => {
w2.operations.get("create")?.parameters.properties.size === 2;
});

it("can share a model reference between operations with different versions", async () => {
const code = `
@test("MyService")
@versioned(Versions)
namespace MyService;
enum Versions { v1, v2, v3 };
model Foo {
prop: string;
}
model Parameters {
name: string;
@added(Versions.v2)
age: Foo;
}
@added(Versions.v1)
op oldOp(...Parameters): void;
@added(Versions.v3)
op newOp(...Parameters): void;
`;
ok(await runner.compile(code));
});

it("can be removed", async () => {
const {
projections: [v1, v2],
Expand Down

0 comments on commit b3075f0

Please sign in to comment.