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
  • #3512
Closed
Open
Issue created Jul 31, 2019 by Administrator@rootContributor5 of 5 checklist items completed5/5 checklist items

[BUG] [cpprestsdk] multipart/related not correctly handled

Created by: CyrilleBenard

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
Description

The generator produces the code with the expected http content type but the corresponding code has not been generated, so that an exception is raised.

Generated code looks like :

pplx::task<utility::string_t> SMContextsCollectionApi::postSmContexts(std::shared_ptr<Inline_object> inlineObject)
{
 ../..
    std::unordered_set<utility::string_t> localVarConsumeHttpContentTypes;
    localVarConsumeHttpContentTypes.insert( utility::conversions::to_string_t("multipart/related") );

    std::shared_ptr<IHttpBody> localVarHttpBody;
    utility::string_t localVarRequestHttpContentType;

    // use JSON if possible
    if ( localVarConsumeHttpContentTypes.size() == 0 || localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != localVarConsumeHttpContentTypes.end() )
    {
        localVarRequestHttpContentType = utility::conversions::to_string_t("application/json");
        web::json::value localVarJson;

        localVarJson = ModelBase::toJson(inlineObject);
        localVarHttpBody = std::shared_ptr<IHttpBody>( new JsonBody( localVarJson ) );
    }
    // 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");
        std::shared_ptr<MultipartFormData> localVarMultipart(new MultipartFormData);

        if(inlineObject.get())
        {
            inlineObject->toMultipart(localVarMultipart, utility::conversions::to_string_t("inlineObject"));
        }

        localVarHttpBody = localVarMultipart;
        localVarRequestHttpContentType += utility::conversions::to_string_t("; boundary=") + localVarMultipart->getBoundary();
    }
    else
    {
        throw ApiException(415, utility::conversions::to_string_t("SMContextsCollectionApi->postSmContexts does not consume any supported media type"));
    }
../..
}

"multipart/related" is set correctly but just behind its set, there is no corresponding code so that the ApiException (415) is raised

openapi-generator version

4.0.0-SNAPSHOT - hash 4b414d81

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  version: 1.0.0
  title: Check generation of cpprest
  description: Internal ref filename is check_multipart-related.yaml

servers:
  - url: http://localhost:8080

paths:
  /sm-contexts:
    post:
      summary:  Create SM Context
      tags:
        - SM contexts collection
      operationId: PostSmContexts
      requestBody:
        description: representation of the SM context to be created in the SMF
        required: true
        content:
          multipart/related:
            schema:
              type: object
              properties: # Request parts
                dataMessage:
                  type: string

      responses:
        '200':
          description: Everythings gonna be alright
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Content"
        default:
          description: unexpected error


components:
  schemas:
    Content:
      type: string
Command line used for generation

openapi-generator-cli.sh generate -i ./openapi.yaml -g cpp-restsdk -o gen-cpp

Steps to reproduce

Just generate

Related issues/PRs

N/A

Suggest a fix

Generate the corresponding code (>_<) 😂

Assignee
Assign to
Time tracking