OpenAPITools / OpenAPITools/openapi-generator
[BUG] [cpprestsdk] multipart/related not correctly handled
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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 4b414d81d49ae21447d944cca1693a11bb0140dd
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 (>_<) 😂
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the provided OpenAPI declaration, the check_multipart-related.yaml case, and the cpp-restsdk command from openapi-generator-cli.sh. Trace request-body handling in the cpp-restsdk generator and compare multipart/related with multipart/form-data. Done means generated code handles multipart/related without raising ApiException 415.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100