OpenAPITools / OpenAPITools/openapi-generator
[BUG] [kotlin-spring] wrong field name and type for multipart
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
Code generator "kotlin-spring" generates incorrect field names and types for requestBody "multipart/form-data". All parts which are defines of type string and format binary gets name "file" and type "org.springframework.core.io.Resource".
The same code is generated correct with generator "spring". All parts gets correct name and type of "MultipartFile".
Here is the result of generated file:
@RequestMapping(
method = [RequestMethod.PUT],
value = ["/test"],
produces = ["application/json"],
consumes = ["multipart/form-data"]
)
fun saveResource(acceptLanguage: kotlin.String, @Valid @RequestPart("file") myImages: kotlin.collections.List<org.springframework.core.io.Resource>, @RequestParam(value = "jsonObject", required = true) jsonObject: JsonObjectDto, @Valid @RequestPart("file") image1: org.springframework.core.io.Resource?, @Valid @RequestPart("file") image2: org.springframework.core.io.Resource?): ResponseEntity<JsonObjectDto> {
return ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
}
openapi-generator version
"org.openapitools":"openapi-generator-maven-plugin":"6.5.0"
OpenAPI declaration file content
/test:
put:
operationId: saveResource
parameters:
- name: Accept-Language
in: header
schema:
type: string
required: true
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
image1:
type: string
format: binary
image2:
type: string
format: binary
myImages:
type: array
maxItems: 10
items:
type: string
format: binary
jsonObject:
$ref: '#/components/schemas/JsonObjectDto'
required:
- jsonObject
- myImages
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/JsonObjectDto'
components:
schemas:
JsonObjectDto:
type: object
properties:
id:
type: string
name:
type: string
Generation Details
generated using maven plugin
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>6.5.0</version>
<executions>
<execution>
<id>gen-svc-models</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/myapp.yaml</inputSpec>
<generatorName>kotlin-spring</generatorName>
<configOptions>
<useTags>true</useTags>
<basePackage>com.mypackage</basePackage>
<apiPackage>com.mypackage.api</apiPackage>
<modelPackage>com.mypackage.model</modelPackage>
<configPackage>com.mypackage.config</configPackage>
<documentationProvider>none</documentationProvider>
<exceptionHandler>false</exceptionHandler>
<interfaceOnly>true</interfaceOnly>
<enumPropertyNaming>UPPERCASE</enumPropertyNaming>
<useSpringBoot3>true</useSpringBoot3>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
Steps to reproduce
Attempting to generate kotling spring interface using given maven plugin and contract generates incorrect types and names of multipart.
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
No repository file or test is named. First reproduce the issue with the supplied OpenAPI declaration using the kotlin-spring generator, then compare its multipart output with the spring generator. Done means each binary part retains its declared name and uses the expected multipart type.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin, openapi, spring
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100