Skip to content

Commit 0b56ee5

Browse files
authored
fix: global http state (#318)
1 parent a83bb7c commit 0b56ee5

3 files changed

Lines changed: 5 additions & 34 deletions

File tree

src/codegen/generators/typescript/channels/asyncapi.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ import {generateKafkaChannels} from './protocols/kafka';
2323
import {generateMqttChannels} from './protocols/mqtt';
2424
import {generateAmqpChannels} from './protocols/amqp';
2525
import {generateEventSourceChannels} from './protocols/eventsource';
26-
import {
27-
generatehttpChannels,
28-
resetHttpCommonTypesState
29-
} from './protocols/http';
26+
import {generatehttpChannels} from './protocols/http';
3027
import {generateWebSocketChannels} from './protocols/websocket';
3128
import {
3229
createMissingInputDocumentError,
@@ -92,11 +89,6 @@ export async function generateTypeScriptChannelsForAsyncAPI(
9289
>,
9390
protocolDependencies: Record<string, string[]>
9491
): Promise<void> {
95-
// Reset protocol-specific state at the start of each generation cycle
96-
if (protocolsToUse.includes('http_client')) {
97-
resetHttpCommonTypesState();
98-
}
99-
10092
const {asyncapiDocument} = validateAsyncapiContext(context);
10193
const channels = asyncapiDocument!
10294
.allChannels()

src/codegen/generators/typescript/channels/openapi.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
} from './types';
1414
import {ConstrainedObjectModel} from '@asyncapi/modelina';
1515
import {collectProtocolDependencies} from './utils';
16-
import {resetHttpCommonTypesState} from './protocols/http';
1716
import {
1817
renderHttpFetchClient,
1918
renderHttpCommonTypes
@@ -51,9 +50,6 @@ const HTTP_METHODS: HttpMethod[] = [
5150
];
5251
const METHODS_WITH_BODY: HttpMethod[] = ['post', 'put', 'patch'];
5352

54-
// Track whether common types have been generated
55-
let httpCommonTypesGenerated = false;
56-
5753
/**
5854
* Generates TypeScript HTTP client channels from an OpenAPI document.
5955
* Only supports http_client protocol - other protocols are ignored for OpenAPI input.
@@ -76,10 +72,6 @@ export async function generateTypeScriptChannelsForOpenAPI(
7672
return;
7773
}
7874

79-
// Reset HTTP common types state
80-
resetHttpCommonTypesState();
81-
httpCommonTypesGenerated = false;
82-
8375
const {openapiDocument} = validateOpenAPIContext(context);
8476

8577
// Collect dependencies
@@ -93,11 +85,10 @@ export async function generateTypeScriptChannelsForOpenAPI(
9385
parameters
9486
);
9587

96-
// Generate common types once
97-
if (!httpCommonTypesGenerated && renders.length > 0) {
88+
// Generate common types once (stateless check)
89+
if (protocolCodeFunctions['http_client'].length === 0 && renders.length > 0) {
9890
const commonTypesCode = renderHttpCommonTypes();
9991
protocolCodeFunctions['http_client'].unshift(commonTypesCode);
100-
httpCommonTypesGenerated = true;
10192
}
10293

10394
// Add renders to output

src/codegen/generators/typescript/channels/protocols/http/index.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,6 @@ import {renderHttpFetchClient, renderHttpCommonTypes} from './fetch';
2121

2222
export {renderHttpFetchClient, renderHttpCommonTypes};
2323

24-
// Track whether common types have been generated for this protocol
25-
let httpCommonTypesGenerated = false;
26-
27-
/**
28-
* Reset the common types generation state.
29-
* Called at the start of each generation cycle.
30-
*/
31-
export function resetHttpCommonTypesState(): void {
32-
httpCommonTypesGenerated = false;
33-
}
34-
3524
export async function generatehttpChannels(
3625
context: TypeScriptChannelsGeneratorContext,
3726
channel: ChannelInterface,
@@ -50,12 +39,11 @@ export async function generatehttpChannels(
5039
renders = generateForOperations(context, channel, topic, parameter);
5140
}
5241

53-
// Generate common types once for the HTTP protocol
54-
if (!httpCommonTypesGenerated && renders.length > 0) {
42+
// Generate common types once for the HTTP protocol (stateless check)
43+
if (protocolCodeFunctions['http_client'].length === 0 && renders.length > 0) {
5544
const commonTypesCode = renderHttpCommonTypes();
5645
// Prepend common types to the beginning of the protocol code
5746
protocolCodeFunctions['http_client'].unshift(commonTypesCode);
58-
httpCommonTypesGenerated = true;
5947
}
6048

6149
addRendersToExternal(

0 commit comments

Comments
 (0)