OpenAPITools / OpenAPITools/openapi-generator
[BUG] `ApiClient.kt.mustache` calls `.toString()` method on a `ByteArray` when building multipart request
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
In the ApiClient.kt.mustache file during the creation of the request body the requestBody(content: T, mediaType: String?) method correctly builds a multipart/form request when part.body is File, but for all other data types the part is added to the request by calling the .toString() method on the part body:
addPart(
Headers.of(partHeaders),
RequestBody.create(null, parameterToString(part.body))
)
This results in the .toString() method being called on a ByteArray - which returns a string containing the class name, '@' symbol, and the hash code of the array object ("[B@7c67645b"), instead of the contents of the byte array.
openapi-generator version
v7.1.0
OpenAPI declaration file content or url
Generation Details
openapi: 3.0.1
info:
contact:
email: na@na.com
description: OpenAPI definitions
license:
name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html
termsOfService: https://terms.io/
title: API
version: 16.0.0
security:
- basicAuth: []
- bearerAuth: []
paths:
/path/to/resource:
post:
operationId: createReceipt
parameters:
- in: path
name: testId
required: true
schema:
type: string
format: uuid
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
file:
type: object
Steps to reproduce
From the given api spec, generate a Kotlin Api client and POST a ByteArray in the request.
Related issues/PRs
Suggest a fix
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache, especially requestBody(content: T, mediaType: String?) and the multipart addPart call around line 156. Reproduce the issue by generating a Kotlin client from the supplied multipart OpenAPI definition and posting a ByteArray; done means the request contains the byte array contents rather than its object representation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 62/100