diff --git a/src/codegen/generators/typescript/channels/openapi.ts b/src/codegen/generators/typescript/channels/openapi.ts index a1d850f1..0957fc5f 100644 --- a/src/codegen/generators/typescript/channels/openapi.ts +++ b/src/codegen/generators/typescript/channels/openapi.ts @@ -124,7 +124,7 @@ export async function generateTypeScriptChannelsForOpenAPI( functionName: r.functionName, messageType: r.messageType ?? '', replyType: r.replyType, - parameterType: undefined + parameterType: r.parameterType })) ); diff --git a/src/codegen/generators/typescript/channels/protocols/http/client.ts b/src/codegen/generators/typescript/channels/protocols/http/client.ts index b394ac34..57357485 100644 --- a/src/codegen/generators/typescript/channels/protocols/http/client.ts +++ b/src/codegen/generators/typescript/channels/protocols/http/client.ts @@ -81,7 +81,8 @@ ${functionCode}`; code, functionName, dependencies: [], - functionType: ChannelFunctionTypes.HTTP_CLIENT + functionType: ChannelFunctionTypes.HTTP_CLIENT, + parameterType: channelParameters?.name }; } diff --git a/src/codegen/types.ts b/src/codegen/types.ts index f10a3cf3..c6b9c437 100644 --- a/src/codegen/types.ts +++ b/src/codegen/types.ts @@ -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 = diff --git a/test/codegen/generators/typescript/channels.spec.ts b/test/codegen/generators/typescript/channels.spec.ts index 864dd955..d116f304 100644 --- a/test/codegen/generators/typescript/channels.spec.ts +++ b/test/codegen/generators/typescript/channels.spec.ts @@ -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 () => {