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
2 changes: 1 addition & 1 deletion src/codegen/generators/typescript/channels/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export async function generateTypeScriptChannelsForOpenAPI(
functionName: r.functionName,
messageType: r.messageType ?? '',
replyType: r.replyType,
parameterType: undefined
parameterType: r.parameterType
}))
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ ${functionCode}`;
code,
functionName,
dependencies: [],
functionType: ChannelFunctionTypes.HTTP_CLIENT
functionType: ChannelFunctionTypes.HTTP_CLIENT,
parameterType: channelParameters?.name
};
}

Expand Down
4 changes: 4 additions & 0 deletions src/codegen/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ export interface HttpRenderType {
functionType: ChannelFunctionTypes;
messageType?: string;
replyType: string;
// Name of the generated path-parameter model, when the operation declares
// path parameters. Consumers (e.g. README generation) rely on this to know an
// operation requires a `parameters` argument.
parameterType?: string;
}

const SCHEMA_DESCRIPTION =
Expand Down
16 changes: 16 additions & 0 deletions test/codegen/generators/typescript/channels.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,22 @@ describe('channels', () => {
const httpProtocolCode = generatedChannels.protocolFiles['http_client'];
expect(httpProtocolCode).toContain('unmarshal(JSON.stringify(rawData))');
expect(httpProtocolCode).not.toMatch(/unmarshal\(rawData\)/);

// Operations with path parameters must expose their parameter model name via
// parameterType so downstream consumers (e.g. README generation) know the
// operation requires a `parameters` argument. Operations without parameters
// must leave it undefined. Regression guard for the previously hardcoded
// `parameterType: undefined`.
const httpFunctions = generatedChannels.renderedFunctions['http_client'];
const withParameters = httpFunctions.find(
(fn) => fn.functionName === 'findPetsByStatusAndCategory'
);
expect(withParameters?.parameterType).toBe('FindPetsByStatusAndCategoryParameters');
const withoutParameters = httpFunctions.find(
(fn) => fn.functionName !== 'findPetsByStatusAndCategory'
);
expect(withoutParameters).toBeDefined();
expect(withoutParameters?.parameterType).toBeUndefined();
});

it('should skip generation when http_client is not in protocols', async () => {
Expand Down
Loading