Skip to content

Conversation

@ityuhui
Copy link
Contributor

@ityuhui ityuhui commented Dec 31, 2019

When a struct field in the generated c client is a C key word (e.g. continue), it should be escaped. This is implemented by the PR #4735.
But #4735 introduces an issue, that is the JSON key name in request/response body is also escaped.
e.g.

./model/v1_list_meta.c:    if(cJSON_AddStringToObject(item, "_continue", v1_list_meta->_continue) == NULL) {
./model/v1_list_meta.c:    cJSON *_continue = cJSON_GetObjectItemCaseSensitive(v1_list_metaJSON, "_continue");

This will cause logic error when API server processes the request/response body.
Actually the JOSN key name should not be escaped, e.g.

./model/v1_list_meta.c:    if(cJSON_AddStringToObject(item, "continue", v1_list_meta->_continue) == NULL) {
./model/v1_list_meta.c:    cJSON *_continue = cJSON_GetObjectItemCaseSensitive(v1_list_metaJSON, "continue");

PR checklist

  • Read the contribution guidelines.
  • If contributing template-only or documentation-only changes which will change sample output, build the project before.
  • Run the shell script(s) under ./bin/ (or Windows batch scripts under.\bin\windows) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the code or mustache templates for a language ({LANG}) (e.g. php, ruby, python, etc).
  • File the PR against the master: master, 4.3.x, 5.0.x. Default: master.
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

@wing328 @zhemant

@zhemant
Copy link
Contributor

zhemant commented Jan 1, 2020

I would like to suggest something, I had faced issue with the struct names, enum values being repeateded or the api contains same struct name but different internal parameters.

To overcome this add the complete name i.e. project name to make each variable, function unique. This has helped me to overcome a lot of issue. only problem is the length of variables increases. But it helps in enums(when two enums have same value, we get compile error in c if in same project) also when there are two structs with same name.

if (!("object".equals(name))) {
name = this.projectName + "_" + name;
}

This is the logic i have added in toModelName function in .java file. If you need to talk more, you can ping me on gitter.

@ityuhui
Copy link
Contributor Author

ityuhui commented Jan 2, 2020

Thank you @zhemant
Your suggestion is very helpful! I will try it when facing the name issue next time.

For this PR, it is used to fix the name that should not be escaped in REST request/response based on the #4735. I think it can be merged.

@wing328
Copy link
Member

wing328 commented Jan 2, 2020

@zhemant thanks for the review and the suggestion.

Agreed with @ityuhui that this PR is safe to be merged.

@wing328 wing328 merged commit 85f6ed5 into OpenAPITools:master Jan 2, 2020
@wing328 wing328 added this to the 4.2.3 milestone Jan 2, 2020
@ityuhui ityuhui deleted the yhworking branch January 2, 2020 07:31
jimschubert added a commit to jimschubert/openapi-generator that referenced this pull request Jan 5, 2020
* master: (275 commits)
  Initial CODEOWNERS (OpenAPITools#4924)
  [scala] Support for Set when array has uniqueItems=true (OpenAPITools#4926)
  remove nodejs server samples, scripts (OpenAPITools#4919)
  Added ability to work with `defaultHeaders` and fixed authentication for code generated by openapi-generator for typescript-node (OpenAPITools#4896)
  replace petstore_api with packageName (OpenAPITools#4921)
  remove base_object_spec.mustache from ruby client (OpenAPITools#4918)
  Add an link to Ada article (OpenAPITools#4920)
  avoid using hardcode prefix in example (OpenAPITools#4917)
  [dart-dio] Fix basepath (OpenAPITools#4911)
  [java][client] jackson update (OpenAPITools#4907)
  [Swift] Minor improvements to swift 5 generator (OpenAPITools#4910)
  [cpp-restbed] Added "out-of-the-box" functionality (OpenAPITools#4759)
  New generator swift5 (OpenAPITools#4086)
  [dart-dio] Adds support for multipart form data post body (OpenAPITools#4797)
  [go][client] fix when schema have multiple servers (OpenAPITools#4901)
  Unables CI tests of python-flask-python2 (OpenAPITools#4889)
  [C-libcurl] The JSON key name in request/response body should not be escaped even though it is a C key word. (OpenAPITools#4893)
  upgrade to JUnit 4.13 (OpenAPITools#4899)
  [r] Ignoring README.md in Rbuildignore (OpenAPITools#4898)
  update samples
  ...
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.

3 participants