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

[java client, gson] Expose @SerializedName value as constant #21

Closed
jmini opened this issue May 13, 2018 · 1 comment
Closed

[java client, gson] Expose @SerializedName value as constant #21

jmini opened this issue May 13, 2018 · 1 comment

Comments

@jmini
Copy link
Member

jmini commented May 13, 2018

Sometimes when you are writing tests for an API (with Rest-Assured in my case) you can not use the fluent API to build request, because you want to create an alternative request (malformed, corner case...)

You can use rest-assured RequestSpecBuilder for that. You then write code like this:

        final String updateBody = "{"
                + "\"id\": \"" + req.getId() + "\", "
                + "\"version\": \"" + req.getVersion() + "\", "
                + "\"name\": \"" + req.getName() + "\", "
                + "\"billingAddressId\": null, "
                + "\"contactAddressId\": null, "
                + "\"metadata\": null}";

        final Account account = createSuperAdminApi().accountsUpdate().simulateQuery(true)
                .reqSpec(b -> b.setBody(updateBody))
                .executeAs(r -> r.thenReturn());

I would be great instead of hard-coding the json member like this, to be able to reference constants:

        final String updateBody = "{"
                + "\""+ Acount.SERIALIZED_NAME_Id +"\": \"" + req.getId() + "\", "
                + "\""+ Acount.SERIALIZED_NAME_Version +"\": \"" + req.getVersion() + "\", "
                + "\""+ Acount.SERIALIZED_NAME_Name +"\": \"" + req.getName() + "\", "
                + "\""+ Acount.SERIALIZED_NAME_BillingAddressId +"\": null, "
                + "\""+ Acount.SERIALIZED_NAME_ContactAddressId +"\": null, "
                + "\"metadata\": null}";

This way, when the API evolves, the Java compiler indicates that something needs to be changed in the test case (the same way that the fluent api is also changed).

jmini added a commit to jmini/openapi-generator that referenced this issue May 13, 2018
wing328 pushed a commit that referenced this issue May 13, 2018
* Java gson: add @SerializedName value as constant

Fix #21

* Run bin/java-petstore-all.sh
@jmini
Copy link
Member Author

jmini commented May 15, 2018

With #42, the constant will be more what a java developper would expect:

        final String updateBody = "{"
                + "\""+ Acount.SERIALIZED_NAME_ID +"\": \"" + req.getId() + "\", "
                + "\""+ Acount.SERIALIZED_NAME_VERSION +"\": \"" + req.getVersion() + "\", "
                + "\""+ Acount.SERIALIZED_NAME_NAME +"\": \"" + req.getName() + "\", "
                + "\""+ Acount.SERIALIZED_NAME_BILLING_ADDRESS_ID +"\": null, "
                + "\""+ Acount.SERIALIZED_NAME_CONTACT_ADDRESS_ID +"\": null, "
                + "\"metadata\": null}";

vvb pushed a commit to vvb/openapi-generator that referenced this issue Jun 1, 2020
…roperties_jblack

Adds *args input to __init__ method to fix test testFruitNullValue
aserkes added a commit to aserkes/openapi-generator that referenced this issue May 30, 2022
* generator for Helidon SE server
* resolve merge conflicts
nilskuhn pushed a commit to nilskuhn/openapi-generator that referenced this issue Apr 6, 2023
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

1 participant