From 07b340a6dc29fbab971693f8de59538386c2a47e Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Tue, 23 Apr 2024 16:02:04 -0700 Subject: [PATCH] Fix: `@path` property should be included in unreachable models (#3218) fix #3217 --- ...rechable-models-path-2024-3-23-19-55-13.md | 8 ++++ ...rechable-models-path-2024-3-23-19-55-14.md | 8 ++++ packages/http/src/metadata.ts | 3 +- packages/openapi3/test/metadata.test.ts | 45 +++++++++++++++++++ 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 .chronus/changes/fix-unrechable-models-path-2024-3-23-19-55-13.md create mode 100644 .chronus/changes/fix-unrechable-models-path-2024-3-23-19-55-14.md diff --git a/.chronus/changes/fix-unrechable-models-path-2024-3-23-19-55-13.md b/.chronus/changes/fix-unrechable-models-path-2024-3-23-19-55-13.md new file mode 100644 index 0000000000..5bdd9caa5a --- /dev/null +++ b/.chronus/changes/fix-unrechable-models-path-2024-3-23-19-55-13.md @@ -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 diff --git a/.chronus/changes/fix-unrechable-models-path-2024-3-23-19-55-14.md b/.chronus/changes/fix-unrechable-models-path-2024-3-23-19-55-14.md new file mode 100644 index 0000000000..465ea26759 --- /dev/null +++ b/.chronus/changes/fix-unrechable-models-path-2024-3-23-19-55-14.md @@ -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` diff --git a/packages/http/src/metadata.ts b/packages/http/src/metadata.ts index 2732016353..5e2c0ad4c0 100644 --- a/packages/http/src/metadata.ts +++ b/packages/http/src/metadata.ts @@ -356,7 +356,7 @@ function isApplicableMetadataCore( return false; } - if (visibility === Visibility.Read) { + if (visibility & Visibility.Read) { return isHeader(program, property) || isStatusCode(program, property); } @@ -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) diff --git a/packages/openapi3/test/metadata.test.ts b/packages/openapi3/test/metadata.test.ts index 3a0bbdd85e..bb76b033a4 100644 --- a/packages/openapi3/test/metadata.test.ts +++ b/packages/openapi3/test/metadata.test.ts @@ -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"], + }); + }); });