fix(generator): skip JSON parse for 204/205 No Content responses#118
Merged
julienandreu merged 1 commit intoMay 29, 2026
Merged
Conversation
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
approved these changes
May 29, 2026
|
🎉 This PR is included in version 1.7.4 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The generated
makeRequestmethod callsawait response.json()unconditionally, which throwsFailed to execute 'json' on 'Response': Unexpected end of JSON inputfor endpoints returning204 No Contentor205 Reset Content(per RFC 7231, these MUST have empty bodies).The generator already correctly emits
Promise<void>return types for OpenAPI endpoints declared with204responses (noresponses.200.contentschema), so the runtime behavior should match — skip the parse for those status codes and returnundefined.Repro
Any OpenAPI spec with a
DELETEendpoint declared asresponses: { "204": { description: "..." } }(no content) generates aPromise<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:Tests
Added a regression test under
tests/unit/code-generator.test.tsasserting the 204 guard is present in the generatedmakeRequestsource (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.