From 69bebff23f3ff9c04402086c01f5884e0311a19a Mon Sep 17 00:00:00 2001 From: Deep Singhvi Date: Wed, 31 Jul 2024 18:35:20 -0400 Subject: [PATCH] (fix, docs): ir to fdr converter sends global headers (#4170) --- .../src/ir-to-fdr-converter/convertPackage.ts | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/cli/register/src/ir-to-fdr-converter/convertPackage.ts b/packages/cli/register/src/ir-to-fdr-converter/convertPackage.ts index 7c7bd900a75..7e92d89fdab 100644 --- a/packages/cli/register/src/ir-to-fdr-converter/convertPackage.ts +++ b/packages/cli/register/src/ir-to-fdr-converter/convertPackage.ts @@ -544,6 +544,28 @@ function convertHttpEndpointExample({ irEndpoint: Ir.http.HttpEndpoint; ir: Ir.ir.IntermediateRepresentation; }): WithoutQuestionMarks { + const requiredGlobalHeaders: Ir.ExampleHeader[] = ir.headers + .map((header) => { + const value = + header.valueType.type === "container" && header.valueType.container.type === "literal" + ? header.valueType.container.literal._visit({ + boolean: (val) => `${val}`, + string: (val) => val, + _other: () => undefined + }) + : undefined; + if (value != null) { + return { + name: header.name, + value: { + jsonExample: value, + shape: Ir.ExampleTypeReferenceShape.primitive(Ir.ExamplePrimitive.string({ original: value })) + } + }; + } + return undefined; + }) + .filter(isNonNullish); const example = userSpecifiedExample.example ?? autogeneratedExample.example; const { codeSamples } = userSpecifiedExample; return { @@ -563,7 +585,7 @@ function convertHttpEndpointExample({ }, {} ), - headers: [...example.serviceHeaders, ...example.endpointHeaders].reduce< + headers: [...requiredGlobalHeaders, ...example.serviceHeaders, ...example.endpointHeaders].reduce< APIV1Write.ExampleEndpointCall["headers"] >((headers, irHeaderExample) => { headers[irHeaderExample.name.wireValue] = irHeaderExample.value.jsonExample;