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][Client] Treat the data type "byteArray" same as "string" #10034

Merged
merged 1 commit into from
Jul 26, 2021

Conversation

ityuhui
Copy link
Contributor

@ityuhui ityuhui commented Jul 25, 2021

If the below data type exists in a OpenAPI spec,

        "data": {
          "additionalProperties": {
            "format": "byte",
            "type": "string"
          },

OpenAPI-Generator (the function isByteArraySchema in ModelUtils.java) will regard the data as a byteArray other than a string

But the model template (model-body.mustache) of CLibcurl generator cannot recognize the data type byteArray, so data will be ignored. This will introduces some problems. e.g. kubernetes-client/c#66

This PR adds the support for the data type byteArray to model-body.mustache, treats it same as the data type "string". (Actually, I copied the code from {{#isString}}...{{/isString}} ). And now the "data" can be generated.

Hi @wing328 @zhemant @michelealbano

Could you please review this PR ? Thanks.

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 master: master, 5.3.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.

@zhemant
Copy link
Contributor

zhemant commented Jul 25, 2021

@ityuhui Thank you for the PR. I have the following suggestion to make handling of bytearray correct/uniform.

  1. Could you please also add byteArray handling in convertToJson function as well?
    https://github.com/OpenAPITools/openapi-generator/blob/ae93625a1b27efaff9904c1d87cb8008661a9ddd/modules/openapi-generator/src/main/resources/C-libcurl/model-body.mustache#L475-L497
    So we handle both cases, parse from json and convert to json.
  2. In model mustache, I saw we were handling byte as number. So all the places in the template are as per numeric values which is clearly wrong as it should be string format as given here: https://swagger.io/docs/specification/data-models/data-types/
    Would it be possible for you to update those in this PR as well?

Thank You!

@ityuhui
Copy link
Contributor Author

ityuhui commented Jul 26, 2021

Thank you @zhemant

It's very helpful! I have addressed all your comments.

Copy link
Contributor

@zhemant zhemant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the fixes. LGTM

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.

None yet

3 participants