Skip to content

Commit 01aec5f

Browse files
authored
chore(release): v0.44.0 (#224)
1 parent 554a82a commit 01aec5f

File tree

10 files changed

+167
-72
lines changed

10 files changed

+167
-72
lines changed

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,4 @@ Get an overview of how to contribute to the project
7272

7373

7474

75+

docs/contributing.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,5 +155,6 @@ Prefix that follows specification is not enough though. Remember that the title
155155

156156

157157

158+
158159

159160

docs/migrations/v0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,4 @@ const subscriber = await jetStreamPullSubscribeToReceiveUserSignedup({
6363

6464

6565

66+

docs/usage.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ $ npm install -g @the-codegen-project/cli
99
$ codegen COMMAND
1010
running command...
1111
$ codegen (--version)
12-
@the-codegen-project/cli/0.43.0 linux-x64 node-v18.20.8
12+
@the-codegen-project/cli/0.44.0 linux-x64 node-v18.20.8
1313
$ codegen --help [COMMAND]
1414
USAGE
1515
$ codegen COMMAND
@@ -81,7 +81,7 @@ DESCRIPTION
8181
Generate code based on your configuration, use `init` to get started.
8282
```
8383

84-
_See code: [src/commands/generate.ts](https://github.com/the-codegen-project/cli/blob/v0.43.0/src/commands/generate.ts)_
84+
_See code: [src/commands/generate.ts](https://github.com/the-codegen-project/cli/blob/v0.44.0/src/commands/generate.ts)_
8585

8686
## `codegen help [COMMAND]`
8787

@@ -139,7 +139,7 @@ DESCRIPTION
139139
Initialize The Codegen Project in your project
140140
```
141141

142-
_See code: [src/commands/init.ts](https://github.com/the-codegen-project/cli/blob/v0.43.0/src/commands/init.ts)_
142+
_See code: [src/commands/init.ts](https://github.com/the-codegen-project/cli/blob/v0.44.0/src/commands/init.ts)_
143143

144144
## `codegen version`
145145

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@the-codegen-project/cli",
33
"description": "CLI to work with code generation in any environment",
4-
"version": "0.43.0",
4+
"version": "0.44.0",
55
"bin": {
66
"codegen": "./bin/run.mjs"
77
},

schemas/configuration-schema-0.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
"type": "array",
3131
"items": {
3232
"anyOf": [
33+
{
34+
"$ref": "#/definitions/AsyncAPICodegenConfiguration/properties/generators/items/anyOf/0"
35+
},
3336
{
3437
"$ref": "#/definitions/AsyncAPICodegenConfiguration/properties/generators/items/anyOf/4"
3538
},

src/codegen/generators/typescript/payloads.ts

Lines changed: 59 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ import {
1111
} from '@asyncapi/modelina';
1212
import {GenericCodegenContext, PayloadRenderType} from '../../types';
1313
import {AsyncAPIDocumentInterface} from '@asyncapi/parser';
14-
import {processAsyncAPIPayloads, ProcessedPayloadSchemaData} from '../../inputs/asyncapi/generators/payloads';
14+
import {
15+
processAsyncAPIPayloads,
16+
ProcessedPayloadSchemaData
17+
} from '../../inputs/asyncapi/generators/payloads';
1518
import {processOpenAPIPayloads} from '../../inputs/openapi/generators/payloads';
1619
import {z} from 'zod';
1720
import {defaultCodegenTypescriptModelinaOptions} from './utils';
1821
import {Logger} from '../../../LoggingInterface';
1922
import {TypeScriptRenderer} from '@asyncapi/modelina/lib/types/generators/typescript/TypeScriptRenderer';
20-
import { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';
23+
import {OpenAPIV2, OpenAPIV3, OpenAPIV3_1} from 'openapi-types';
2124

2225
export const zodTypeScriptPayloadGenerator = z.object({
2326
id: z.string().optional().default('payloads-typescript'),
@@ -87,8 +90,14 @@ export type TypeScriptPayloadRenderType =
8790

8891
// Interface for processed payloads data (input-agnostic)
8992
export interface ProcessedPayloadData {
90-
channelModels: Record<string, {messageModel: OutputModel; messageType: string}>;
91-
operationModels: Record<string, {messageModel: OutputModel; messageType: string}>;
93+
channelModels: Record<
94+
string,
95+
{messageModel: OutputModel; messageType: string}
96+
>;
97+
operationModels: Record<
98+
string,
99+
{messageModel: OutputModel; messageType: string}
100+
>;
92101
otherModels: Array<{messageModel: OutputModel; messageType: string}>;
93102
}
94103

@@ -303,14 +312,14 @@ export function safeStringify(value: any): string {
303312
let depth = 0;
304313
const maxDepth = 255;
305314
const maxRepetitions = 5; // Allow up to 5 repetitions of the same object
306-
315+
307316
// eslint-disable-next-line sonarjs/cognitive-complexity
308317
function stringify(val: any, currentPath: any[] = []): any {
309318
// Check depth limit
310319
if (depth > maxDepth) {
311320
return true;
312321
}
313-
322+
314323
switch (typeof val) {
315324
case 'function':
316325
return true;
@@ -322,38 +331,47 @@ export function safeStringify(value: any): string {
322331
if (val === null) {
323332
return null;
324333
}
325-
334+
326335
// Check for immediate circular reference (direct self-reference)
327-
if (currentPath.length > 0 && currentPath[currentPath.length - 1] === val) {
336+
if (
337+
currentPath.length > 0 &&
338+
currentPath[currentPath.length - 1] === val
339+
) {
328340
return true;
329341
}
330-
342+
331343
// Count how many times this object appears in the current path
332-
const repetitionCount = currentPath.filter(obj => obj === val).length;
333-
344+
const repetitionCount = currentPath.filter((obj) => obj === val).length;
345+
334346
// If we've seen this object too many times in the current path, cut it off
335347
if (repetitionCount >= maxRepetitions) {
336348
return true;
337349
}
338-
350+
339351
depth++;
340352
const newPath = [...currentPath, val];
341-
353+
342354
let result: any;
343-
355+
344356
if (Array.isArray(val)) {
345-
result = val.map(item => stringify(item, newPath));
357+
result = val.map((item) => stringify(item, newPath));
346358
} else {
347359
result = {};
348360
for (const [key, value] of Object.entries(val)) {
349361
// Skip extension properties
350-
if (key.startsWith('x-modelina') || key.startsWith('x-the-codegen-project') || key.startsWith('x-parser-') || key.startsWith('x-modelgen-') || key.startsWith('discriminator')) {
362+
if (
363+
key.startsWith('x-modelina') ||
364+
key.startsWith('x-the-codegen-project') ||
365+
key.startsWith('x-parser-') ||
366+
key.startsWith('x-modelgen-') ||
367+
key.startsWith('discriminator')
368+
) {
351369
continue;
352370
}
353371
result[key] = stringify(value, newPath);
354372
}
355373
}
356-
374+
357375
depth--;
358376
return result;
359377
}
@@ -363,7 +381,7 @@ export function safeStringify(value: any): string {
363381
return true;
364382
}
365383
}
366-
384+
367385
return JSON.stringify(stringify(value));
368386
}
369387

@@ -372,7 +390,7 @@ export async function generateTypescriptPayloadsCore(
372390
processedData: ProcessedPayloadData,
373391
generator: TypeScriptPayloadGeneratorInternal
374392
): Promise<TypeScriptPayloadRenderType> {
375-
// The models are already generated by the input processors,
393+
// The models are already generated by the input processors,
376394
// so we just need to return them in the expected format
377395
return {
378396
channelModels: processedData.channelModels,
@@ -480,12 +498,21 @@ ${renderUnionUnmarshalByStatusCode(model)}`;
480498
useJavascriptReservedKeywords: generator.useForJavaScript
481499
});
482500

483-
const channelModels: Record<string, {messageModel: OutputModel; messageType: string}> = {};
484-
const operationModels: Record<string, {messageModel: OutputModel; messageType: string}> = {};
485-
const otherModels: Array<{messageModel: OutputModel; messageType: string}> = [];
501+
const channelModels: Record<
502+
string,
503+
{messageModel: OutputModel; messageType: string}
504+
> = {};
505+
const operationModels: Record<
506+
string,
507+
{messageModel: OutputModel; messageType: string}
508+
> = {};
509+
const otherModels: Array<{messageModel: OutputModel; messageType: string}> =
510+
[];
486511

487512
// Generate models for channel payloads
488-
for (const [channelId, schemaData] of Object.entries(processedSchemaData.channelPayloads)) {
513+
for (const [channelId, schemaData] of Object.entries(
514+
processedSchemaData.channelPayloads
515+
)) {
489516
if (schemaData) {
490517
const models = await modelinaGenerator.generateToFiles(
491518
schemaData.schema,
@@ -508,7 +535,9 @@ ${renderUnionUnmarshalByStatusCode(model)}`;
508535
}
509536

510537
// Generate models for operation payloads
511-
for (const [operationId, schemaData] of Object.entries(processedSchemaData.operationPayloads)) {
538+
for (const [operationId, schemaData] of Object.entries(
539+
processedSchemaData.operationPayloads
540+
)) {
512541
if (schemaData) {
513542
const models = await modelinaGenerator.generateToFiles(
514543
schemaData.schema,
@@ -573,15 +602,15 @@ export async function generateTypescriptPayload(
573602
if (!asyncapiDocument) {
574603
throw new Error('Expected AsyncAPI input, was not given');
575604
}
576-
605+
577606
processedSchemaData = await processAsyncAPIPayloads(asyncapiDocument);
578607
break;
579608
}
580609
case 'openapi': {
581610
if (!openapiDocument) {
582611
throw new Error('Expected OpenAPI input, was not given');
583612
}
584-
613+
585614
processedSchemaData = processOpenAPIPayloads(openapiDocument);
586615
break;
587616
}
@@ -590,5 +619,8 @@ export async function generateTypescriptPayload(
590619
}
591620

592621
// Generate final result using processed schema data
593-
return generateTypescriptPayloadsCoreFromSchemas(processedSchemaData, generator);
622+
return generateTypescriptPayloadsCoreFromSchemas(
623+
processedSchemaData,
624+
generator
625+
);
594626
}

src/codegen/inputs/asyncapi/generators/payloads.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
/* eslint-disable security/detect-object-injection */
2-
import {
3-
AsyncAPIInputProcessor
4-
} from '@asyncapi/modelina';
2+
import {AsyncAPIInputProcessor} from '@asyncapi/modelina';
53
import {AsyncAPIDocumentInterface, MessageInterface} from '@asyncapi/parser';
64
import {pascalCase} from '../../../generators/typescript/utils';
7-
import {findNameFromChannel, findOperationId, findReplyId, onlyUnique} from '../../../utils';
5+
import {
6+
findNameFromChannel,
7+
findOperationId,
8+
findReplyId,
9+
onlyUnique
10+
} from '../../../utils';
811

912
// Interface for processed payload schema data
1013
export interface ProcessedPayloadSchemaData {
@@ -68,7 +71,10 @@ export async function processAsyncAPIPayloads(
6871
if (typeof schema === 'boolean') {
6972
schemaObj = schema;
7073
} else {
71-
id = message.id() ?? message.name() ?? schema['x-modelgen-inferred-name'];
74+
id =
75+
message.id() ??
76+
message.name() ??
77+
schema['x-modelgen-inferred-name'];
7278
if (id.includes('AnonymousSchema_')) {
7379
id = pascalCase(`${preId}_Payload`);
7480
}
@@ -84,7 +90,7 @@ export async function processAsyncAPIPayloads(
8490
} else {
8591
return;
8692
}
87-
93+
8894
return {
8995
schema: schemaObj,
9096
schemaId: id ?? schemaObj.$id ?? pascalCase(`${preId}_Payload`)
@@ -97,7 +103,7 @@ export async function processAsyncAPIPayloads(
97103
for (const operation of channel.operations().all()) {
98104
const operationMessages = operation.messages().all();
99105
const operationReply = operation.reply();
100-
106+
101107
if (operationReply) {
102108
const operationReplyId = findReplyId(
103109
operation,
@@ -112,17 +118,14 @@ export async function processAsyncAPIPayloads(
112118
operationPayloads[operationReplyId] = operationReplySchema;
113119
}
114120
}
115-
121+
116122
const operationId = findOperationId(operation, channel);
117-
const operationSchema = processMessages(
118-
operationMessages,
119-
operationId
120-
);
123+
const operationSchema = processMessages(operationMessages, operationId);
121124
if (operationSchema) {
122125
operationPayloads[operationId] = operationSchema;
123126
}
124127
}
125-
128+
126129
// Process channel messages
127130
const channelSchema = processMessages(
128131
channel.messages().all(),

0 commit comments

Comments
 (0)