Skip to content

Commit 07b340a

Browse files
Fix: @path property should be included in unreachable models (#3218)
fix #3217
1 parent fe51f05 commit 07b340a

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
3+
changeKind: fix
4+
packages:
5+
- "@typespec/openapi3"
6+
---
7+
8+
Fix: `@path` property should be included in unreachable models
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
3+
changeKind: fix
4+
packages:
5+
- "@typespec/http"
6+
---
7+
8+
Fix: `@path` property shouldn't be applicableMetadata if the visibility contain `Read`

packages/http/src/metadata.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ function isApplicableMetadataCore(
356356
return false;
357357
}
358358

359-
if (visibility === Visibility.Read) {
359+
if (visibility & Visibility.Read) {
360360
return isHeader(program, property) || isStatusCode(program, property);
361361
}
362362

@@ -538,6 +538,7 @@ export function createMetadataInfo(program: Program, options?: MetadataInfoOptio
538538
if (isOptional(property, canonicalVisibility) !== isOptional(property, visibility)) {
539539
return true;
540540
}
541+
541542
return (
542543
isPayloadProperty(property, visibility, undefined, /* keep shared */ true) !==
543544
isPayloadProperty(property, canonicalVisibility, undefined, /*keep shared*/ true)

packages/openapi3/test/metadata.test.ts

+45
Original file line numberDiff line numberDiff line change
@@ -1170,4 +1170,49 @@ describe("openapi3: metadata", () => {
11701170
"WidgetCreate",
11711171
]);
11721172
});
1173+
1174+
it("unreachable models include @path properties", async () => {
1175+
const res = await openApiFor(`
1176+
model Unreachable {
1177+
@path name: string;
1178+
}
1179+
`);
1180+
1181+
deepStrictEqual(res.components.schemas.Unreachable, {
1182+
type: "object",
1183+
properties: {
1184+
name: {
1185+
type: "string",
1186+
},
1187+
},
1188+
required: ["name"],
1189+
});
1190+
});
1191+
1192+
it("inheritance tree unreachable with @path doesn't get conflicts", async () => {
1193+
const res = await openApiFor(`
1194+
model Base {
1195+
}
1196+
1197+
model Child extends Base {
1198+
@path name: string;
1199+
}
1200+
`);
1201+
1202+
deepStrictEqual(Object.keys(res.components.schemas), ["Base", "Child"]);
1203+
deepStrictEqual(res.components.schemas.Child, {
1204+
type: "object",
1205+
allOf: [
1206+
{
1207+
$ref: "#/components/schemas/Base",
1208+
},
1209+
],
1210+
properties: {
1211+
name: {
1212+
type: "string",
1213+
},
1214+
},
1215+
required: ["name"],
1216+
});
1217+
});
11731218
});

0 commit comments

Comments
 (0)