Skip to content
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
Expand Up @@ -17,6 +17,7 @@ export function renderHttpFetchClient({
replyMessageType,
replyMessageModule,
channelParameters,
channelHeaders,
method,
servers = [],
subName = pascalCase(requestTopic),
Expand All @@ -43,7 +44,8 @@ export function renderHttpFetchClient({
const contextInterface = generateContextInterface(
contextInterfaceName,
messageType,
hasParameters,
channelParameters?.type,
channelHeaders?.type,
method
);

Expand Down Expand Up @@ -92,7 +94,8 @@ ${functionCode}`;
function generateContextInterface(
interfaceName: string,
messageType: string | undefined,
hasParameters: boolean,
parametersType: string | undefined,
headersType: string | undefined,
method: string
): string {
const fields: string[] = [];
Expand All @@ -102,16 +105,19 @@ function generateContextInterface(
fields.push(` payload: ${messageType};`);
}

// Add parameters field if operation has path parameters
if (hasParameters) {
fields.push(
` parameters: { getChannelWithParameters: (path: string) => string };`
);
// Reference the concrete generated parameter class so consumers get typed
// query/path parameters. It still exposes getChannelWithParameters, so the
// buildUrlWithParameters call in the function body keeps working.
if (parametersType) {
fields.push(` parameters: ${parametersType};`);
}

// Add requestHeaders field (optional) for operations that support typed headers
// This is always optional since headers can also be passed via additionalHeaders
fields.push(` requestHeaders?: { marshal: () => string };`);
// Reference the concrete generated headers model when available; fall back to
// the structural marshal contract otherwise. Always optional since headers can
// also be passed via additionalHeaders.
fields.push(
` requestHeaders?: ${headersType ?? '{ marshal: () => string }'};`
);

const fieldsStr = fields.length > 0 ? `\n${fields.join('\n')}\n` : '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function generateForOperations(
parameters: ConstrainedObjectModel | undefined
): HttpRenderType[] {
const renders: HttpRenderType[] = [];
const {generator, payloads} = context;
const {generator, payloads, headers} = context;
const functionTypeMapping = generator.functionTypeMapping?.[channel.id()];

for (const operation of channel.operations().all()) {
Expand Down Expand Up @@ -138,6 +138,7 @@ function generateForOperations(
method: httpMethod.toUpperCase(),
channelParameters:
parameters !== undefined ? parameters : undefined,
channelHeaders: headers,
includesStatusCodes: replyIncludesStatusCodes,
description,
deprecated
Expand Down
1 change: 1 addition & 0 deletions src/codegen/generators/typescript/channels/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ export interface RenderHttpParameters {
replyMessageType: string;
replyMessageModule: string | undefined;
channelParameters: ConstrainedObjectModel | undefined;
channelHeaders?: ConstrainedObjectModel | undefined;
subName?: string;
functionName?: string;
method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ async function updatePet(context: UpdatePetContext): Promise<HttpClientResponse<
}

export interface FindPetsByStatusAndCategoryContext extends HttpClientContext {
parameters: { getChannelWithParameters: (path: string) => string };
parameters: Parameter;
requestHeaders?: { marshal: () => string };
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2003,8 +2003,8 @@ async function getMultiStatusResponse(context: GetMultiStatusResponseContext = {
}

export interface GetGetUserItemContext extends HttpClientContext {
parameters: { getChannelWithParameters: (path: string) => string };
requestHeaders?: { marshal: () => string };
parameters: UserItemsParameters;
requestHeaders?: ItemRequestHeaders;
}

/**
Expand Down Expand Up @@ -2127,8 +2127,8 @@ async function getGetUserItem(context: GetGetUserItemContext): Promise<HttpClien

export interface PutUpdateUserItemContext extends HttpClientContext {
payload: ItemRequest;
parameters: { getChannelWithParameters: (path: string) => string };
requestHeaders?: { marshal: () => string };
parameters: UserItemsParameters;
requestHeaders?: ItemRequestHeaders;
}

/**
Expand Down
Loading