Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: @path property should be included in unreachable models #3218

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"],
});
});
});
Loading