Skip to content
New issue

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

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

Already on GitHub? # to your account

[C][Client] Convert integer/boolean to string for query parameter in request url #6652

Merged
merged 2 commits into from
Jun 18, 2020
Merged

Conversation

ityuhui
Copy link
Contributor

@ityuhui ityuhui commented Jun 14, 2020

If the data type of query parameter is "int" or "bool" in OpenAPI Spec, the request url will not be right generated by c-libcurl.

For example, in the function

CoreV1API_listNamespacedPod(..., int limit ,... )
{
...
    // query parameters
    char *keyQuery_limit = NULL;
    int valueQuery_limit ;
    keyValuePair_t *keyPairQuery_limit = 0;
    if (limit)
    {
        keyQuery_limit = strdup("limit");
        valueQuery_limit = (limit);
        keyPairQuery_limit = keyValuePair_create(keyQuery_limit, &valueQuery_limit);  <-- limit is only be referred as int *
        list_addElement(localVarQueryParameters,keyPairQuery_limit);
    }

but in the function

char *assembleTargetUrl(char    *basePath,
                        char    *operationParameter,
                        list_t    *queryParameters) {
    if(queryParameters != NULL) {
        strcat(targetUrl, "?");
        list_ForEach(listEntry, queryParameters) {
            keyValuePair_t *pair = listEntry->data;
            replaceSpaceWithPlus(pair->key);
            strcat(targetUrl, pair->key);
            strcat(targetUrl, "=");
            replaceSpaceWithPlus(pair->value);
            strcat(targetUrl, pair->value);    <=== valueQuery_limit is not a char *, so this is wrong.
            if(listEntry->nextListEntry != NULL) {
                strcat(targetUrl, "&");
            }
        }
    }

If we call

CoreV1API_listNamespacedPod(...
                                           10,   /* limit */
...);

the targetUrl becomes:

"https://ip:6443/api/v1/namespaces/default/pods?limit=P.xUUU"

My fix is converting the parameter to string

    // query parameters
    char *keyQuery_limit = NULL;
    char * valueQuery_limit = NULL;
    keyValuePair_t *keyPairQuery_limit = 0;
    if (limit)
    {
        keyQuery_limit = strdup("limit");
        valueQuery_limit = calloc(1,MAX_NUMBER_LENGTH);
        snprintf(valueQuery_limit, MAX_NUMBER_LENGTH, "%d", limit);
        keyPairQuery_limit = keyValuePair_create(keyQuery_limit, valueQuery_limit);
        list_addElement(localVarQueryParameters,keyPairQuery_limit);
    }

the targetUrl now is right:

"https://ip:6443/api/v1/namespaces/default/pods?list=10"

PR checklist

  • Read the contribution guidelines.
  • If contributing template-only or documentation-only changes which will change sample output, build the project beforehand.
  • Run the shell script ./bin/generate-samples.shto update all Petstore samples related to your fix. 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/config/java*. For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

@zhemant @michelealbano

@auto-labeler
Copy link

auto-labeler bot commented Jun 14, 2020

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@wing328
Copy link
Member

wing328 commented Jun 14, 2020

When you've time, please merge the latest master into this branch to address the Drone.io CI failrue.

@wing328 wing328 added this to the 5.0.0 milestone Jun 14, 2020
@ityuhui
Copy link
Contributor Author

ityuhui commented Jun 14, 2020

When you've time, please merge the latest master into this branch to address the Drone.io CI failrue.

Done.

@ityuhui
Copy link
Contributor Author

ityuhui commented Jun 18, 2020

Hi @zhemant @michelealbano @wing328

Could you please review this code change if you have time ?

Thanks

Copy link
Member

@wing328 wing328 left a comment

Choose a reason for hiding this comment

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

LGTM

@wing328 wing328 merged commit b86f6c8 into OpenAPITools:master Jun 18, 2020
@ityuhui
Copy link
Contributor Author

ityuhui commented Jun 18, 2020

Thank you @wing328

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

Successfully merging this pull request may close these issues.

2 participants