Fixes versioning when using versioned named union variants (#4408)
Example of bug: [playground](https://typespec.io/playground?c=aW1wb3J0ICJAdHlwZXNwZWMvaHR0cCI7CtIZcmVzdNUZdmVyc2lvbmluZyI7Cgp1c2luZyBUeXBlU3BlYy5WyR070BtIdHRw0RVSZXN0OwoKQMdVZWQox0JzKQpAc2VydmljZSh7CiAgdGl0bGU6ICJXaWRnZXQgU8YbIiwKfSkKbmFtZXNwYWNlIERlbW%2FHGzsKCmVudW0gyFAgxEZ2MSzEBjIsCn0KCnVuaW9uIEZvb0NvbnRlbnTFInN0cmluZywKCiAgQGFkZOsAkS52MikKIMQwOsQFW13FRdQlbW9kZWzEJMVS5AE5OsdYO9UzMcgzQ2hhdFJlcXVlc%2BYAjWPmAJnFcOcApTsKICDkAPA%2FzVNhbGlhcyBPdGhlclXlANY9xx4gfMQ8W107Cg%3D%3D&e=%40typespec%2Fopenapi3&options=%7B%7D) --------- Co-authored-by: Christopher Radek <Christopher.Radek@microsoft.com>
This commit is contained in:
Родитель
7d444a4331
Коммит
32a118dbf6
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
changeKind: fix
|
||||
packages:
|
||||
- "@typespec/versioning"
|
||||
---
|
||||
|
||||
Fixes versioning when using versioned named union variants
|
|
@ -533,8 +533,10 @@ function validateReference(program: Program, source: Type | Type[], target: Type
|
|||
|
||||
switch (target.kind) {
|
||||
case "Union":
|
||||
for (const variant of target.variants.values()) {
|
||||
validateReference(program, source, variant.type);
|
||||
if (typeof target.name !== "string") {
|
||||
for (const variant of target.variants.values()) {
|
||||
validateReference(program, source, variant.type);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "Tuple":
|
||||
|
|
|
@ -680,6 +680,31 @@ describe("versioning: logic", () => {
|
|||
strictEqual((v6 as any as IntrinsicType).name, "never");
|
||||
});
|
||||
|
||||
it("does not emit diagnostic when using named versioned union variant in incompatible versioned source", async () => {
|
||||
const diagnostics = await runner.diagnose(`
|
||||
@versioned(Versions)
|
||||
namespace TestService {
|
||||
enum Versions {v1, v2}
|
||||
|
||||
@added(Versions.v2)
|
||||
model Versioned {}
|
||||
|
||||
union NamedUnion {
|
||||
string;
|
||||
|
||||
@added(Versions.v2)
|
||||
Versioned;
|
||||
}
|
||||
|
||||
@added(Versions.v1)
|
||||
model Foo {
|
||||
content: NamedUnion;
|
||||
}
|
||||
}
|
||||
`);
|
||||
expectDiagnosticEmpty(diagnostics);
|
||||
});
|
||||
|
||||
async function versionedUnion(versions: string[], union: string) {
|
||||
const { Test } = (await runner.compile(`
|
||||
@versioned(Versions)
|
||||
|
|
Загрузка…
Ссылка в новой задаче