mirror of
https://github.com/HenkKalkwater/harbour-sailfin.git
synced 2025-04-07 13:12:40 +00:00
Update the generator to be able to handle the new challenges that arose with the new specification, namely: - Enums that do not start with a capital letter - Enums that contain a reserved keyword - Basic handling 'allOf' keys in properties Additionally, the comparison enum deserialisation is now case-insensitive.
41 lines
821 B
Handlebars
41 lines
821 B
Handlebars
{{className}}Class::{{className}}Class() {}
|
|
|
|
} // NS DTO
|
|
|
|
namespace Support {
|
|
|
|
using {{className}} = Jellyfin::DTO::{{className}};
|
|
|
|
template <>
|
|
|
|
{{className}} fromJsonValue(const QJsonValue &source, convertType<{{className}}>) {
|
|
if (!source.isString()) return {{className}}::EnumNotSet;
|
|
|
|
QString str = source.toString();
|
|
|
|
{{#each entries as |entry|}}
|
|
if (str == QStringLiteral("{{entry.value}}")) {
|
|
return {{className}}::{{entry.name}};
|
|
}
|
|
|
|
{{/each}}
|
|
|
|
return {{className}}::EnumNotSet;
|
|
}
|
|
|
|
template <>
|
|
QJsonValue toJsonValue(const {{className}} &source, convertType<{{className}}>) {
|
|
switch(source) {
|
|
|
|
{{#each entries as |entry|}}
|
|
case {{className}}::{{entry.name}}:
|
|
return QStringLiteral("{{entry.value}}");
|
|
|
|
{{/each}}
|
|
|
|
case {{className}}::EnumNotSet: // Fallthrough
|
|
default:
|
|
return QJsonValue();
|
|
}
|
|
}
|