Skip to content

fix(core): map content-less response schema to Unit, not JsonElement#79

Open
halotukozak wants to merge 1 commit into
fix/inline-enum-array-itemsfrom
fix/empty-response-schema-unit
Open

fix(core): map content-less response schema to Unit, not JsonElement#79
halotukozak wants to merge 1 commit into
fix/inline-enum-array-itemsfrom
fix/empty-response-schema-unit

Conversation

@halotukozak

@halotukozak halotukozak commented Jun 9, 2026

Copy link
Copy Markdown
Member

Problem

A response whose schema carries no structure — e.g. {} or { "nullable": true } — means "no body". It was resolved to TypeRef.Unknown and surfaced in the client as an untyped JsonElement success type instead of Unit.

Fix

Such a response schema now parses to a null schema, routing it through the existing no-content code path in ClientGenerator.resolveReturnType, which already falls back to UNIT. No runtime change is needed — the Unit path already existed for responses declared without content.

Responses with a real schema ($ref, type, properties, items, combinators, enum, or additionalProperties) are unaffected.

Tests

New SpecParserEmptyResponseTest + fixture: an empty-content response schema parses to null, while a sibling response with a $ref schema stays typed. :core:test and ktlintCheck are green.

A response whose schema carries no structure (e.g. `{}` or
`{ "nullable": true }`) means "no body". It was resolved to TypeRef.Unknown
and surfaced as a `JsonElement` success type. Now such a response schema
parses to `null`, routing it through the existing no-content path so the
client method returns `HttpResult<E, Unit>`.

Responses with a real schema ($ref, type, properties, items, combinators,
enum, or additionalProperties) are unaffected.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@halotukozak halotukozak self-assigned this Jun 9, 2026
@halotukozak halotukozak added this to the 1.0.0 milestone Jun 9, 2026
@halotukozak halotukozak requested a review from mfabisiak June 9, 2026 15:01
@halotukozak halotukozak added the bug Something isn't working label Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant