From 33c546a95bf4b7360d2692dc61231d769e60c692 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Tue, 23 Apr 2024 12:49:34 -0700 Subject: [PATCH 1/4] Fix: `@path` property should be included in unreacahble models --- packages/http/src/metadata.ts | 3 +- packages/openapi3/src/openapi.ts | 1 + packages/openapi3/test/metadata.test.ts | 45 +++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) 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/src/openapi.ts b/packages/openapi3/src/openapi.ts index 20e1355bcd..96a833f95d 100644 --- a/packages/openapi3/src/openapi.ts +++ b/packages/openapi3/src/openapi.ts @@ -1473,6 +1473,7 @@ function createOAPIEmitter( !paramModels.has(type) && !shouldInline(program, type) ) { + console.log("Process schemas", (type as any).name); callSchemaEmitter(type, Visibility.All); } }; 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"], + }); + }); }); From 68abe6876766fa1b6acf2f7596c336ac93af0cf8 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Tue, 23 Apr 2024 12:56:52 -0700 Subject: [PATCH 2/4] Create fix-unrechable-models-path-2024-3-23-19-55-13.md --- .../fix-unrechable-models-path-2024-3-23-19-55-13.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .chronus/changes/fix-unrechable-models-path-2024-3-23-19-55-13.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 From 0143de58ba841ea640c08bfa08c8558b63bb4a84 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Tue, 23 Apr 2024 12:57:31 -0700 Subject: [PATCH 3/4] Create fix-unrechable-models-path-2024-3-23-19-55-14.md --- .../fix-unrechable-models-path-2024-3-23-19-55-14.md | 8 ++++++++ 1 file changed, 8 insertions(+) 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-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` From 1f09fa39d60500bd3519d93b06b9ffa352d3a08d Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Tue, 23 Apr 2024 15:39:46 -0700 Subject: [PATCH 4/4] . --- packages/openapi3/src/openapi.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/openapi3/src/openapi.ts b/packages/openapi3/src/openapi.ts index 96a833f95d..20e1355bcd 100644 --- a/packages/openapi3/src/openapi.ts +++ b/packages/openapi3/src/openapi.ts @@ -1473,7 +1473,6 @@ function createOAPIEmitter( !paramModels.has(type) && !shouldInline(program, type) ) { - console.log("Process schemas", (type as any).name); callSchemaEmitter(type, Visibility.All); } };