Skip to content

Improve consumption of primitive types as body#23257

Merged
wing328 merged 4 commits intoOpenAPITools:masterfrom
noordawod:feature/body-scalar-type-improvement
Mar 15, 2026
Merged

Improve consumption of primitive types as body#23257
wing328 merged 4 commits intoOpenAPITools:masterfrom
noordawod:feature/body-scalar-type-improvement

Conversation

@noordawod
Copy link
Copy Markdown
Contributor

@noordawod noordawod commented Mar 15, 2026

Currently, the ApiClient for OkHttp allows sending textual body payloads (MIME=text/plain) only for Strings, but it can be easily adapted to send primitive types too: any character sequence, numbers, and booleans.

This small PR allows doing just that. If the content is not a primitive, then a suitable error is thrown instead.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@karismann (2019/03) @Zomzog (2019/04) @andrewemery (2019/10) @4brunu (2019/11) @yutaka0m (2020/03) @stefankoppier (2022/06) @e5l (2024/10) @dennisameling (2026/02)


Summary by cubic

Extend the Kotlin JVM OkHttp ApiClient to support text/plain bodies from primitive values (Char/CharSequence, Number, Boolean via toString); non-primitives now error clearly, logic is consolidated into a single when, and samples are regenerated.

Written for commit 40b7d40. Summary will update on new commits.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

10 issues found across 28 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt">

<violation number="1" location="samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt:279">
P2: `text/plain` primitive handling excludes `Char`, so single-character bodies still throw `UnsupportedOperationException`.</violation>
</file>

<file name="samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt">

<violation number="1" location="samples/client/echo_api/kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt:275">
P2: `text/plain` primitive handling claims character support but omits Kotlin `Char`, causing `Char` request bodies to throw.</violation>
</file>

<file name="samples/client/petstore/kotlin-allOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt">

<violation number="1" location="samples/client/petstore/kotlin-allOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt:275">
P2: `text/plain` body serialization excludes Kotlin `Char`, contradicting the stated support for characters and causing valid primitive payloads to throw.</violation>
</file>

<file name="samples/client/petstore/kotlin-name-parameter-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt">

<violation number="1" location="samples/client/petstore/kotlin-name-parameter-mappings/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt:275">
P2: `text/plain` primitive handling omits Kotlin `Char`, causing single-character bodies to throw `UnsupportedOperationException`.</violation>
</file>

<file name="samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt">

<violation number="1" location="samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt:275">
P2: `text/plain` primitive handling claims character support but rejects Kotlin `Char` at runtime.</violation>
</file>

<file name="samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt">

<violation number="1" location="samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt:275">
P2: `text/plain` primitive support claims to allow characters but omits Kotlin `Char`, causing valid single-character payloads to fail.</violation>
</file>

<file name="samples/client/others/kotlin-jvm-okhttp-parameter-tests/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt">

<violation number="1" location="samples/client/others/kotlin-jvm-okhttp-parameter-tests/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt:275">
P2: `text/plain` primitive-body handling omits Kotlin `Char`, causing runtime `UnsupportedOperationException` for single-character payloads.</violation>
</file>

<file name="samples/client/petstore/kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt">

<violation number="1" location="samples/client/petstore/kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt:275">
P2: `text/plain` primitive body handling omits Kotlin `Char`, so single-character payloads are rejected despite claiming character support.</violation>
</file>

<file name="samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt">

<violation number="1" location="samples/client/others/kotlin-jvm-okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt:275">
P2: `text/plain` primitive handling is incomplete: `Char` bodies are rejected because the new type checks omit `Char` even though the code claims to support characters.</violation>
</file>

<file name="samples/client/petstore/kotlin-bigdecimal-default-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt">

<violation number="1" location="samples/client/petstore/kotlin-bigdecimal-default-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt:275">
P2: `text/plain` primitive serialization omits Kotlin `Char`, causing runtime rejection despite claiming character support.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@wing328 wing328 added this to the 7.21.0 milestone Mar 15, 2026
@wing328 wing328 merged commit 7ddd693 into OpenAPITools:master Mar 15, 2026
69 checks passed
@wing328
Copy link
Copy Markdown
Member

wing328 commented Mar 15, 2026

thanks for the contribution, which has been merged

@noordawod noordawod deleted the feature/body-scalar-type-improvement branch March 15, 2026 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants