From 4c34e787477d3ab3b75ad14a6d03911341a07305 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Mon, 25 Mar 2024 11:56:55 -0700 Subject: [PATCH] Fix visibility conflict with base models (#3049) fix #2922 fix #3048(dup) --- ...-conflict-base-model-2024-2-25-15-48-50.md | 8 +++++++ packages/openapi3/src/visibility-usage.ts | 3 +++ packages/openapi3/test/metadata.test.ts | 23 +++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 .chronus/changes/fix-visibility-conflict-base-model-2024-2-25-15-48-50.md diff --git a/.chronus/changes/fix-visibility-conflict-base-model-2024-2-25-15-48-50.md b/.chronus/changes/fix-visibility-conflict-base-model-2024-2-25-15-48-50.md new file mode 100644 index 0000000000..a0599d1e68 --- /dev/null +++ b/.chronus/changes/fix-visibility-conflict-base-model-2024-2-25-15-48-50.md @@ -0,0 +1,8 @@ +--- +# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking +changeKind: fix +packages: + - "@typespec/openapi3" +--- + +Fix visibility naming conflict when a model used with `extends` was used in different visibility. diff --git a/packages/openapi3/src/visibility-usage.ts b/packages/openapi3/src/visibility-usage.ts index 3826d7a4a4..4cfe40ceba 100644 --- a/packages/openapi3/src/visibility-usage.ts +++ b/packages/openapi3/src/visibility-usage.ts @@ -171,6 +171,9 @@ function navigateReferencedTypes( case "Model": callback(type, usage); navigateIterable(type.properties, usage, callback, visited); + if (type.baseModel) { + navigateReferencedTypes(type.baseModel, usage, callback, visited); + } navigateIterable(type.derivedModels, usage, callback, visited); if (type.indexer) { if (type.indexer.key.name === "integer") { diff --git a/packages/openapi3/test/metadata.test.ts b/packages/openapi3/test/metadata.test.ts index 68e592ec15..87bf9ea39e 100644 --- a/packages/openapi3/test/metadata.test.ts +++ b/packages/openapi3/test/metadata.test.ts @@ -1130,4 +1130,27 @@ describe("openapi3: metadata", () => { }, }); }); + + it("base models used in different visibility gets distinct names", async () => { + const res = await openApiFor(` + model Widget { + @visibility("read", "update") + @path + id: string; + + weight: int32; + } + + model CreatedWidget extends Widget {} + + @post op create(widget: Widget): CreatedWidget; + `); + + deepStrictEqual(Object.keys(res.components.schemas), [ + "CreatedWidget", + "CreatedWidgetCreate", + "Widget", + "WidgetCreate", + ]); + }); });