OpenAPITools / OpenAPITools/openapi-generator

[Java client] add a way to duplicate an model class

Open
#1,606 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.