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 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", () => {