Skip to content

Commit e48538f

Browse files
committed
chore: regenerate samples with enum validation
1 parent 2cfdc5b commit e48538f

File tree

7 files changed

+66
-8
lines changed

7 files changed

+66
-8
lines changed

samples/learn/schema/StarWarsSharedTypes.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,14 @@ service::AwaitableResolver Result<learn::Episode>::convert(service::AwaitableSca
5050
return ModifiedResult<learn::Episode>::resolve(std::move(result), std::move(params),
5151
[](learn::Episode value, const ResolverParams&)
5252
{
53-
return ResolverResult { { response::ValueToken::EnumValue { std::string { s_namesEpisode[static_cast<std::size_t>(value)] } } } };
53+
const size_t idx = static_cast<size_t>(value);
54+
55+
if (idx >= s_namesEpisode.size())
56+
{
57+
throw service::schema_exception { { R"ex(Enum value out of range for Episode)ex" } };
58+
}
59+
60+
return ResolverResult { { response::ValueToken::EnumValue { std::string { s_namesEpisode[idx] } } } };
5461
});
5562
}
5663

samples/proxy/schema/ProxySharedTypes.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,14 @@ service::AwaitableResolver Result<proxy::OperationType>::convert(service::Awaita
5050
return ModifiedResult<proxy::OperationType>::resolve(std::move(result), std::move(params),
5151
[](proxy::OperationType value, const ResolverParams&)
5252
{
53-
return ResolverResult { { response::ValueToken::EnumValue { std::string { s_namesOperationType[static_cast<std::size_t>(value)] } } } };
53+
const size_t idx = static_cast<size_t>(value);
54+
55+
if (idx >= s_namesOperationType.size())
56+
{
57+
throw service::schema_exception { { R"ex(Enum value out of range for OperationType)ex" } };
58+
}
59+
60+
return ResolverResult { { response::ValueToken::EnumValue { std::string { s_namesOperationType[idx] } } } };
5461
});
5562
}
5663

samples/today/nointrospection/TodaySharedTypes.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,14 @@ service::AwaitableResolver Result<today::TaskState>::convert(service::AwaitableS
5050
return ModifiedResult<today::TaskState>::resolve(std::move(result), std::move(params),
5151
[](today::TaskState value, const ResolverParams&)
5252
{
53-
return ResolverResult { { response::ValueToken::EnumValue { std::string { s_namesTaskState[static_cast<std::size_t>(value)] } } } };
53+
const size_t idx = static_cast<size_t>(value);
54+
55+
if (idx >= s_namesTaskState.size())
56+
{
57+
throw service::schema_exception { { R"ex(Enum value out of range for TaskState)ex" } };
58+
}
59+
60+
return ResolverResult { { response::ValueToken::EnumValue { std::string { s_namesTaskState[idx] } } } };
5461
});
5562
}
5663

samples/today/schema/TodaySharedTypes.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,14 @@ service::AwaitableResolver Result<today::TaskState>::convert(service::AwaitableS
5050
return ModifiedResult<today::TaskState>::resolve(std::move(result), std::move(params),
5151
[](today::TaskState value, const ResolverParams&)
5252
{
53-
return ResolverResult { { response::ValueToken::EnumValue { std::string { s_namesTaskState[static_cast<std::size_t>(value)] } } } };
53+
const size_t idx = static_cast<size_t>(value);
54+
55+
if (idx >= s_namesTaskState.size())
56+
{
57+
throw service::schema_exception { { R"ex(Enum value out of range for TaskState)ex" } };
58+
}
59+
60+
return ResolverResult { { response::ValueToken::EnumValue { std::string { s_namesTaskState[idx] } } } };
5461
});
5562
}
5663

samples/validation/schema/ValidationSharedTypes.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,14 @@ service::AwaitableResolver Result<validation::DogCommand>::convert(service::Awai
5050
return ModifiedResult<validation::DogCommand>::resolve(std::move(result), std::move(params),
5151
[](validation::DogCommand value, const ResolverParams&)
5252
{
53-
return ResolverResult { { response::ValueToken::EnumValue { std::string { s_namesDogCommand[static_cast<std::size_t>(value)] } } } };
53+
const size_t idx = static_cast<size_t>(value);
54+
55+
if (idx >= s_namesDogCommand.size())
56+
{
57+
throw service::schema_exception { { R"ex(Enum value out of range for DogCommand)ex" } };
58+
}
59+
60+
return ResolverResult { { response::ValueToken::EnumValue { std::string { s_namesDogCommand[idx] } } } };
5461
});
5562
}
5663

@@ -102,7 +109,14 @@ service::AwaitableResolver Result<validation::CatCommand>::convert(service::Awai
102109
return ModifiedResult<validation::CatCommand>::resolve(std::move(result), std::move(params),
103110
[](validation::CatCommand value, const ResolverParams&)
104111
{
105-
return ResolverResult { { response::ValueToken::EnumValue { std::string { s_namesCatCommand[static_cast<std::size_t>(value)] } } } };
112+
const size_t idx = static_cast<size_t>(value);
113+
114+
if (idx >= s_namesCatCommand.size())
115+
{
116+
throw service::schema_exception { { R"ex(Enum value out of range for CatCommand)ex" } };
117+
}
118+
119+
return ResolverResult { { response::ValueToken::EnumValue { std::string { s_namesCatCommand[idx] } } } };
106120
});
107121
}
108122

src/SchemaGenerator.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,12 +1692,14 @@ service::AwaitableResolver Result<)cpp"
16921692
<< R"cpp(::)cpp" << enumType.cppType << R"cpp( value, const ResolverParams&)
16931693
{
16941694
const size_t idx = static_cast<size_t>(value);
1695+
16951696
if (idx >= s_names)cpp"
16961697
<< enumType.cppType << R"cpp(.size())
16971698
{
16981699
throw service::schema_exception { { R"ex(Enum value out of range for )cpp"
16991700
<< enumType.type << R"cpp()ex" } };
17001701
}
1702+
17011703
return ResolverResult { { response::ValueToken::EnumValue { std::string { s_names)cpp"
17021704
<< enumType.cppType << R"cpp([idx] } } } };
17031705
});

src/introspection/IntrospectionSharedTypes.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,14 @@ service::AwaitableResolver Result<introspection::TypeKind>::convert(service::Awa
5050
return ModifiedResult<introspection::TypeKind>::resolve(std::move(result), std::move(params),
5151
[](introspection::TypeKind value, const ResolverParams&)
5252
{
53-
return ResolverResult { { response::ValueToken::EnumValue { std::string { s_namesTypeKind[static_cast<std::size_t>(value)] } } } };
53+
const size_t idx = static_cast<size_t>(value);
54+
55+
if (idx >= s_namesTypeKind.size())
56+
{
57+
throw service::schema_exception { { R"ex(Enum value out of range for __TypeKind)ex" } };
58+
}
59+
60+
return ResolverResult { { response::ValueToken::EnumValue { std::string { s_namesTypeKind[idx] } } } };
5461
});
5562
}
5663

@@ -102,7 +109,14 @@ service::AwaitableResolver Result<introspection::DirectiveLocation>::convert(ser
102109
return ModifiedResult<introspection::DirectiveLocation>::resolve(std::move(result), std::move(params),
103110
[](introspection::DirectiveLocation value, const ResolverParams&)
104111
{
105-
return ResolverResult { { response::ValueToken::EnumValue { std::string { s_namesDirectiveLocation[static_cast<std::size_t>(value)] } } } };
112+
const size_t idx = static_cast<size_t>(value);
113+
114+
if (idx >= s_namesDirectiveLocation.size())
115+
{
116+
throw service::schema_exception { { R"ex(Enum value out of range for __DirectiveLocation)ex" } };
117+
}
118+
119+
return ResolverResult { { response::ValueToken::EnumValue { std::string { s_namesDirectiveLocation[idx] } } } };
106120
});
107121
}
108122

0 commit comments

Comments
 (0)