I have an ENUM with some documentation about the values ("Description 1", "Description 2"):
ENUM(MyEnum, v_int32,
VALUE(VAL1, 3, "ME_VAL1", "Description 1"),
VALUE(VAL2, 7, "ME_VAL2", "Description 2")
)
I use it in a DTO:
class MyDto : public oatpp::DTO
{
DTO_INIT(MyDto, DTO)
DTO_FIELD(Enum<MyEnum>::AsString, myEnumProperty);
}
I know that it's not possible to display Enum documentation in Swagger. I want therefore to gather documentation of my Enum's programmatically and implement my own method to display this. I have tried out I can get this documentation as follows:
auto entries = oatpp::Enum<MyEnum>::getEntries();
for (size_t i = 0; i < entries.size(); i++)
{
printf("Name: %s\n", entries[i].name.std_str().c_str());
printf("Numeric value: %d\n", entries[i].value);
printf("Description: %s\n", entries[i].description.std_str().c_str());
}
But my problem is there are a lot of Enum's defined in my project and I want to automate gathering documentation for them. So I don't want to explicitly state "I want documentation for MyEnum", but traverse the list of my endpoints and their documentation, much like the oatpp-swagger module does when composing the web page. So I have used code from Generator.cpp as an example and can successfully list all my Enums used in the project. But what I can't do is get the documentation.
I can though print all the String values used by the Enum:
void printInterpretedEnum(const oatpp::Type *type)
{
auto polymorphicDispatcher = static_cast<const oatpp::data::mapping::type::__class::AbstractEnum::PolymorphicDispatcher*>(type->polymorphicDispatcher);
auto interEnum = polymorphicDispatcher->getInterpretedEnum();
for (auto &v : interEnum)
{
auto str = (v.retrieve(v.getStoredType())).cast<oatpp::String>();
printf("Enum value as string: %s\n", str->c_str());
}
}
So the code above would print:
Enum value as string: ME_VAL1
Enum value as string: ME_VAL2
So to conclude my question: by having the variable "const oatpp::Type *type" (as in the code just above), is there a possibility to retrieve the description fields defined with the ENUM macro? Additionally - if possible, I would also like to retrieve the numeric values (3 and 7) also defined by the ENUM macro.
Or is this possible only by specifically hardcoding MyEnum (and all the other Enum types used) into my source code?