feat(generator): emit all documented responses (status codes + errors) via Tuyau rawResponse#1
Open
thetutlage wants to merge 1 commit into
Open
feat(generator): emit all documented responses (status codes + errors) via Tuyau rawResponse#1thetutlage wants to merge 1 commit into
thetutlage wants to merge 1 commit into
Conversation
getResponses() previously read only the `response` type and hardcoded it
under status 200. As a result error responses (401/403/422/…) were never
emitted, non-200 successes (201) were mislabeled 200, and empty-body 204s
were dropped entirely.
Drive responses from Tuyau's normalized `rawResponse` union
({ status; response } across all status codes): split the union, read each
member's instantiated status literal and body, group by status, and emit one
response per code (oneOf when a code has multiple shapes; no content for
empty 204 bodies). Falls back to the legacy `response`→200 path when
`rawResponse` is absent, so older @tuyau/core registries keep working.
Status/response literals are read via getTypeAtLocation so the instantiated
value (201 / concrete body) is used rather than the generic ExtractRawResponse
type parameters.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P3ZYnmGMEZwTuBuZviLDSq
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.
@outloud/adonis-openapi-generator — Emit all documented responses via Tuyau
rawResponseProblem
Route.getResponses()reads only the registry'sresponsetype and hardcodes it under status200:Consequences in the generated spec:
errorResponse(401/403/422/…) is available in the Tuyau registry but nothing reads it.201(response.created) is documented as200; a204(response.noContent) resolves to anunknownbody and is dropped entirely (theisUnknown()guard bails, emitting no responses at all).Change
Drive
getResponses()from Tuyau's normalizedrawResponseunion ({ status; response }across all status codes — see companion@tuyau/corePR). For each union member, read its status literal and body, group by status, and emit one OpenAPI response per code:oneOf;void/unknownbody (e.g.204) → response with a description and no content;Falls back to the previous
response→200behavior whenrawResponseis absent (older@tuyau/core), so the generator keeps working across versions.Implementation note (subtle)
Read each member's
status/responsewithsymbol.getTypeAtLocation(node), notsymbol.getValueDeclaration()?.getType(). The latter returns the generic parameter (S/R) from theExtractRawResponsedefinition rather than the instantiated literal (201) / concrete body — which silently drops everyinfer-derived status.Before → after (example API)
POST /auth/signup(response.created)200201,422POST /auth/login(two success states)200200(oneOf),422POST /oauth/token(returnsunauthorized)200200,401,422POST /logout(response.noContent)204DELETE /social-identities/:id204,422Error bodies now carry the real
{ errors: [...] }schema; multi-state 200s render as a discriminatedoneOf; 204s have no content.Compatibility
Requires
@tuyau/corewithrawResponse(companion PR). Without it, thethis.context.property("rawResponse")lookup is caught and the generator uses the legacy 200-only path — no crash, no behavior change for old registries.Known limitation (out of scope)
Only responses the controller returns through a typed helper (
response.created,response.unauthorized, …) or that Tuyau appends (the auto422) are captured. Errors that are thrown (e.g.E_INVALID_CREDENTIALS, rate-limit429, self-handled exceptions) aren't in the controller's return type, so neither Tuyau nor this generator can see them. Surfacing those would need a separate mechanism (e.g. a decorator/annotation to declare thrown statuses).Files touched
Route.getResponses()(compiled:build/index.js)🤖 Generated with Claude Code