Skip to content

[cpprestsdk] Bug: if block for setting localVarRequestHttpContentType for content type x-www-form-urlencoded is not generating #6994

@himadree-shekhar

Description

@himadree-shekhar
Description

I was trying to generate c++ REST SDK client for submitting form request.
However i noticed the generated API function code has following part:

std::unordered_set<utility::string_t> localVarConsumeHttpContentTypes;
localVarConsumeHttpContentTypes.insert(utility::conversions::to_string_t("application/x-www-form-urlencoded"));
     // JSON 
    if (localVarConsumeHttpContentTypes.size() == 0 || localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != localVarConsumeHttpContentTypes.end())
    {
        localVarRequestHttpContentType = utility::conversions::to_string_t("application/json");
    }
    // multipart formdata
    else if (localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != localVarConsumeHttpContentTypes.end())
    {
        localVarRequestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
    }  
    else
    {
        throw ApiException(415, utility::conversions::to_string_t("UserApi does not consume any supported media type"));
    }

So the generator is not adding code else-if for type "application/x-www-form-urlencoded".
So I have manually add an else-if block each time like below:
else if (localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/x-www-form-urlencoded")) != localVarConsumeHttpContentTypes.end())
{
    localVarRequestHttpContentType = utility::conversions::to_string_t("application/x-www-form-urlencoded");
}
I want the generator to generate such codes fo expected types. 
##### openapi-generator version 4.3.1

##### OpenAPI declaration file content 
here is a sample yaml code
```
/api/list/{modelID}/models':
    post:
      tags:
        models
      summary: submit model name.
      description: submit model name.
      operationId: postModelName.
      parameters:
        in: path
        name: modelID
        required: true
        schema:
          type: string
      requestBody:
        description: Sends the name.
        required: true
        content:
          application/x-www-form-urlencoded:
            schema:
              type: array
              items:
                type: object
              properties:
                name:
                  type: string
              required:
                - name
      responses:
        '201':
          description: returns model.
          content:
            application/json:
              schema:
                type: object
```





Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions