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++][Qt]Replace usage of QVariant with a more intuitive optional wrapper #8960

Conversation

etherealjoy
Copy link
Contributor

@etherealjoy etherealjoy commented Mar 12, 2021

Fixes #8934

Issue was due to Optional support with QVariant here #8733

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master, 5.1.x, 6.0.x
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Changes

  • QVariant cannot construct user types hence it is not suitable for all cases
  • A more intuitive approach is provided, which also shows the type of optional in the api instead of plain QVariant
  • Added handling of optional body

Function declaration now looks like this

void deletePet(const qint64 &pet_id, const OptionalParam<QString> &api_key = OptionalParam<QString>());
void updatePetWithForm(const qint64 &pet_id, const OptionalParam<QString> &name = OptionalParam<QString>(), 
           const OptionalParam<QString> &status = OptionalParam<QString>());

instead of this

void deletePet(const qint64 &pet_id, const QVariant &api_key = QVariant());
void updatePetWithForm(const qint64 &pet_id, const QVariant &name = QVariant(), const QVariant &status = QVariant());

User types are supported like this

    QList<OAIObject> list;
    QMap<QString, OAIObject> map;
    QList<QString> strl;
    list.append(OAIObject());
    api->notifyTopicV1(list);
    api->notifyTopicV1();
    api->notifyTopicV2();
    api->notifyTopicV2(map);
    api->notifyTopicV3();
    api->notifyTopicV3(strl);

cc @ravinikam @stkrwork @MartinDelille @muttleyxd

@xconverge
I had to rework this due to side effects, made a more simpler and intuitive approach.

@xconverge
Copy link
Contributor

xconverge commented Mar 12, 2021

LGTM, we probably should just use std::optional later but this works for now. Looks like it wasn't too bad as an incremental step on what I had done, sorry about that. The ability to sub in a hacky qvariant and not break peoples code obviously didn't fully work, better to find out sooner rather than later

You can remove the type information I put in the doxygen comments to supplement the qvariant downsides if you want to

@etherealjoy
Copy link
Contributor Author

LGTM, we probably should just use std::optional later but this works for now. Looks like it wasn't too bad as an incremental step on what I had done, sorry about that. The ability to sub in a hacky qvariant and not break peoples code obviously didn't fully work, better to find out sooner rather than later

std::optional would have same issue like QVariant

You can remove the type information I put in the doxygen comments to supplement the qvariant downsides if you want to

This is fine, the doxygen is still meaningful. From user point of view, the pass the parameters normally without bothering about the OptionalParam, construction will happen in the template automatically.

@etherealjoy etherealjoy force-pushed the use_optional_wrapper_instead_of_qvariant branch from 1e83411 to 9991679 Compare March 12, 2021 17:32
@xconverge
Copy link
Contributor

LGTM, we probably should just use std::optional later but this works for now. Looks like it wasn't too bad as an incremental step on what I had done, sorry about that. The ability to sub in a hacky qvariant and not break peoples code obviously didn't fully work, better to find out sooner rather than later

std::optional would have same issue like QVariant

You can remove the type information I put in the doxygen comments to supplement the qvariant downsides if you want to

This is fine, the doxygen is still meaningful. From user point of view, the pass the parameters normally without bothering about the OptionalParam, construction will happen in the template automatically.

Yep makes sense, it looks so straightforward and obvious now vs before when we were first considering QVariant vs std::optional. This looks great

@etherealjoy etherealjoy added this to the 5.1.0 milestone Mar 13, 2021
@xconverge
Copy link
Contributor

:/ thanks for the cleanup @etherealjoy I had been using master successfully for the past few days without seeing these issues

@etherealjoy etherealjoy merged commit fcab513 into OpenAPITools:master Mar 15, 2021
@wing328
Copy link
Member

wing328 commented Mar 22, 2021

@etherealjoy thanks for the PR, which has been included in the v5.1.0 release: https://twitter.com/oas_generator/status/1373636654024380423

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Generator Qt5 - QStringList parameter fails
3 participants