Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: regenerate samples with enum validation #339

Merged
merged 1 commit into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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