OpenAPITools / OpenAPITools/openapi-generator
[BUG] [scala-sttp] Generated code fails to compile when multipart/form-data includes the required fields
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
Generated code fails to compile when the requestbody of multipart/form-data includes the required field(s).
openapi-generator version
The version 6.x.x and the latest master branch (6.3.0).
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: multipart requestBody
version: '1.0'
paths:
/translations/upload:
post:
operationId: translations_upload
parameters:
- description: Client Instance Uuid.
explode: false
in: path
name: client_instance_uuid
required: true
schema:
format: uuid
type: string
style: simple
requestBody:
content:
multipart/form-data:
encoding:
translation_file:
style: form
schema:
$ref: '#/components/schemas/translations_upload_request'
responses:
"200":
content:
application/json:
schema:
format: binary
type: string
summary: Upload translations
x-content-type: multipart/form-data
x-accepts: application/json
components:
schemas:
translations_upload_request:
properties:
translation_file:
description: Gets or sets translation file (json/zip).
format: binary
type: string
required:
- translation_file
type: object
Generation Details
Command line used for generation:
openapi-generator-cli generate \
-g scala-sttp \
-i name_of_file.yaml \
-p mainPackage=myPackage \
-o myApi
Issues in the generated client:
No implicit view available from sttp.model.Part[sttp.client3.RequestBody[Any]] => scala.collection.IterableOnce[B].
def translationsUpload(clientInstanceUuid: UUID, translationFile: File
): Request[Either[ResponseException[String, Exception], File], Any] =
basicRequest
.method(Method.POST, uri"$baseUrl/translations/upload")
.contentType("multipart/form-data")
.multipartBody(Seq(
multipartFile("translation_file", translationFile)
).flatten) <---- compile error
.response(asJson[File])
}
Related issues/PRs
Suggest a fix
The issue seems in https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/scala-sttp/paramMultipartCreation.mustache#L1-L8
can someone review the template above?
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 with modules/openapi-generator/src/main/resources/scala-sttp/paramMultipartCreation.mustache and reproduce the issue using the provided openapi-generator-cli command and YAML specification. Inspect the generated Scala sttp client around multipartBody and verify that the generated code compiles when the multipart/form-data field is required.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, scala
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100