OpenAPITools / OpenAPITools/openapi-generator
[JavaSpring] Import conflict with generated model and one of the libraries of same name
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
I have a schema named 'ResponseEntity'. The model class gets generated with the same name.
This conflicts with the ResponseEntiy class of Springframework and gives an error
error: a type with the same simple name is already defined by the single-type-import of ResponseEntity
import org.springframework.http.ResponseEntity;
API File:
default ResponseEntity myClass() {
// code
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
Here, the func return-type ResponseEntity is from org.springframework.http.ResponseEntity
whereas the Generic type(one in the <>) ResponseEntity is my model class.
Discarded approaches:
- I do not want to use importmappings to create an external model and map it to the ResponseEntity model. This will create issues on changing the swagger schema.
- I cannot add Suffix/Prefix to all the generated models.
Is there a way such that?
- I can add Suffix/Prefix to only that particular generated model.
- Any workaround to never let the class 'org.springframework.http.ResponseEntity' be imported. I will add this in the ResponseEntity method of api.mustache class as a prefix.
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 the Java Spring generator's api.mustache template and reproduce the conflict using a schema containing a ResponseEntity model. Trace how the generated return type and imports are assembled, then verify that generation produces compilable code without the name collision while retaining the schema model.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring
- Domain
- backend, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100