Skip to content

Commit

Permalink
Merge pull request #336 from gitmodimo/issues-334
Browse files Browse the repository at this point in the history
Add enum value validation
  • Loading branch information
wravery authored Dec 7, 2024
2 parents b1a4d0a + b53247c commit 2cfdc5b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/SchemaGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>(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<std::size_t>(value)] } } } };
<< enumType.cppType << R"cpp([idx] } } } };
});
}
Expand Down

0 comments on commit 2cfdc5b

Please sign in to comment.