OpenAPITools / OpenAPITools/openapi-generator
[BUG][SPRING]compilation errors due to different request body type in api and apiDelegate files
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)?
- What's the version of OpenAPI Generator used?
- Have you search for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Bounty to sponsor the fix (example)
Description
We have encountered this problem
generated Api and ApiDelegate files have different request body types (Resource/MultipartFile), which is resulting in compilation errors.
Issue seemed to have addressed in v4.0.0-beta3 version, but issue still persists when we tried with the cli version of v4.0.0-beta3.
openapi-generator version
v4.0.2
OpenAPI declaration file content or url
openapi: 3.0.1
info:
title: testapp
version: 0.0.1
servers:
- url: 'http://localhost:8081/api'
description: Development server
paths:
'/foo':
post:
operationId: foo
requestBody:
content:
image/png:
schema:
type: string
format: binary
responses:
default:
description: successful operation
Command line used for generation
java -jar openapi-generator-cli.jar generate -g spring -i api.yml -o ./out --additional-properties delegatePattern=true
Steps to reproduce
- Run the command above with provided api.yml.
- Open out/src/main/java/org/openapitools/api/FooApi.java, look at generated
foomethod
default ResponseEntity<Void> foo(@ApiParam(value = "" ) @Valid @RequestBody Resource body) {
return getDelegate().foo(body);
}
- Open out/src/main/java/org/openapitools/api/FooApiDelegate.java, look at generated apiDelegate method
default ResponseEntity<Void> foo(MultipartFile body) {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
foo from FooApiDelegate consumes MultipartFile whereas FooApi passes Resource as request body type.
Related issues/PRs
Issue seemed to have addressed in v4.0.0-beta3 version per above PR, but issue still persists when we tried with the cli version of v4.0.0-beta3.
Suggest a fix
Use either Multipartfile or Resource in both api and apidelegate
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
Run the provided OpenAPI Generator command with api.yml, then compare the generated FooApi.java and FooApiDelegate.java methods. Trace how the request body type is selected for each generated file. Done means both methods use the same request body type and the generated Spring project compiles.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100