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
10 changes: 1 addition & 9 deletions src/codegen/generators/typescript/channels/asyncapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -92,11 +89,6 @@ export async function generateTypeScriptChannelsForAsyncAPI(
>,
protocolDependencies: Record<string, string[]>
): Promise<void> {
// 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()
Expand Down
13 changes: 2 additions & 11 deletions src/codegen/generators/typescript/channels/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
} from './types';
import {ConstrainedObjectModel} from '@asyncapi/modelina';
import {collectProtocolDependencies} from './utils';
import {resetHttpCommonTypesState} from './protocols/http';
import {
renderHttpFetchClient,
renderHttpCommonTypes
Expand Down Expand Up @@ -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.
Expand All @@ -76,10 +72,6 @@ export async function generateTypeScriptChannelsForOpenAPI(
return;
}

// Reset HTTP common types state
resetHttpCommonTypesState();
httpCommonTypesGenerated = false;

const {openapiDocument} = validateOpenAPIContext(context);

// Collect dependencies
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand Down