Skip to content

Commit 7612b26

Browse files
authored
chore(release): v0.43.0 (#221)
1 parent 015426c commit 7612b26

File tree

10 files changed

+86
-47
lines changed

10 files changed

+86
-47
lines changed

docs/README.md

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

7272

7373

74+

docs/contributing.md

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

155155

156156

157+
157158

158159

docs/migrations/v0.md

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

6363

6464

65+

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.42.0 linux-x64 node-v18.20.8
12+
@the-codegen-project/cli/0.43.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.42.0/src/commands/generate.ts)_
84+
_See code: [src/commands/generate.ts](https://github.com/the-codegen-project/cli/blob/v0.43.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.42.0/src/commands/init.ts)_
142+
_See code: [src/commands/init.ts](https://github.com/the-codegen-project/cli/blob/v0.43.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.42.0",
4+
"version": "0.43.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/4"
35+
},
3336
{
3437
"$ref": "#/definitions/AsyncAPICodegenConfiguration/properties/generators/items/anyOf/6"
3538
}

src/codegen/generators/typescript/headers.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import {GenericCodegenContext, HeadersRenderType} from '../../types';
1010
import {z} from 'zod';
1111
import {defaultCodegenTypescriptModelinaOptions} from './utils';
1212
import {OpenAPIV2, OpenAPIV3, OpenAPIV3_1} from 'openapi-types';
13-
import { processAsyncAPIHeaders } from '../../inputs/asyncapi/generators/headers';
14-
import { processOpenAPIHeaders } from '../../inputs/openapi/generators/headers';
13+
import {processAsyncAPIHeaders} from '../../inputs/asyncapi/generators/headers';
14+
import {processOpenAPIHeaders} from '../../inputs/openapi/generators/headers';
1515

1616
export const zodTypescriptHeadersGenerator = z.object({
1717
id: z.string().optional().default('headers-typescript'),
@@ -47,10 +47,14 @@ export type TypeScriptHeadersRenderType =
4747

4848
// Interface for processed headers data (input-agnostic)
4949
export interface ProcessedHeadersData {
50-
channelHeaders: Record<string, {
51-
schema: any;
52-
schemaId: string;
53-
} | undefined>;
50+
channelHeaders: Record<
51+
string,
52+
| {
53+
schema: any;
54+
schemaId: string;
55+
}
56+
| undefined
57+
>;
5458
}
5559

5660
// Core generator function that works with processed data
@@ -75,7 +79,9 @@ export async function generateTypescriptHeadersCore(
7579

7680
const channelModels: Record<string, OutputModel | undefined> = {};
7781

78-
for (const [channelId, headerData] of Object.entries(processedData.channelHeaders)) {
82+
for (const [channelId, headerData] of Object.entries(
83+
processedData.channelHeaders
84+
)) {
7985
if (headerData) {
8086
const models = await modelinaGenerator.generateToFiles(
8187
headerData.schema,
@@ -97,7 +103,7 @@ export async function generateTypescriptHeaders(
97103
context: TypescriptHeadersContext
98104
): Promise<TypeScriptHeadersRenderType> {
99105
const {asyncapiDocument, openapiDocument, inputType, generator} = context;
100-
106+
101107
let processedData: ProcessedHeadersData;
102108

103109
// Process input based on type
@@ -119,7 +125,10 @@ export async function generateTypescriptHeaders(
119125
}
120126

121127
// Generate models using processed data
122-
const channelModels = await generateTypescriptHeadersCore(processedData, generator);
128+
const channelModels = await generateTypescriptHeadersCore(
129+
processedData,
130+
generator
131+
);
123132

124133
return {
125134
channelModels,

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
import { AsyncAPIDocumentInterface } from "@asyncapi/parser";
2-
import { ProcessedHeadersData } from "../../../generators/typescript/headers";
3-
import { pascalCase } from "../../../generators/typescript/utils";
1+
import {AsyncAPIDocumentInterface} from '@asyncapi/parser';
2+
import {ProcessedHeadersData} from '../../../generators/typescript/headers';
3+
import {pascalCase} from '../../../generators/typescript/utils';
44

55
// AsyncAPI input processor
66
export function processAsyncAPIHeaders(
77
asyncapiDocument: AsyncAPIDocumentInterface
88
): ProcessedHeadersData {
9-
const channelHeaders: Record<string, {
10-
schema: any;
11-
schemaId: string;
12-
} | undefined> = {};
9+
const channelHeaders: Record<
10+
string,
11+
| {
12+
schema: any;
13+
schemaId: string;
14+
}
15+
| undefined
16+
> = {};
1317

1418
for (const channel of asyncapiDocument.allChannels().all()) {
1519
const messages = channel.messages().all();
@@ -39,5 +43,5 @@ export function processAsyncAPIHeaders(
3943
}
4044
}
4145

42-
return { channelHeaders };
46+
return {channelHeaders};
4347
}

src/codegen/inputs/openapi/generators/headers.ts

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,51 @@
11
/* eslint-disable security/detect-object-injection */
2-
import { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from "openapi-types";
3-
import { ProcessedHeadersData } from "../../../generators/typescript/headers";
4-
import { pascalCase } from "../../../generators/typescript/utils";
2+
import {OpenAPIV2, OpenAPIV3, OpenAPIV3_1} from 'openapi-types';
3+
import {ProcessedHeadersData} from '../../../generators/typescript/headers';
4+
import {pascalCase} from '../../../generators/typescript/utils';
55

66
// Helper function to convert OpenAPI parameter schema to JSON Schema
77
function convertParameterSchemaToJsonSchema(parameter: any): any {
88
let schema: any;
9-
9+
1010
if (parameter.schema) {
1111
// OpenAPI 3.x format
12-
schema = { ...parameter.schema };
12+
schema = {...parameter.schema};
1313
} else if (parameter.type) {
1414
// OpenAPI 2.x format
1515
schema = {
1616
type: parameter.type,
17-
...(parameter.format && { format: parameter.format }),
18-
...(parameter.enum && { enum: parameter.enum }),
19-
...(parameter.minimum !== undefined && { minimum: parameter.minimum }),
20-
...(parameter.maximum !== undefined && { maximum: parameter.maximum }),
21-
...(parameter.minLength !== undefined && { minLength: parameter.minLength }),
22-
...(parameter.maxLength !== undefined && { maxLength: parameter.maxLength }),
23-
...(parameter.pattern && { pattern: parameter.pattern }),
17+
...(parameter.format && {format: parameter.format}),
18+
...(parameter.enum && {enum: parameter.enum}),
19+
...(parameter.minimum !== undefined && {minimum: parameter.minimum}),
20+
...(parameter.maximum !== undefined && {maximum: parameter.maximum}),
21+
...(parameter.minLength !== undefined && {
22+
minLength: parameter.minLength
23+
}),
24+
...(parameter.maxLength !== undefined && {
25+
maxLength: parameter.maxLength
26+
}),
27+
...(parameter.pattern && {pattern: parameter.pattern})
2428
};
2529
} else {
2630
// Fallback to string type
27-
schema = { type: 'string' };
31+
schema = {type: 'string'};
2832
}
2933

3034
return schema;
3135
}
3236

3337
// Extract header parameters from OpenAPI operations
34-
function extractHeadersFromOperations(paths: OpenAPIV3.PathsObject | OpenAPIV2.PathsObject | OpenAPIV3_1.PathsObject): Record<string, any[]> {
38+
function extractHeadersFromOperations(
39+
paths: OpenAPIV3.PathsObject | OpenAPIV2.PathsObject | OpenAPIV3_1.PathsObject
40+
): Record<string, any[]> {
3541
const operationHeaders: Record<string, any[]> = {};
3642

3743
for (const [pathKey, pathItem] of Object.entries(paths)) {
3844
for (const [method, operation] of Object.entries(pathItem)) {
39-
const operationObj = operation as OpenAPIV3.OperationObject | OpenAPIV2.OperationObject | OpenAPIV3_1.OperationObject;
45+
const operationObj = operation as
46+
| OpenAPIV3.OperationObject
47+
| OpenAPIV2.OperationObject
48+
| OpenAPIV3_1.OperationObject;
4049
// Collect header parameters from operation and path-level
4150
const allParameters = operationObj.parameters ?? [];
4251

@@ -45,7 +54,9 @@ function extractHeadersFromOperations(paths: OpenAPIV3.PathsObject | OpenAPIV2.P
4554
});
4655

4756
if (allParameters.length > 0) {
48-
const operationId = operationObj.operationId ?? `${method}${pathKey.replace(/[^a-zA-Z0-9]/g, '')}`;
57+
const operationId =
58+
operationObj.operationId ??
59+
`${method}${pathKey.replace(/[^a-zA-Z0-9]/g, '')}`;
4960
operationHeaders[operationId] = headerParams;
5061
}
5162
}
@@ -56,15 +67,24 @@ function extractHeadersFromOperations(paths: OpenAPIV3.PathsObject | OpenAPIV2.P
5667

5768
// OpenAPI input processor
5869
export function processOpenAPIHeaders(
59-
openapiDocument: OpenAPIV3.Document | OpenAPIV2.Document | OpenAPIV3_1.Document
70+
openapiDocument:
71+
| OpenAPIV3.Document
72+
| OpenAPIV2.Document
73+
| OpenAPIV3_1.Document
6074
): ProcessedHeadersData {
61-
const channelHeaders: Record<string, {
62-
schema: any;
63-
schemaId: string;
64-
} | undefined> = {};
75+
const channelHeaders: Record<
76+
string,
77+
| {
78+
schema: any;
79+
schemaId: string;
80+
}
81+
| undefined
82+
> = {};
6583

6684
// Extract header parameters from all operations
67-
const operationHeaders = extractHeadersFromOperations(openapiDocument.paths ?? {});
85+
const operationHeaders = extractHeadersFromOperations(
86+
openapiDocument.paths ?? {}
87+
);
6888

6989
// Process each operation that has header parameters
7090
for (const [operationId, headerParams] of Object.entries(operationHeaders)) {
@@ -80,7 +100,7 @@ export function processOpenAPIHeaders(
80100
for (const param of headerParams) {
81101
const paramName = param.name;
82102
const paramSchema = convertParameterSchemaToJsonSchema(param);
83-
103+
84104
// Add description if available
85105
if (param.description) {
86106
paramSchema.description = param.description;
@@ -114,5 +134,5 @@ export function processOpenAPIHeaders(
114134
};
115135
}
116136

117-
return { channelHeaders };
137+
return {channelHeaders};
118138
}

0 commit comments

Comments
 (0)