OpenAPITools / OpenAPITools/openapi-generator

[Bug][cpp-restsdk]Call extract_string() will not get correct string when media type is not "application/json"

Open
#12,349 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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](https://apidevtools.org/swagger-parser/online/))?
  • [ ✓ ] Have you tested with the latest master to confirm the issue still exists?
  • [ ✓ ] Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

1.CPP-RESTSDK will extract string with default input parm : ignore_content_type = false https://github.com/microsoft/cpprestsdk/blob/master/Release/include/cpprest/http_msg.h#L613-L619
2.When a json has a customed content type , the content type validation will cause the extract string get incorrect value.

3.Additional,As https://en.wikipedia.org/wiki/Media_type says , there is common content type like "application/json" and also other customed content type , which only need to follow the standards.

Why this will cause incorrect value , jump to the code ,we see :

https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/api-source.mustache#L309

openapi-generator version

master , 5.4.0

Suggest a fix

For 2. ,suggest hard code the extract_string(true)

https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/api-source.mustache#L309

return localVarResponse.extract_string(true);

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/api-source.mustache around line 309 and review how extract_string() handles non-application/json media types. Update the generated call as suggested, then verify that generated C++ REST SDK clients extract the expected string for custom media types.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.