Skip to content

Commit

Permalink
(fix, docs): ir to fdr converter sends global headers (#4170)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi authored Jul 31, 2024
1 parent f781f49 commit 69bebff
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion packages/cli/register/src/ir-to-fdr-converter/convertPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,28 @@ function convertHttpEndpointExample({
irEndpoint: Ir.http.HttpEndpoint;
ir: Ir.ir.IntermediateRepresentation;
}): WithoutQuestionMarks<APIV1Write.ExampleEndpointCall> {
const requiredGlobalHeaders: Ir.ExampleHeader[] = ir.headers
.map((header) => {
const value =
header.valueType.type === "container" && header.valueType.container.type === "literal"
? header.valueType.container.literal._visit<string | undefined>({
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 {
Expand All @@ -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;
Expand Down

0 comments on commit 69bebff

Please sign in to comment.