Skip to content

feat(core): support default response in return type resolution#50

Open
halotukozak wants to merge 1 commit intomasterfrom
feat/default-response-fallback
Open

feat(core): support default response in return type resolution#50
halotukozak wants to merge 1 commit intomasterfrom
feat/default-response-fallback

Conversation

@halotukozak
Copy link
Copy Markdown
Member

Summary

  • 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 both are present

Closes #38

Test plan

  • Test: default response used when no 2xx defined → typed return
  • Test: 2xx takes precedence over default
  • Test: default without schema → Unit
  • All existing tests pass

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings April 9, 2026 18:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 default response schema when no 2xx schema is present.
  • Add tests covering default-only responses, 2xx precedence over default, and default without 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.

Comment on lines +160 to +167
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
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support default response in OpenAPI endpoint parsing

2 participants