diff --git a/src/SchemaGenerator.cpp b/src/SchemaGenerator.cpp index 87b17fb5..5c3fb8cd 100644 --- a/src/SchemaGenerator.cpp +++ b/src/SchemaGenerator.cpp @@ -1691,8 +1691,15 @@ service::AwaitableResolver Result<)cpp" []()cpp" << _loader.getSchemaNamespace() << R"cpp(::)cpp" << enumType.cppType << R"cpp( value, const ResolverParams&) { + const size_t idx = static_cast(value); + if (idx >= s_names)cpp" + << enumType.cppType << R"cpp(.size()) + { + throw service::schema_exception { { R"ex(Enum value out of range for )cpp" + << enumType.type << R"cpp()ex" } }; + } return ResolverResult { { response::ValueToken::EnumValue { std::string { s_names)cpp" - << enumType.cppType << R"cpp([static_cast(value)] } } } }; + << enumType.cppType << R"cpp([idx] } } } }; }); }