Skip to content

fix(generator): skip JSON parse for 204/205 No Content responses#118

Merged
julienandreu merged 1 commit into
julienandreu:mainfrom
laurentjacob:fix/handle-204-no-content
May 29, 2026
Merged

fix(generator): skip JSON parse for 204/205 No Content responses#118
julienandreu merged 1 commit into
julienandreu:mainfrom
laurentjacob:fix/handle-204-no-content

Conversation

@laurentjacob

Copy link
Copy Markdown
Contributor

Summary

The generated makeRequest method calls await response.json() unconditionally, which throws Failed to execute 'json' on 'Response': Unexpected end of JSON input for endpoints returning 204 No Content or 205 Reset Content (per RFC 7231, these MUST have empty bodies).

The generator already correctly emits Promise<void> return types for OpenAPI endpoints declared with 204 responses (no responses.200.content schema), so the runtime behavior should match — skip the parse for those status codes and return undefined.

Repro

Any OpenAPI spec with a DELETE endpoint declared as responses: { "204": { description: "..." } } (no content) generates a Promise<void> method that, when called, throws on the JSON parse.

Fix

Guard the response.json() call with a status check before parsing. Adds the equivalent of:

if (response.status === 204 || response.status === 205) {
    return undefined as T;
}
return await response.json();

Tests

Added a regression test under tests/unit/code-generator.test.ts asserting the 204 guard is present in the generated makeRequest source (mirror the style used by the multi-param path-template test from #115).

Context

Follow-up to #115 — same generator, separate bug. The downstream SDK (@saris-ai/api) ships a couple dozen DELETE endpoints in its new RBAC slice and we're hitting this on every revoke/delete operation.

The generated makeRequest method called `await response.json()`
unconditionally, which throws "Unexpected end of JSON input" on
endpoints that return 204 No Content (commonly DELETE endpoints
declared as `Promise<void>` in OpenAPI specs).

Per RFC 7231 §6.3.5 and §6.3.6, 204 and 205 responses MUST have
empty bodies. This adds an early return of `undefined as T` for
those status codes before attempting JSON parse.

Affects every OpenAPI spec that declares 204 or 205 responses — a
common pattern for resource deletion and idempotent state changes.
@julienandreu julienandreu merged commit 20b317f into julienandreu:main May 29, 2026
2 of 3 checks passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.7.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants