OpenAPITools / OpenAPITools/openapi-generator
[Java client] add a way to duplicate an model class
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
There are scenario where being able to create a new instance of a model class with the same values as an other one is necessary.
Example:
Pet pet = api.getPetById().petIdPath(id).executeAs(r -> r.thenReturn());
Pet body = pet; // this should be a new instance of Pet, a copy with the same values.
pet.setName("New name");
api.updatePet().body(body).execute(r -> r.prettyPeek());
Pet pet2 = api.getPetById().petIdPath(id).executeAs(r -> r.thenReturn());
// here you need the pet instance as it was (without any modification)
// and pet2 to perform some assertions
I suggest to add two constructors to the models classes:
- An empty one (current behaviour)
- A constructor accepting an other instance of the same class
In the second case, the values will be copied.
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
The issue names no files or tests, so first locate the Java client model-generation entry point and any existing model-generation tests. Review how generated model classes are defined, then verify that generated models support both empty construction and copying values from another instance, with tests covering the copied values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100