Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #6994
Closed
Open
Issue created Jul 20, 2020 by Administrator@rootContributor

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

Created by: 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
```




Assignee
Assign to
Time tracking