swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
After a long time using my original version of the cpprest generator, I decided to migrate finally to the official swagger-codegen version. We are using a somehow non-open-api-standard compliant feature: having files as model properties. This used to work in my original codebase but seemed to be broken since issue #3773 was fixed. Instead of generating:
Take given swagger specification and generate a cpprest client
Inspect the MyFileViewModel.cpp and notice the non-shared_ptr file property.
Compile the sources and there will be compilation errors for MyFileViewModel::fromJson as it cannot call setFile(HttpContent) with a shared_ptr<HttpContent> parameter.
Also a compile error on MyFileViewModel::toMultipart is shown as there is no ModelBase::toHttpContent(utility::string_t, HttpContent) overload. It needs a shared_ptr<HttpContent> as second parameter.
I expect that removing p instanceof FileProperty from the code follow source line will fix the issue by bringing back the shared_ptr<HttpContent>. Maybe @sdrichter can point out why it was added in a first place. His issue mentions something that there were issues on APIs which return a file object.
Description
After a long time using my original version of the cpprest generator, I decided to migrate finally to the official swagger-codegen version. We are using a somehow non-open-api-standard compliant feature: having files as model properties. This used to work in my original codebase but seemed to be broken since issue #3773 was fixed. Instead of generating:
...the following source is generated:
This in advance leads to errors when serializing/deserializing as the ModelBase only provides overloads for the shared_ptr.
Swagger-codegen version
2.2.3
Swagger declaration file content or url
https://gist.github.com/Danielku15/27d3604077fd325ba4dacf475a8fc66a
Command line used for generation
Steps to reproduce
MyFileViewModel::fromJson
as it cannot callsetFile(HttpContent)
with ashared_ptr<HttpContent>
parameter.MyFileViewModel::toMultipart
is shown as there is noModelBase::toHttpContent(utility::string_t, HttpContent)
overload. It needs ashared_ptr<HttpContent>
as second parameter.Related issues/PRs
https://github.com/swagger-api/swagger-codegen/issues/3773 https://github.com/swagger-api/swagger-codegen/pull/3876
Suggest a fix/enhancement
I expect that removing
p instanceof FileProperty
from the code follow source line will fix the issue by bringing back theshared_ptr<HttpContent>
. Maybe @sdrichter can point out why it was added in a first place. His issue mentions something that there were issues on APIs which return a file object.https://github.com/swagger-api/swagger-codegen/blob/8cc8c1eac6eba2770bca17ca6387bc0303756574/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CppRestClientCodegen.java#L308