diff --git a/src/codegen/generators/typescript/channels/asyncapi.ts b/src/codegen/generators/typescript/channels/asyncapi.ts index 2f35167..4e87c52 100644 --- a/src/codegen/generators/typescript/channels/asyncapi.ts +++ b/src/codegen/generators/typescript/channels/asyncapi.ts @@ -23,10 +23,7 @@ import {generateKafkaChannels} from './protocols/kafka'; import {generateMqttChannels} from './protocols/mqtt'; import {generateAmqpChannels} from './protocols/amqp'; import {generateEventSourceChannels} from './protocols/eventsource'; -import { - generatehttpChannels, - resetHttpCommonTypesState -} from './protocols/http'; +import {generatehttpChannels} from './protocols/http'; import {generateWebSocketChannels} from './protocols/websocket'; import { createMissingInputDocumentError, @@ -92,11 +89,6 @@ export async function generateTypeScriptChannelsForAsyncAPI( >, protocolDependencies: Record ): Promise { - // Reset protocol-specific state at the start of each generation cycle - if (protocolsToUse.includes('http_client')) { - resetHttpCommonTypesState(); - } - const {asyncapiDocument} = validateAsyncapiContext(context); const channels = asyncapiDocument! .allChannels() diff --git a/src/codegen/generators/typescript/channels/openapi.ts b/src/codegen/generators/typescript/channels/openapi.ts index a8413ad..3ea2d90 100644 --- a/src/codegen/generators/typescript/channels/openapi.ts +++ b/src/codegen/generators/typescript/channels/openapi.ts @@ -13,7 +13,6 @@ import { } from './types'; import {ConstrainedObjectModel} from '@asyncapi/modelina'; import {collectProtocolDependencies} from './utils'; -import {resetHttpCommonTypesState} from './protocols/http'; import { renderHttpFetchClient, renderHttpCommonTypes @@ -51,9 +50,6 @@ const HTTP_METHODS: HttpMethod[] = [ ]; const METHODS_WITH_BODY: HttpMethod[] = ['post', 'put', 'patch']; -// Track whether common types have been generated -let httpCommonTypesGenerated = false; - /** * Generates TypeScript HTTP client channels from an OpenAPI document. * Only supports http_client protocol - other protocols are ignored for OpenAPI input. @@ -76,10 +72,6 @@ export async function generateTypeScriptChannelsForOpenAPI( return; } - // Reset HTTP common types state - resetHttpCommonTypesState(); - httpCommonTypesGenerated = false; - const {openapiDocument} = validateOpenAPIContext(context); // Collect dependencies @@ -93,11 +85,10 @@ export async function generateTypeScriptChannelsForOpenAPI( parameters ); - // Generate common types once - if (!httpCommonTypesGenerated && renders.length > 0) { + // Generate common types once (stateless check) + if (protocolCodeFunctions['http_client'].length === 0 && renders.length > 0) { const commonTypesCode = renderHttpCommonTypes(); protocolCodeFunctions['http_client'].unshift(commonTypesCode); - httpCommonTypesGenerated = true; } // Add renders to output diff --git a/src/codegen/generators/typescript/channels/protocols/http/index.ts b/src/codegen/generators/typescript/channels/protocols/http/index.ts index e15aad1..a90d5ed 100644 --- a/src/codegen/generators/typescript/channels/protocols/http/index.ts +++ b/src/codegen/generators/typescript/channels/protocols/http/index.ts @@ -21,17 +21,6 @@ import {renderHttpFetchClient, renderHttpCommonTypes} from './fetch'; export {renderHttpFetchClient, renderHttpCommonTypes}; -// Track whether common types have been generated for this protocol -let httpCommonTypesGenerated = false; - -/** - * Reset the common types generation state. - * Called at the start of each generation cycle. - */ -export function resetHttpCommonTypesState(): void { - httpCommonTypesGenerated = false; -} - export async function generatehttpChannels( context: TypeScriptChannelsGeneratorContext, channel: ChannelInterface, @@ -50,12 +39,11 @@ export async function generatehttpChannels( renders = generateForOperations(context, channel, topic, parameter); } - // Generate common types once for the HTTP protocol - if (!httpCommonTypesGenerated && renders.length > 0) { + // Generate common types once for the HTTP protocol (stateless check) + if (protocolCodeFunctions['http_client'].length === 0 && renders.length > 0) { const commonTypesCode = renderHttpCommonTypes(); // Prepend common types to the beginning of the protocol code protocolCodeFunctions['http_client'].unshift(commonTypesCode); - httpCommonTypesGenerated = true; } addRendersToExternal(