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,10 @@
{
"changes": [
{
"packageName": "@typespec/versioning",
"comment": "Fix issue where \"is\" dependencies were not detected.",
"type": "none"
}
],
"packageName": "@typespec/versioning"
}
2 changes: 2 additions & 0 deletions packages/versioning/src/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export function $onValidate(program: Program) {
if (isTemplateInstance(model)) {
return;
}
addDependency(model.namespace, model.sourceModel);
addDependency(model.namespace, model.baseModel);
for (const prop of model.properties.values()) {
addDependency(model.namespace, prop.type);
Expand Down Expand Up @@ -75,6 +76,7 @@ export function $onValidate(program: Program) {
}

const namespace = op.namespace ?? op.interface?.namespace;
addDependency(namespace, op.sourceOperation);
addDependency(namespace, op.parameters);
addDependency(namespace, op.returnType);

Expand Down
67 changes: 66 additions & 1 deletion packages/versioning/test/versioned-dependencies.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ describe("versioning: reference versioned library", () => {
name: string;
@added(Versions.l2) age: int32;
}

@removed(Versions.l2)
op Operation<TParams, TResponse>(...TParams): TResponse;
}
${code}`,
});
Expand All @@ -47,6 +50,8 @@ describe("versioning: reference versioned library", () => {
@useDependency(VersionedLib.Versions.l1)
@test namespace MyService {
@test model Test extends VersionedLib.Foo {}
@test op test1 is VersionedLib.Operation<{name: string}, int32>;
alias test2 = VersionedLib.Operation<{name: string}, int32>;
}
`)) as { MyService: Namespace; Test: Model };
const versions = buildVersionProjections(runner.program, MyService);
Expand Down Expand Up @@ -74,6 +79,8 @@ describe("versioning: reference versioned library", () => {
@test model Test extends VersionedLib.Foo {}

@test op getBar(): OtherVersionedLib.Bar;
@test op test1 is VersionedLib.Operation<{name: string}, int32>;
alias test2 = VersionedLib.Operation<{name: string}, int32>;
}
`)) as { MyService: Namespace; Test: Model; getBar: Operation };
const versions = buildVersionProjections(runner.program, MyService);
Expand Down Expand Up @@ -116,6 +123,8 @@ describe("versioning: reference versioned library", () => {
v2
}
@test model Test extends VersionedLib.Foo {}
@test op test1 is VersionedLib.Operation<{name: string}, int32>;
alias test2 = VersionedLib.Operation<{name: string}, int32>;
}
`)) as { MyService: Namespace; Test: Model };
const versions = buildVersionProjections(runner.program, MyService);
Expand Down Expand Up @@ -144,6 +153,8 @@ describe("versioning: reference versioned library", () => {
v2
}
@test model Test extends VersionedLib.Foo {}
@test op test1 is VersionedLib.Operation<{name: string}, int32>;
alias test2 = VersionedLib.Operation<{name: string}, int32>;
}
`)) as { MyService: Namespace; Test: Model };
const versions = buildVersionProjections(runner.program, MyService);
Expand Down Expand Up @@ -200,7 +211,7 @@ describe("versioning: reference versioned library", () => {
});

describe("when using versioned library without @useDependency", () => {
it("emit diagnostic when used in extends", async () => {
it("emit diagnostic when model uses extends", async () => {
const diagnostics = await runner.diagnose(`
namespace MyService {
model Test extends VersionedLib.Foo {}
Expand All @@ -213,6 +224,60 @@ describe("versioning: reference versioned library", () => {
});
});

it("emit diagnostic when model uses is", async () => {
const diagnostics = await runner.diagnose(`
namespace MyService {
model Test is VersionedLib.Foo {}
}
`);
expectDiagnostics(diagnostics, {
code: "@typespec/versioning/using-versioned-library",
message:
"Namespace 'MyService' is referencing types from versioned namespace 'VersionedLib' but didn't specify which versions with @useDependency.",
});
});

it("emit diagnostic when model uses alias", async () => {
const diagnostics = await runner.diagnose(`
namespace MyService {
alias Test = VersionedLib.Foo;
op test(): Test;
}
`);
expectDiagnostics(diagnostics, {
code: "@typespec/versioning/using-versioned-library",
message:
"Namespace 'MyService' is referencing types from versioned namespace 'VersionedLib' but didn't specify which versions with @useDependency.",
});
});

it("emit diagnostic when operation uses is", async () => {
const diagnostics = await runner.diagnose(`
namespace MyService {
op test is VersionedLib.Operation<{name: string}, int32>;
}
`);
expectDiagnostics(diagnostics, {
code: "@typespec/versioning/using-versioned-library",
message:
"Namespace 'MyService' is referencing types from versioned namespace 'VersionedLib' but didn't specify which versions with @useDependency.",
});
});

it("emit diagnostic when operation uses alias", async () => {
const diagnostics = await runner.diagnose(`
namespace MyService {
alias test = VersionedLib.Operation<{name: string}, int32>;
op myTest is test;
}
`);
expectDiagnostics(diagnostics, {
code: "@typespec/versioning/using-versioned-library",
message:
"Namespace 'MyService' is referencing types from versioned namespace 'VersionedLib' but didn't specify which versions with @useDependency.",
});
});

it("emit diagnostic when used in properties", async () => {
const diagnostics = await runner.diagnose(`
namespace MyService {
Expand Down