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
4 changes: 4 additions & 0 deletions .github/workflows/version-bump.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ jobs:
run: npm run build
- name: Assets generation
run: npm run generate:assets
- name: Regenerate playground bundle and schema
run: npm run generate:playground
- name: Regenerate MCP server bundled docs
run: npm run generate:mcp:docs
- name: Create Pull Request with updated asset files including package.json
uses: peter-evans/create-pull-request@38e0b6e68b4c852a5500a94740f0e535e0d7ba54 # use 4.2.4 https://github.com/peter-evans/create-pull-request/releases/tag/v4.2.4
with:
Expand Down
58 changes: 58 additions & 0 deletions docs/migrations/v0.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ sidebar_position: 99
* [Breaking Changes 0.64.2](#breaking-changes-0642)
* [Breaking Changes 0.71.0](#breaking-changes-0710)
+ [Library API Type Changes](#library-api-type-changes)
* [Breaking Changes 0.72.3](#breaking-changes-0723)
+ [OpenAPI Operation Names](#openapi-operation-names)
* [Breaking Changes 0.72.6](#breaking-changes-0726)
+ [Generated HTTP Client Uses Native fetch](#generated-http-client-uses-native-fetch)

<!-- tocstop -->

Expand Down Expand Up @@ -167,6 +171,60 @@ interface GeneratedFile {
3. Replace `generator.filesWritten` with `generator.files.map(f => f.path)`
4. Optionally leverage the new `content` property for in-memory processing

## Breaking Changes 0.72.3

### OpenAPI Operation Names

The OpenAPI `channels` and `client` (`http_client`) generators previously prepended the HTTP method to the operation name, even when the spec already provided an `operationId`. This produced a duplicated verb (e.g. an `addPet` operation with method `POST` generated `postAddPet`). The `operationId` is now used verbatim as the function name, and the method is only used to synthesize a name when no `operationId` is present.

This renames the generated functions (and their `*Context` interfaces) for any OpenAPI operation that declares an `operationId`.

**Before (v0.72.2 and earlier):**
```typescript
import { postAddPet, putUpdatePet, getFindPetsByStatusAndCategory } from './channels/http_client';

await postAddPet({ /* ... */ });
```

**After (v0.72.3+):**
```typescript
import { addPet, updatePet, findPetsByStatusAndCategory } from './channels/http_client';

await addPet({ /* ... */ });
```

**Migration steps:**
1. Regenerate your code.
2. Update call sites to drop the leading HTTP verb from function names that came from an `operationId` (e.g. `postAddPet` → `addPet`).
3. Update any references to the renamed `*Context` interfaces (e.g. `PostAddPetContext` → `AddPetContext`).

## Breaking Changes 0.72.6

### Generated HTTP Client Uses Native fetch

The generated HTTP client (OpenAPI `http_client` channels and the `http` client) no longer imports `node-fetch`. It now uses the global `fetch`/`Headers` built into the runtime. The `node-fetch` (and `@types/node-fetch`) dependency is no longer needed. This project already requires Node.js 22, which ships a global `fetch`.

**Before (v0.72.5 and earlier):**
```typescript
// Generated client imported node-fetch
import * as NodeFetch from 'node-fetch';
// package.json needed:
// "node-fetch": "^2.6.7", "@types/node-fetch": "^2.6.11"
```

**After (v0.72.6+):**
```typescript
// Generated client uses the runtime's global fetch — no import, no dependency.
// To use a different HTTP implementation (node-fetch, axios, ...), provide it
// via the makeRequest hook on the client context.
```

**Migration steps:**
1. Regenerate your code.
2. Remove `node-fetch` and `@types/node-fetch` from your project's dependencies if they were only used by the generated client.
3. Ensure your runtime provides a global `fetch` (Node.js 18+). If you need a custom HTTP implementation, supply it through the `makeRequest` hook instead of relying on the default.





Expand Down
10 changes: 6 additions & 4 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ $ npm install -g @the-codegen-project/cli
$ codegen COMMAND
running command...
$ codegen (--version)
@the-codegen-project/cli/0.74.0 linux-x64 node-v22.23.1
@the-codegen-project/cli/0.74.0 darwin-arm64 node-v24.15.0
$ codegen --help [COMMAND]
USAGE
$ codegen COMMAND
Expand Down Expand Up @@ -140,9 +140,9 @@ Initialize The Codegen Project in your project
```
USAGE
$ codegen init [--json] [--no-color] [--debug | | [--silent | -v | -q]] [--help] [--input-file <value>]
[--config-name <value>] [--input-type asyncapi|openapi] [--output-directory <value>] [--config-type
[--config-name <value>] [--input-type asyncapi|openapi|jsonschema] [--output-directory <value>] [--config-type
esm|json|yaml|ts] [--languages typescript] [--no-tty] [--include-payloads] [--include-headers] [--include-client]
[--include-parameters] [--include-channels] [--gitignore-generated]
[--include-parameters] [--include-channels] [--include-types] [--include-models] [--gitignore-generated]

FLAGS
-q, --quiet Only show errors and warnings
Expand All @@ -159,11 +159,13 @@ FLAGS
--include-channels Include channels generation, available for TypeScript
--include-client Include client generation, available for TypeScript
--include-headers Include headers generation, available for TypeScript
--include-models Include models generation, available for TypeScript
--include-parameters Include parameters generation, available for TypeScript
--include-payloads Include payloads generation, available for TypeScript
--include-types Include types generation, available for TypeScript
--input-file=<value> File path for the code generation input such as AsyncAPI document
--input-type=<option> Input file type
<options: asyncapi|openapi>
<options: asyncapi|openapi|jsonschema>
--json Output results as JSON for scripting
--languages=<option> Which languages do you wish to generate code for?
<options: typescript>
Expand Down
16 changes: 12 additions & 4 deletions mcp-server/lib/data/generators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,25 @@ export const generators: Record<GeneratorPreset, GeneratorDefinition> = {
client: {
preset: 'client',
description:
'Generates a high-level client class that wraps channel functions with connection management.',
supportedInputs: ['asyncapi'],
'Generates a high-level client class that wraps channel functions with connection management (NATS) or shared request configuration (HTTP).',
supportedInputs: ['asyncapi', 'openapi'],
defaultOutputPath: 'src/__gen__/client',
dependencies: ['channels'],
options: [
{
name: 'protocols',
type: 'array',
description: 'Protocols to generate clients for (currently only NATS supported)',
description:
'Protocols to generate clients for. NATS wraps the channel functions and manages the connection; HTTP generates a single client class wrapping the http_client channel functions.',
required: true,
enumValues: ['nats'],
default: ['nats'],
enumValues: ['nats', 'http'],
},
{
name: 'clientName',
type: 'string',
description:
'Overrides the generated HTTP client class name. When omitted, the name is derived from the input document title, falling back to "HttpClient". Only affects the HTTP protocol client.',
},
],
},
Expand Down
66 changes: 35 additions & 31 deletions mcp-server/lib/resources/bundled-docs.ts

Large diffs are not rendered by default.

65 changes: 53 additions & 12 deletions mcp-server/lib/tools/config-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,41 @@ import {
protocolDescriptions,
} from '../data/generators';

/**
* The client generator only supports a subset of protocols, and names the HTTP
* protocol `http` (the channels generator calls it `http_client`). Map the MCP
* protocol names onto the client generator's protocol values.
*/
const CLIENT_PROTOCOL_MAP: Record<string, string> = {
nats: 'nats',
http: 'http',
http_client: 'http',
};

/**
* Resolve the protocols a `client` generator should use from the requested
* protocol list, returning the (deduped) supported values and any that were
* dropped because the client generator does not support them.
*/
function resolveClientProtocols(requested: string[]): {
protocols: string[];
unsupported: string[];
} {
const protocols: string[] = [];
const unsupported: string[] = [];
for (const protocol of requested) {
const mapped = CLIENT_PROTOCOL_MAP[protocol];
if (mapped) {
if (!protocols.includes(mapped)) {
protocols.push(mapped);
}
} else {
unsupported.push(protocol);
}
}
return { protocols, unsupported };
}

/**
* Schema for create_config tool
*/
Expand Down Expand Up @@ -70,15 +105,18 @@ export function createConfig(input: CreateConfigInput): {

// Add protocols if needed
if ((preset === 'channels' || preset === 'client') && input.protocols?.length) {
const validProtocols =
preset === 'client'
? input.protocols.filter((p) => p === 'nats')
: input.protocols;
if (validProtocols.length > 0) {
config.protocols = validProtocols;
}
if (preset === 'client' && input.protocols.some((p) => p !== 'nats')) {
warnings.push('Client generator currently only supports NATS protocol.');
if (preset === 'client') {
const { protocols, unsupported } = resolveClientProtocols(input.protocols);
if (protocols.length > 0) {
config.protocols = protocols;
}
if (unsupported.length > 0) {
warnings.push(
`Client generator supports only NATS and HTTP protocols. Ignoring: ${unsupported.join(', ')}.`
);
}
} else {
config.protocols = input.protocols;
}
}

Expand Down Expand Up @@ -247,9 +285,12 @@ export function addGenerator(input: AddGeneratorInput): {
// Add protocols if applicable
if ((input.preset === 'channels' || input.preset === 'client') && input.protocols) {
if (input.preset === 'client') {
config.protocols = input.protocols.filter((p) => p === 'nats');
if (input.protocols.some((p) => p !== 'nats')) {
notes.push('Client generator currently only supports NATS. Other protocols were filtered out.');
const { protocols, unsupported } = resolveClientProtocols(input.protocols);
config.protocols = protocols;
if (unsupported.length > 0) {
notes.push(
`Client generator supports only NATS and HTTP. Other protocols were filtered out: ${unsupported.join(', ')}.`
);
}
} else {
config.protocols = input.protocols;
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@
"generate:readme:commands": "oclif readme --readme-path=\"./docs/usage.md\" --output-dir=\"./docs\"",
"generate:assets": "npm run generate:readme:toc && npm run generate:commands && npm run generate:schema && npm run format",
"generate:schema": "node scripts/generateSchemaFiles.js",
"generate:playground": "npm run build:browser && cd website && npm run copy:bundle && npm run copy:schema",
"generate:mcp:docs": "cd mcp-server && npm ci && npm run bundle-docs",
"generate:commands": "npm run generate:readme:commands",
"generate:readme:toc": "markdown-toc -i README.md && markdown-toc -i ./docs/usage.md && markdown-toc -i ./docs/migrations/v0.md && markdown-toc -i ./docs/README.md && markdown-toc -i ./docs/contributing.md ",
"lint": "eslint --max-warnings 0 --config .eslintrc . && npm run typecheck:test",
Expand Down
5 changes: 5 additions & 0 deletions src/codegen/generators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ export {
TypescriptTypesGeneratorInternal,
defaultTypeScriptTypesOptions,
generateTypescriptTypes,
TypescriptModelsContext,
TypescriptModelsGenerator,
TypescriptModelsGeneratorInternal,
defaultTypeScriptModelsOptions,
generateTypescriptModels,
ChannelFunctionTypes
} from './typescript';
export {
Expand Down
7 changes: 7 additions & 0 deletions src/codegen/generators/typescript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ export {
defaultTypeScriptTypesOptions,
TypescriptTypesGeneratorInternal
} from './types';
export {
generateTypescriptModels,
TypescriptModelsContext,
TypescriptModelsGenerator,
defaultTypeScriptModelsOptions,
TypescriptModelsGeneratorInternal
} from './models';

// Export presets for external use
export * from '../../modelina/presets';
Loading
Loading