fix: separate mapped type from explicit properties in generated response object type#1954
Merged
pmcelhaney merged 6 commits intomainfrom Apr 26, 2026
Merged
Conversation
…nse object type
TypeScript doesn't allow combining explicit properties (e.g. 200: {...})
with a mapped type ([statusCode in Exclude<HttpStatusCode, ...>]: {...})
in the same object literal. When an OpenAPI spec defines a `default`
response alongside explicit status codes, the generator now emits an
intersection instead:
{ 200: {...}, 400: {...} } & { [statusCode in Exclude<HttpStatusCode, 200 | 400>]: {...} }
Also adds tests for buildResponseObjectType covering the intersection
case, the explicit-only case, and the mapped-only case.
Agent-Logs-Url: https://github.com/counterfact/api-simulator/sessions/486c1732-897a-4987-8e33-6564ad8af31c
Copilot
AI
changed the title
[WIP] Fix combined mapped type and explicit properties issue
fix: separate mapped type from explicit properties in generated response object type
Apr 25, 2026
Collaborator
|
@copilot unit tests are failing |
…d responses The change to buildResponseObjectType now emits explicit status codes and the mapped-type default entry as an intersection when both are present. Update the 5 affected Jest snapshots in operation-type-coder.test.ts and generate.test.ts to match the new output. Agent-Logs-Url: https://github.com/counterfact/api-simulator/sessions/f5a4b315-d88f-4ffc-87ed-f482aafafc6f
auto-merge was automatically disabled
April 26, 2026 01:41
Head branch was pushed to by a user without write access
Contributor
Author
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.
TypeScript prohibits mixing explicit properties and a mapped type in the same object literal. When an OpenAPI spec includes a
defaultresponse alongside explicit status codes, the generator was emitting invalid TypeScript:Summary
Generated response types broke
tscwhen an operation defined both explicit status codes and adefaultresponse.responses-type-coder.ts:buildResponseObjectTypenow partitions entries into explicit (numeric) and mapped ([statusCode in ...]) buckets. When both are present, emits an intersection; otherwise emits a single object as before.responses-type-coder.test.ts: Three newbuildResponseObjectTypetests cover the intersection path, the explicit-only path, and the mapped-only path.operation-type-coder.test.ts(×4) andgenerate.test.ts(×1) updated to match the new intersection output format.Original Prompt
TypeScript doesn't like this:
Manual acceptance tests
defaultresponse (e.g. Petstore); confirm the emitted.types.tsfile compiles without TypeScript errorsdefault) generates a single object type with no&intersectiondefaultresponse generates[statusCode in HttpStatusCode]: ...with no intersection200,400,422, anddefault) compiles cleanly undertsc --noEmitTasks
buildResponseObjectTypeentries into explicit vs. mapped buckets; emit intersection when both present