From 69016c14fe8d9f02f8b34259adf8278b0d20ce3a Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Wed, 15 May 2024 08:37:29 -0700 Subject: [PATCH 1/2] Fix: stop omiting non version enum --- packages/typespec-autorest/src/openapi.ts | 4 ++-- packages/typespec-autorest/test/options.test.ts | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/typespec-autorest/src/openapi.ts b/packages/typespec-autorest/src/openapi.ts index 2b26ea52cd..b46c0a83f7 100644 --- a/packages/typespec-autorest/src/openapi.ts +++ b/packages/typespec-autorest/src/openapi.ts @@ -1243,8 +1243,8 @@ export async function getOpenAPIForService( } function isVersionEnum(program: Program, enumObj: Enum): boolean { - const versions = getVersionsForEnum(program, enumObj); - if (versions !== undefined && versions.length > 0) { + const [_, map] = getVersionsForEnum(program, enumObj); + if (map !== undefined && map.getVersions()[0].enumMember.enum === enumObj) { return true; } return false; diff --git a/packages/typespec-autorest/test/options.test.ts b/packages/typespec-autorest/test/options.test.ts index 6d9e25f0d2..8e9d23bb14 100644 --- a/packages/typespec-autorest/test/options.test.ts +++ b/packages/typespec-autorest/test/options.test.ts @@ -245,6 +245,19 @@ op test(): void; }); deepStrictEqual(Object.keys(output.definitions!), ["NotReferenced", "Versions"]); }); + + it("doesn't omit other enums", async () => { + const output = await openapiWithOptions( + `@service + @versioned(Versions) + namespace My { + enum Versions {v1, v2} + enum NotReferenced {a, b} + }`, + {} + ); + deepStrictEqual(Object.keys(output.definitions!), ["NotReferenced"]); + }); }); describe("include-x-typespec-name", () => { From f8d463df78a7f0f947aecae3a544536399e23d04 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Wed, 15 May 2024 08:39:20 -0700 Subject: [PATCH 2/2] Changelog --- .../fix-omitted-non-version-enums-2024-4-15-8-39-12.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .chronus/changes/fix-omitted-non-version-enums-2024-4-15-8-39-12.md diff --git a/.chronus/changes/fix-omitted-non-version-enums-2024-4-15-8-39-12.md b/.chronus/changes/fix-omitted-non-version-enums-2024-4-15-8-39-12.md new file mode 100644 index 0000000000..0693e0063e --- /dev/null +++ b/.chronus/changes/fix-omitted-non-version-enums-2024-4-15-8-39-12.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@azure-tools/typespec-autorest" +--- + +Do not omit unreferenced non version enum when `omit-unreachable-types` is not set to true \ No newline at end of file