Skip to content

fix: correct baseUrl interpolation and spurious body null checks#54

Merged
halotukozak merged 2 commits intomasterfrom
fixes-before-0.0.2
Apr 10, 2026
Merged

fix: correct baseUrl interpolation and spurious body null checks#54
halotukozak merged 2 commits intomasterfrom
fixes-before-0.0.2

Conversation

@halotukozak
Copy link
Copy Markdown
Member

Summary

  • baseUrl not interpolated: Generated URLs contained ${'$'}{baseUrl} (literal text) instead of ${baseUrl} (interpolation). Every HTTP request was sent to a URL starting with the literal string ${baseUrl} instead of the actual base URL value.
  • Spurious if (body != null) on bodyless endpoints: Endpoints without a request body (GETs, DELETEs, etc.) emitted if (body != null) { contentType(Json); setBody(body) }. Since there was no body function parameter, body resolved to HttpRequestBuilder.body (Ktor internals, always non-null), adding a Content-Type: application/json header to every bodyless request.
  • Bumps snapshot version to 0.0.3-SNAPSHOT.

Test plan

  • New test: endpoint without requestBody does not generate body null check
  • New test: generated URL interpolates baseUrl property
  • All existing tests pass
  • ktlint clean

🤖 Generated with Claude Code

baseUrl was rendered as literal text (${'$'}{baseUrl}) instead of being
interpolated, so generated HTTP clients never substituted the actual URL.
Endpoints without a request body incorrectly emitted `if (body != null)`
which resolved to HttpRequestBuilder.body and added a JSON Content-Type
header to every bodyless request.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 10, 2026 08:53
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 10, 2026

Coverage Report

Overall Project 96.54% 🍏
Files changed 100% 🍏

File Coverage
BodyGenerator.kt 95.78% 🍏

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

Fixes two codegen issues in the Ktor client generator: (1) baseUrl was being emitted as a literal string template (\${'$'}{baseUrl}) instead of a real interpolation, and (2) bodyless endpoints were incorrectly emitting if (body != null) { ... setBody(body) ... } due to resolving body to HttpRequestBuilder.body.

Changes:

  • Guard JSON body emission so contentType(Json)/setBody(body) is generated only when endpoint.requestBody != null.
  • Rework URL template construction so generated request URLs correctly interpolate baseUrl (and path params).
  • Add targeted generator tests for both regressions and bump snapshot version to 0.0.3-SNAPSHOT.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.

File Description
core/src/main/kotlin/com/avsystem/justworks/core/gen/client/BodyGenerator.kt Fixes body emission for bodyless endpoints and corrects baseUrl interpolation in generated URL string templates.
core/src/test/kotlin/com/avsystem/justworks/core/gen/ClientGeneratorTest.kt Adds regression tests ensuring no body null-check is emitted without a request body and that URLs interpolate baseUrl.
build.gradle.kts Bumps default snapshot version to 0.0.3-SNAPSHOT.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@halotukozak halotukozak self-assigned this Apr 10, 2026
@halotukozak halotukozak requested a review from MattK97 April 10, 2026 09:01
@halotukozak halotukozak added this to the 0.0.2 milestone Apr 10, 2026
@halotukozak halotukozak merged commit 014b88b into master Apr 10, 2026
2 checks passed
@halotukozak halotukozak deleted the fixes-before-0.0.2 branch April 10, 2026 09:35
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.

3 participants