OpenAPITools / OpenAPITools/openapi-generator
[REQ] [cpprestsdk] ApiException is not used in the way it is generated
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Is your feature request related to a problem? Please describe.
The generator produces code that uses ApiException not in the way it has been intended. Ok, this is not exactly true but let me show what I mean thanks to the PetApi example :
In the file PetApi.cpp line 136 we can see one error treatment throwing an ApiException
if (localVarResponse.status_code() >= 400)
{
throw ApiException(localVarResponse.status_code()
, utility::conversions::to_string_t("error calling addPet: ") + localVarResponse.reason_phrase()
, std::make_shared<std::stringstream>(localVarResponse.extract_utf8string(true).get()));
}
The 3rd parameter of the ApiException is set with a std::make_shared<std::stringstream> whereas the ApiException shows the corresponding API with a std::shared_ptr<std::istream>
class ApiException
: public web::http::http_exception
{
public:
ApiException( int errorCode
, const utility::string_t& message
, std::shared_ptr<std::istream> content = nullptr );
../..
}
Of course this is allowed because a std::stringstream IS A std::istream but when I (the developer) want to handle an ApiException in my application, I retrieve "'only" an std::istream that is not really convenient to use whereas at the origin, the ApiException has been raised with a std::stringstream.
Describe the solution you'd like
What about modifying the ApiException and replace the use of std::istream with std::stringstream ?
Describe alternatives you've considered
N/A
Additional context
N/A
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
Start with samples/client/petstore/cpp-restsdk/client/ApiException.h and the generated use in samples/client/petstore/cpp-restsdk/client/api/PetApi.cpp around line 136. Trace these files back to the generator source that produces them, then inspect related C++ REST SDK tests. Done means the generated exception interface supports the content type requested in the issue and the generated client remains consistent.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- api
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100