feat(core): support default response in return type resolution#50
feat(core): support default response in return type resolution#50halotukozak wants to merge 1 commit intomasterfrom
Conversation
When an endpoint defines only a `default` response (no explicit 2xx), the generator now falls back to the default response schema instead of returning Unit. 2xx responses still take precedence when present. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds support in the Kotlin client generator to use an OpenAPI default response schema for the generated success return type when no explicit 2xx response schema exists, and adds regression tests for this behavior (Issue #38).
Changes:
- Update return type resolution to fall back to
defaultresponse schema when no 2xx schema is present. - Add tests covering
default-only responses, 2xx precedence overdefault, anddefaultwithout schema →Unit.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| core/src/main/kotlin/com/avsystem/justworks/core/gen/client/ClientGenerator.kt | Adjusts endpoint return type resolution to consider default responses. |
| core/src/test/kotlin/com/avsystem/justworks/core/gen/ClientGeneratorTest.kt | Adds tests to validate default fallback and precedence rules. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| val twoXxSchema = endpoint.responses.entries | ||
| .asSequence() | ||
| .filter { it.key.startsWith("2") } | ||
| .firstNotNullOfOrNull { it.value.schema } | ||
|
|
||
| val schema = twoXxSchema ?: endpoint.responses["default"]?.schema | ||
|
|
||
| return schema?.toTypeName() ?: UNIT |
There was a problem hiding this comment.
Current fallback uses the default schema whenever no 2xx schema is found. That changes behavior when a 2xx response exists but has no schema (e.g., only 204), causing the generator to treat a default (often error) schema as the success body type and emit toResult() instead of toEmptyResult(). To match the PR description/precedence rules, only fall back to default when no 2xx response is defined at all; if any 2xx response exists but none have a schema, keep returning Unit.
Summary
defaultresponse (no explicit 2xx), the generator now falls back to the default response schema instead of returningUnitCloses #38
Test plan
defaultresponse used when no 2xx defined → typed returndefaultdefaultwithout schema →Unit🤖 Generated with Claude Code