@@ -741,10 +741,8 @@ using namespace )cpp"
741741
742742 pendingSeparator.add ();
743743
744- std::unordered_set<std::string_view> outputEnumNames;
745744 std::unordered_set<std::string_view> outputModifiedVariableEnum;
746745 std::unordered_set<std::string_view> outputModifiedVariableInput;
747- std::unordered_set<std::string_view> outputEnumValues;
748746 std::unordered_set<std::string_view> outputModifiedResponseEnum;
749747
750748 for (const auto & operation : operations)
@@ -762,48 +760,39 @@ using namespace )cpp"
762760 continue ;
763761 }
764762
765- if (outputEnumNames.insert (cppType).second )
766- {
767- pendingSeparator.reset ();
763+ pendingSeparator.reset ();
768764
769- const auto & enumValues = enumType->enumValues ();
765+ const auto & enumValues = enumType->enumValues ();
770766
771- sourceFile << R"cpp( static const std::array<std::string_view, )cpp"
772- << enumValues.size () << R"cpp( > s_names)cpp" << cppType
773- << R"cpp( = {)cpp" ;
767+ sourceFile << R"cpp( template <>
768+ response::Value Variable<)cpp"
769+ << cppType << R"cpp( >::serialize()cpp" << cppType << R"cpp( && value)
770+ {
771+ static const std::array<std::string_view, )cpp"
772+ << enumValues.size () << R"cpp( > s_names = {)cpp" ;
774773
775- bool firstValue = true ;
774+ bool firstValue = true ;
776775
777- for (const auto & enumValue : enumValues)
776+ for (const auto & enumValue : enumValues)
777+ {
778+ if (!firstValue)
778779 {
779- if (!firstValue)
780- {
781- sourceFile << R"cpp( ,)cpp" ;
782- }
783-
784- firstValue = false ;
785- sourceFile << R"cpp(
786- R"gql()cpp" << enumValue->name ()
787- << R"cpp( )gql"sv)cpp" ;
788- pendingSeparator.add ();
780+ sourceFile << R"cpp( ,)cpp" ;
789781 }
790782
791- pendingSeparator.reset ();
792- sourceFile << R"cpp( };
793-
794- )cpp" ;
783+ firstValue = false ;
784+ sourceFile << R"cpp(
785+ R"gql()cpp" << enumValue->name ()
786+ << R"cpp( )gql"sv)cpp" ;
787+ pendingSeparator.add ();
795788 }
796789
797790 pendingSeparator.reset ();
791+ sourceFile << R"cpp( };
798792
799- sourceFile << R"cpp( template <>
800- response::Value Variable<)cpp"
801- << cppType << R"cpp( >::serialize()cpp" << cppType << R"cpp( && value)
802- {
803793 response::Value result { response::Type::EnumValue };
804794
805- result.set<std::string>(std::string { s_names)cpp"
806- << cppType << R"cpp( [static_cast<size_t>(value)] });
795+ result.set<std::string>(std::string { s_names[static_cast<size_t>(value)] });
807796
808797 return result;
809798}
@@ -862,58 +851,10 @@ response::Value Variable<)cpp"
862851 continue ;
863852 }
864853
865- if (outputEnumValues.insert (cppType).second )
866- {
867- pendingSeparator.reset ();
868-
869- const auto & enumValues = enumType->enumValues ();
870-
871- sourceFile << R"cpp( static const std::array<std::pair<std::string_view, )cpp"
872- << cppType << R"cpp( >, )cpp" << enumValues.size ()
873- << R"cpp( > s_values)cpp" << cppType << R"cpp( = {)cpp" ;
874-
875- std::vector<std::pair<std::string_view, std::string_view>> sortedValues (
876- enumValues.size ());
877-
878- std::transform (enumValues.cbegin (),
879- enumValues.cend (),
880- sortedValues.begin (),
881- [](const auto & value) noexcept {
882- return std::make_pair (value->name (),
883- SchemaLoader::getSafeCppName (value->name ()));
884- });
885- std::sort (sortedValues.begin (),
886- sortedValues.end (),
887- [](const auto & lhs, const auto & rhs) noexcept {
888- return internal::shorter_or_less {}(lhs.first , rhs.first );
889- });
890-
891- bool firstValue = true ;
892-
893- for (const auto & enumValue : sortedValues)
894- {
895- if (!firstValue)
896- {
897- sourceFile << R"cpp( ,)cpp" ;
898- }
899-
900- firstValue = false ;
901- sourceFile << R"cpp(
902- std::make_pair(R"gql()cpp" << enumValue.first
903- << R"cpp( )gql"sv, )cpp" << cppType << R"cpp( ::)cpp"
904- << enumValue.second << R"cpp( ))cpp" ;
905- pendingSeparator.add ();
906- }
907-
908- pendingSeparator.reset ();
909- sourceFile << R"cpp( };
910- )cpp" ;
911-
912- pendingSeparator.add ();
913- }
914-
915854 pendingSeparator.reset ();
916855
856+ const auto & enumValues = enumType->enumValues ();
857+
917858 sourceFile << R"cpp( template <>
918859)cpp" << cppType << R"cpp( Response<)cpp"
919860 << cppType << R"cpp( >::parse(response::Value&& value)
@@ -924,9 +865,48 @@ response::Value Variable<)cpp"
924865 << enumType->name () << R"cpp( value)ex" };
925866 }
926867
868+ static const std::array<std::pair<std::string_view, )cpp"
869+ << cppType << R"cpp( >, )cpp" << enumValues.size ()
870+ << R"cpp( > s_values = {)cpp" ;
871+
872+ std::vector<std::pair<std::string_view, std::string_view>> sortedValues (
873+ enumValues.size ());
874+
875+ std::transform (enumValues.cbegin (),
876+ enumValues.cend (),
877+ sortedValues.begin (),
878+ [](const auto & value) noexcept {
879+ return std::make_pair (value->name (),
880+ SchemaLoader::getSafeCppName (value->name ()));
881+ });
882+ std::sort (sortedValues.begin (),
883+ sortedValues.end (),
884+ [](const auto & lhs, const auto & rhs) noexcept {
885+ return internal::shorter_or_less {}(lhs.first , rhs.first );
886+ });
887+
888+ bool firstValue = true ;
889+
890+ for (const auto & enumValue : sortedValues)
891+ {
892+ if (!firstValue)
893+ {
894+ sourceFile << R"cpp( ,)cpp" ;
895+ }
896+
897+ firstValue = false ;
898+ sourceFile << R"cpp(
899+ std::make_pair(R"gql()cpp"
900+ << enumValue.first << R"cpp( )gql"sv, )cpp" << cppType << R"cpp( ::)cpp"
901+ << enumValue.second << R"cpp( ))cpp" ;
902+ pendingSeparator.add ();
903+ }
904+
905+ pendingSeparator.reset ();
906+ sourceFile << R"cpp( };
907+
927908 const auto result = internal::sorted_map_lookup<internal::shorter_or_less>(
928- s_values)cpp" << cppType
929- << R"cpp( ,
909+ s_values,
930910 std::string_view { value.get<std::string>() });
931911
932912 if (!result)
0 commit comments