Skip to content

Commit

Permalink
Fix: @path property should be included in unreachable models (#3218)
Browse files Browse the repository at this point in the history
fix #3217
  • Loading branch information
timotheeguerin committed Apr 23, 2024
1 parent fe51f05 commit 07b340a
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
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: `@path` property should be included in unreachable models
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/http"
---

Fix: `@path` property shouldn't be applicableMetadata if the visibility contain `Read`
3 changes: 2 additions & 1 deletion packages/http/src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ function isApplicableMetadataCore(
return false;
}

if (visibility === Visibility.Read) {
if (visibility & Visibility.Read) {
return isHeader(program, property) || isStatusCode(program, property);
}

Expand Down Expand Up @@ -538,6 +538,7 @@ export function createMetadataInfo(program: Program, options?: MetadataInfoOptio
if (isOptional(property, canonicalVisibility) !== isOptional(property, visibility)) {
return true;
}

return (
isPayloadProperty(property, visibility, undefined, /* keep shared */ true) !==
isPayloadProperty(property, canonicalVisibility, undefined, /*keep shared*/ true)
Expand Down
45 changes: 45 additions & 0 deletions packages/openapi3/test/metadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1170,4 +1170,49 @@ describe("openapi3: metadata", () => {
"WidgetCreate",
]);
});

it("unreachable models include @path properties", async () => {
const res = await openApiFor(`
model Unreachable {
@path name: string;
}
`);

deepStrictEqual(res.components.schemas.Unreachable, {
type: "object",
properties: {
name: {
type: "string",
},
},
required: ["name"],
});
});

it("inheritance tree unreachable with @path doesn't get conflicts", async () => {
const res = await openApiFor(`
model Base {
}
model Child extends Base {
@path name: string;
}
`);

deepStrictEqual(Object.keys(res.components.schemas), ["Base", "Child"]);
deepStrictEqual(res.components.schemas.Child, {
type: "object",
allOf: [
{
$ref: "#/components/schemas/Base",
},
],
properties: {
name: {
type: "string",
},
},
required: ["name"],
});
});
});

0 comments on commit 07b340a

Please sign in to comment.