OpenAPITools / OpenAPITools/openapi-generator

[REQ] [C++][Pistache] Make getXXX() return reference.

Open
#4,218 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

The getXXX() functions in the generated models for the pistache server always return data by value. This is rather wasteful, especially when large subobjects are being passed around.

I.e. currently generated code looks like:

class  Animal {
  public:
    std::string getName () const;
}

It would be much better to return a const reference instead. This would avoid making any copies. It also shouldn't break any existing code.

I.e. improved code would be:

class  Animal {
  public:
    std::string const & getName () const;
}

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

Start by locating the generator templates for Pistache server models and the tests covering generated C++ getters. Confirm how the current getXXX() declarations and definitions are produced, then verify that generated getters return const references without breaking existing generated-code tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, openapi
Domain
api, backend-api-design
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 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.