You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Model class generation for Pistache server C++ generator can be vastly improved. This changes, though, break with existing code but also get rid of unnecessary polymorphism and code complexity. Since this is a C++ language feature, other C++ code generators could leverage this improvement as well.
Describe the solution you'd like
Existing generated code relies on nlohmann::json library to serialize and deserialize bewteen JSON and real objects. This library provides the necessary mechanisms to perform those translations with free functions, leaving the model datatypes with a clean interface (no more fromJson and toJson).
Since nlohmann::json already provides proper overloads for basic datatypes such as std::string and int32_t, it is not necessary to worry about them, the nlohmann::basic_json::operator= will call the proper function.
This method handles composes really well. We can have other definitions containing errors without the necessity of re-implementing the serialization again (from this point on we handle an Error instance serialization/deserialization as we do here with std::string and int32_t, providing we include Error.hpp. It can also leverage enumerations (which if I remember correctly are not supported).
This method does not rely on RTTI, hence the runtime type information, virtual tables and the implicit vtable pointer are not necessary any more.
I made this extension myself to the previous swagger-codegen a year ago, but I'm keen to contribute with this improvement and enumeration support if it raises enough interest from the maintainers.
The text was updated successfully, but these errors were encountered:
@xurxoham thanks for the suggestion. Given that you've already made the extensions, what about submitting a PR to start with so that we can review the enhancement more easily?
Is your feature request related to a problem? Please describe.
Model class generation for Pistache server C++ generator can be vastly improved. This changes, though, break with existing code but also get rid of unnecessary polymorphism and code complexity. Since this is a C++ language feature, other C++ code generators could leverage this improvement as well.
Describe the solution you'd like
Existing generated code relies on
nlohmann::json
library to serialize and deserialize bewteen JSON and real objects. This library provides the necessary mechanisms to perform those translations with free functions, leaving the model datatypes with a clean interface (no morefromJson
andtoJson
).Example:
error.yaml
:Generated code:
Error.hpp
:Error.cpp
:Since
nlohmann::json
already provides proper overloads for basic datatypes such asstd::string
andint32_t
, it is not necessary to worry about them, thenlohmann::basic_json::operator=
will call the proper function.This method handles composes really well. We can have other definitions containing errors without the necessity of re-implementing the serialization again (from this point on we handle an
Error
instance serialization/deserialization as we do here withstd::string
andint32_t
, providing we includeError.hpp
. It can also leverage enumerations (which if I remember correctly are not supported).This method does not rely on RTTI, hence the runtime type information, virtual tables and the implicit vtable pointer are not necessary any more.
I made this extension myself to the previous
swagger-codegen
a year ago, but I'm keen to contribute with this improvement and enumeration support if it raises enough interest from the maintainers.The text was updated successfully, but these errors were encountered: