Skip to content

Commit

Permalink
Fix visibility conflict with base models (#3049)
Browse files Browse the repository at this point in the history
fix #2922
fix #3048(dup)
  • Loading branch information
timotheeguerin authored Mar 25, 2024
1 parent 095c7dd commit 4c34e78
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions packages/openapi3/src/visibility-usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
23 changes: 23 additions & 0 deletions packages/openapi3/test/metadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]);
});
});

0 comments on commit 4c34e78

Please sign in to comment.