Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C++] Use 'const' for cpp getters even when the return type is an aggregate #1175

Open
alotia opened this issue Oct 4, 2018 · 3 comments
Open

Comments

@alotia
Copy link

alotia commented Oct 4, 2018

Description

We are using openapi-generator to generate C++ classes from Java. For primitive types, the C++ getter method has 'const' qualifier, but when aggregates are specified, the method does not have have the const qualifier. Can a 'const' be added for getter methods even when the return type is an aggregate? (I am not very familiar with C++, and maybe there is a reason this is not being done. And I am filing this on behalf of someone who mentioned that not having a const on these getters causes them some grief.)

Please Note: I had originally filed this issue against swagger-codegen (v2.2.3), and William Cheng had asked to try out the latest version of OpenAPI Generator, but it does not address the issue I had. He had then recommended that I file an issue in OpenAPI as well. For your reference, the swagger-codegen issue is: swagger-api/swagger-codegen#8770

openapi-generator version

We are using openapi-generator-maven-plugin v3.3.0
and openapi-generator v3.3.0

OpenAPI declaration file content or url
Command line used for generation

Using the openapi-generator-maven-plugin to generate the code. Please let me know if you need any additional info

Steps to reproduce

Please use the included sample Java code to generate a C++ class. If you need any additional info, please let me know.

Related issues/PRs

swagger-api/swagger-codegen#8770

Suggest a fix/enhancement
@wing328
Copy link
Member

wing328 commented Oct 5, 2018

cc @ravinikam (2017/07) @stkrwork (2017/07) @fvarose (2017/11) @etherealjoy (2018/02) @MartinDelille (2018/03)

@MartinDelille
Copy link
Contributor

@alotia We should definitely have const qualifiers on getters.

@etherealjoy
Copy link
Contributor

cpp-qt5-qhttpengine-server has const getter and const ref setters args

https://github.com/OpenAPITools/openapi-generator/blob/master/samples/server/petstore/cpp-qt5-qhttpengine-server/server/src/models/OAIOrder.h#L53

https://github.com/OpenAPITools/openapi-generator/blob/master/samples/server/petstore/cpp-qt5-qhttpengine-server/server/src/models/OAIOrder.h#L54

    QDateTime getShipDate() const;
    void setShipDate(const QDateTime &ship_date);

Sadly I fear breaking too much when applied to others.

@stkrwork stkrwork changed the title Use 'const' for cpp getters even when the return type is an aggregate [C++] Use 'const' for cpp getters even when the return type is an aggregate Oct 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants