Skip to content

Commit

Permalink
Merge pull request #339 from wravery/next
Browse files Browse the repository at this point in the history
chore: regenerate samples with enum validation
  • Loading branch information
wravery authored Dec 7, 2024
2 parents 2cfdc5b + e48538f commit b61e0d5
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 8 deletions.
9 changes: 8 additions & 1 deletion samples/learn/schema/StarWarsSharedTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ service::AwaitableResolver Result<learn::Episode>::convert(service::AwaitableSca
return ModifiedResult<learn::Episode>::resolve(std::move(result), std::move(params),
[](learn::Episode value, const ResolverParams&)
{
return ResolverResult { { response::ValueToken::EnumValue { std::string { s_namesEpisode[static_cast<std::size_t>(value)] } } } };
const size_t idx = static_cast<size_t>(value);

if (idx >= s_namesEpisode.size())
{
throw service::schema_exception { { R"ex(Enum value out of range for Episode)ex" } };
}

return ResolverResult { { response::ValueToken::EnumValue { std::string { s_namesEpisode[idx] } } } };
});
}

Expand Down
9 changes: 8 additions & 1 deletion samples/proxy/schema/ProxySharedTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ service::AwaitableResolver Result<proxy::OperationType>::convert(service::Awaita
return ModifiedResult<proxy::OperationType>::resolve(std::move(result), std::move(params),
[](proxy::OperationType value, const ResolverParams&)
{
return ResolverResult { { response::ValueToken::EnumValue { std::string { s_namesOperationType[static_cast<std::size_t>(value)] } } } };
const size_t idx = static_cast<size_t>(value);

if (idx >= s_namesOperationType.size())
{
throw service::schema_exception { { R"ex(Enum value out of range for OperationType)ex" } };
}

return ResolverResult { { response::ValueToken::EnumValue { std::string { s_namesOperationType[idx] } } } };
});
}

Expand Down
9 changes: 8 additions & 1 deletion samples/today/nointrospection/TodaySharedTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ service::AwaitableResolver Result<today::TaskState>::convert(service::AwaitableS
return ModifiedResult<today::TaskState>::resolve(std::move(result), std::move(params),
[](today::TaskState value, const ResolverParams&)
{
return ResolverResult { { response::ValueToken::EnumValue { std::string { s_namesTaskState[static_cast<std::size_t>(value)] } } } };
const size_t idx = static_cast<size_t>(value);

if (idx >= s_namesTaskState.size())
{
throw service::schema_exception { { R"ex(Enum value out of range for TaskState)ex" } };
}

return ResolverResult { { response::ValueToken::EnumValue { std::string { s_namesTaskState[idx] } } } };
});
}

Expand Down
9 changes: 8 additions & 1 deletion samples/today/schema/TodaySharedTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ service::AwaitableResolver Result<today::TaskState>::convert(service::AwaitableS
return ModifiedResult<today::TaskState>::resolve(std::move(result), std::move(params),
[](today::TaskState value, const ResolverParams&)
{
return ResolverResult { { response::ValueToken::EnumValue { std::string { s_namesTaskState[static_cast<std::size_t>(value)] } } } };
const size_t idx = static_cast<size_t>(value);

if (idx >= s_namesTaskState.size())
{
throw service::schema_exception { { R"ex(Enum value out of range for TaskState)ex" } };
}

return ResolverResult { { response::ValueToken::EnumValue { std::string { s_namesTaskState[idx] } } } };
});
}

Expand Down
18 changes: 16 additions & 2 deletions samples/validation/schema/ValidationSharedTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ service::AwaitableResolver Result<validation::DogCommand>::convert(service::Awai
return ModifiedResult<validation::DogCommand>::resolve(std::move(result), std::move(params),
[](validation::DogCommand value, const ResolverParams&)
{
return ResolverResult { { response::ValueToken::EnumValue { std::string { s_namesDogCommand[static_cast<std::size_t>(value)] } } } };
const size_t idx = static_cast<size_t>(value);

if (idx >= s_namesDogCommand.size())
{
throw service::schema_exception { { R"ex(Enum value out of range for DogCommand)ex" } };
}

return ResolverResult { { response::ValueToken::EnumValue { std::string { s_namesDogCommand[idx] } } } };
});
}

Expand Down Expand Up @@ -102,7 +109,14 @@ service::AwaitableResolver Result<validation::CatCommand>::convert(service::Awai
return ModifiedResult<validation::CatCommand>::resolve(std::move(result), std::move(params),
[](validation::CatCommand value, const ResolverParams&)
{
return ResolverResult { { response::ValueToken::EnumValue { std::string { s_namesCatCommand[static_cast<std::size_t>(value)] } } } };
const size_t idx = static_cast<size_t>(value);

if (idx >= s_namesCatCommand.size())
{
throw service::schema_exception { { R"ex(Enum value out of range for CatCommand)ex" } };
}

return ResolverResult { { response::ValueToken::EnumValue { std::string { s_namesCatCommand[idx] } } } };
});
}

Expand Down
2 changes: 2 additions & 0 deletions src/SchemaGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1692,12 +1692,14 @@ service::AwaitableResolver Result<)cpp"
<< 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([idx] } } } };
});
Expand Down
18 changes: 16 additions & 2 deletions src/introspection/IntrospectionSharedTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ service::AwaitableResolver Result<introspection::TypeKind>::convert(service::Awa
return ModifiedResult<introspection::TypeKind>::resolve(std::move(result), std::move(params),
[](introspection::TypeKind value, const ResolverParams&)
{
return ResolverResult { { response::ValueToken::EnumValue { std::string { s_namesTypeKind[static_cast<std::size_t>(value)] } } } };
const size_t idx = static_cast<size_t>(value);

if (idx >= s_namesTypeKind.size())
{
throw service::schema_exception { { R"ex(Enum value out of range for __TypeKind)ex" } };
}

return ResolverResult { { response::ValueToken::EnumValue { std::string { s_namesTypeKind[idx] } } } };
});
}

Expand Down Expand Up @@ -102,7 +109,14 @@ service::AwaitableResolver Result<introspection::DirectiveLocation>::convert(ser
return ModifiedResult<introspection::DirectiveLocation>::resolve(std::move(result), std::move(params),
[](introspection::DirectiveLocation value, const ResolverParams&)
{
return ResolverResult { { response::ValueToken::EnumValue { std::string { s_namesDirectiveLocation[static_cast<std::size_t>(value)] } } } };
const size_t idx = static_cast<size_t>(value);

if (idx >= s_namesDirectiveLocation.size())
{
throw service::schema_exception { { R"ex(Enum value out of range for __DirectiveLocation)ex" } };
}

return ResolverResult { { response::ValueToken::EnumValue { std::string { s_namesDirectiveLocation[idx] } } } };
});
}

Expand Down

0 comments on commit b61e0d5

Please sign in to comment.