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
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,6 @@ Connect AI assistants like Claude Code, Cursor, and Windsurf to The Codegen Proj






1 change: 1 addition & 0 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,5 +216,6 @@ Prefix that follows specification is not enough though. Remember that the title






1 change: 1 addition & 0 deletions docs/migrations/v0.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,5 +244,6 @@ import * as NodeFetch from 'node-fetch';






10 changes: 5 additions & 5 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.78.1 linux-x64 node-v22.23.1
@the-codegen-project/cli/0.79.0 linux-x64 node-v22.23.1
$ codegen --help [COMMAND]
USAGE
$ codegen COMMAND
Expand Down Expand Up @@ -80,7 +80,7 @@ FLAGS
--silent Suppress all output except fatal errors
```

_See code: [src/commands/base.ts](https://github.com/the-codegen-project/cli/blob/v0.78.1/src/commands/base.ts)_
_See code: [src/commands/base.ts](https://github.com/the-codegen-project/cli/blob/v0.79.0/src/commands/base.ts)_

## `codegen generate [FILE]`

Expand Down Expand Up @@ -111,7 +111,7 @@ DESCRIPTION
configuration.
```

_See code: [src/commands/generate.ts](https://github.com/the-codegen-project/cli/blob/v0.78.1/src/commands/generate.ts)_
_See code: [src/commands/generate.ts](https://github.com/the-codegen-project/cli/blob/v0.79.0/src/commands/generate.ts)_

## `codegen help [COMMAND]`

Expand Down Expand Up @@ -180,7 +180,7 @@ DESCRIPTION
Initialize The Codegen Project in your project
```

_See code: [src/commands/init.ts](https://github.com/the-codegen-project/cli/blob/v0.78.1/src/commands/init.ts)_
_See code: [src/commands/init.ts](https://github.com/the-codegen-project/cli/blob/v0.79.0/src/commands/init.ts)_

## `codegen telemetry ACTION`

Expand Down Expand Up @@ -213,7 +213,7 @@ EXAMPLES
$ codegen telemetry disable
```

_See code: [src/commands/telemetry.ts](https://github.com/the-codegen-project/cli/blob/v0.78.1/src/commands/telemetry.ts)_
_See code: [src/commands/telemetry.ts](https://github.com/the-codegen-project/cli/blob/v0.79.0/src/commands/telemetry.ts)_

## `codegen version`

Expand Down
6 changes: 3 additions & 3 deletions mcp-server/lib/resources/bundled-docs.ts

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@the-codegen-project/cli",
"description": "CLI to work with code generation in any environment",
"version": "0.78.1",
"version": "0.79.0",
"bin": {
"codegen": "./bin/run.mjs"
},
Expand Down
148 changes: 129 additions & 19 deletions website/static/codegen.browser.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -119777,8 +119777,6 @@ var init_object = __esm({
init_dirname();
init_buffer2();
init_process2();
init_get();
init_set();
init_object_default();
}
});
Expand Down Expand Up @@ -1029881,7 +1029879,71 @@ async function handleTokenRefresh(
}

// src/codegen/generators/typescript/channels/protocols/http/common-types.ts
function renderHttpCommonTypes(securitySchemes) {
var HTTP_REASON_PHRASES = {
400: "Bad Request",
401: "Unauthorized",
402: "Payment Required",
403: "Forbidden",
404: "Not Found",
405: "Method Not Allowed",
406: "Not Acceptable",
407: "Proxy Authentication Required",
408: "Request Timeout",
409: "Conflict",
410: "Gone",
411: "Length Required",
412: "Precondition Failed",
413: "Payload Too Large",
414: "URI Too Long",
415: "Unsupported Media Type",
416: "Range Not Satisfiable",
417: "Expectation Failed",
418: "I'm a Teapot",
421: "Misdirected Request",
422: "Unprocessable Entity",
423: "Locked",
424: "Failed Dependency",
425: "Too Early",
426: "Upgrade Required",
428: "Precondition Required",
429: "Too Many Requests",
431: "Request Header Fields Too Large",
451: "Unavailable For Legal Reasons",
500: "Internal Server Error",
501: "Not Implemented",
502: "Bad Gateway",
503: "Service Unavailable",
504: "Gateway Timeout",
505: "HTTP Version Not Supported",
506: "Variant Also Negotiates",
507: "Insufficient Storage",
508: "Loop Detected",
510: "Not Extended",
511: "Network Authentication Required"
};
function renderHandleHttpErrorBody(errorStatusCodes) {
const defaultThrow = "throw new HttpError(`HTTP Error: ${status} ${statusText}`, status, statusText, body);";
const numericCodes = errorStatusCodes.filter((code) => typeof code === "number").filter((code, index4, all) => all.indexOf(code) === index4).sort((first, second) => first - second);
if (numericCodes.length === 0) {
return ` ${defaultThrow}`;
}
const cases = numericCodes.map((code) => {
const phrase = HTTP_REASON_PHRASES[code] ?? `HTTP Error: ${code}`;
return ` case ${code}:
throw new HttpError(${JSON.stringify(
phrase
)}, status, statusText, body);`;
}).join("\n");
return ` switch (status) {
${cases}
default:
${defaultThrow}
}`;
}
function renderHttpCommonTypes({
securitySchemes,
errorStatusCodes = []
} = {}) {
const requirements = analyzeSecuritySchemes(securitySchemes);
const securityTypes = renderSecurityTypes(securitySchemes, requirements);
const applyAuthCases = renderApplyAuthCases(requirements);
Expand Down Expand Up @@ -1029935,6 +1029997,27 @@ export interface HttpClientResponse<T> {
rawData: Record<string, any>;
}

/**
* Error thrown for non-OK HTTP responses.
*
* Carries the HTTP \`status\`, \`statusText\`, and the parsed response \`body\`
* (when the error response had a JSON body). Thrown by \`handleHttpError\` and
* routed through the \`onError\` hook / retry logic unchanged.
*/
export class HttpError extends Error {
status: number;
statusText: string;
body?: unknown;

constructor(message: string, status: number, statusText: string, body?: unknown) {
super(message);
this.name = 'HttpError';
this.status = status;
this.statusText = statusText;
this.body = body;
}
}

/**
* HTTP request parameters passed to the request hook
*/
Expand Down Expand Up @@ -1030191,21 +1030274,12 @@ async function executeWithRetry(
}

/**
* Handle HTTP error status codes with standardized messages
* Handle HTTP error status codes by throwing a typed HttpError.
* Explicit cases are generated from the error status codes declared by the
* input document; undeclared codes fall through to the default handler.
*/
function handleHttpError(status: number, statusText: string): never {
switch (status) {
case 401:
throw new Error('Unauthorized');
case 403:
throw new Error('Forbidden');
case 404:
throw new Error('Not Found');
case 500:
throw new Error('Internal Server Error');
default:
throw new Error(\`HTTP Error: \${status} \${statusText}\`);
}
function handleHttpError(status: number, statusText: string, body?: unknown): never {
${renderHandleHttpErrorBody(errorStatusCodes)}
}

/**
Expand Down Expand Up @@ -1030506,7 +1030580,8 @@ ${parameterNormalization}${oauth2ValidateBlock} // Build headers
${oauth2TokenBlock}
// Handle error responses
if (!response.ok) {
handleHttpError(response.status, response.statusText);
const errorBody = await response.json().catch(() => undefined);
handleHttpError(response.status, response.statusText, errorBody);
}

// Parse response
Expand Down Expand Up @@ -1031350,7 +1031425,11 @@ async function generateTypeScriptChannelsForOpenAPI(context2, parameters, payloa
oauth2Enabled
);
if (protocolCodeFunctions["http_client"].length === 0 && renders.length > 0) {
const commonTypesCode = renderHttpCommonTypes(securitySchemes);
const errorStatusCodes = collectErrorStatusCodes(openapiDocument);
const commonTypesCode = renderHttpCommonTypes({
securitySchemes,
errorStatusCodes
});
protocolCodeFunctions["http_client"].unshift(commonTypesCode);
}
addRendersToExternal({
Expand All @@ -1031361,6 +1031440,37 @@ async function generateTypeScriptChannelsForOpenAPI(context2, parameters, payloa
dependencies: deps
});
}
function collectResponseErrorCodes(responses, codes2) {
if (!responses) {
return;
}
for (const statusCode of Object.keys(responses)) {
if (statusCode === "default") {
codes2.add("default");
continue;
}
const numericCode = Number(statusCode);
if (Number.isInteger(numericCode) && numericCode >= 400) {
codes2.add(numericCode);
}
}
}
function collectErrorStatusCodes(openapiDocument) {
const codes2 = /* @__PURE__ */ new Set();
for (const pathItem of Object.values(openapiDocument.paths ?? {})) {
if (!pathItem) {
continue;
}
for (const method2 of HTTP_METHODS) {
const operation = pathItem[method2];
collectResponseErrorCodes(
operation?.responses,
codes2
);
}
}
return [...codes2];
}
function processOpenAPIOperations(openapiDocument, payloads, parameters, headers, oauth2Enabled) {
const renders = [];
for (const [path2, pathItem] of Object.entries(openapiDocument.paths ?? {})) {
Expand Down
Loading