Skip to content
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
10 changes: 8 additions & 2 deletions env/env_yaml.cc
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,14 @@ absl::Status ParseVariableConfigs(Config& config, absl::string_view yaml,
}
variable_config.description = GetString(yaml, description);
}

CEL_ASSIGN_OR_RETURN(auto type_info, ParseTypeInfo(variable, yaml));
const YAML::Node type = variable["type"];
Config::TypeInfo type_info;
if (type.IsDefined() && !type.IsScalar()) {
// Old format, type spec is in 'type' instead of directly embedded.
CEL_ASSIGN_OR_RETURN(type_info, ParseTypeInfo(variable["type"], yaml));
} else {
CEL_ASSIGN_OR_RETURN(type_info, ParseTypeInfo(variable, yaml));
}
ConstantKindCase constant_kind_case = GetConstantKindCase(type_info.name);
std::string value_str;
YAML::Node value = variable["value"];
Expand Down
18 changes: 18 additions & 0 deletions env/env_yaml_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,24 @@ TEST(EnvYamlTest, ParseVariableConfigWithTypeParamsLegacySyntax) {
EXPECT_THAT(type_info.params[1].params, IsEmpty());
}

TEST(EnvYamlTest, ParseVariableConfigWithNestedRuleOldFormat) {
ASSERT_OK_AND_ASSIGN(Config config, EnvConfigFromYaml(R"yaml(
variables:
- name: "x"
type:
type_name: "int"
)yaml"));

ASSERT_THAT(config.GetVariableConfigs(), SizeIs(1));
const Config::VariableConfig& variable_config =
config.GetVariableConfigs()[0];
EXPECT_EQ(variable_config.name, "x");
const auto& type_info = variable_config.type_info;
EXPECT_EQ(type_info.name, "int");
EXPECT_FALSE(type_info.is_type_param);
EXPECT_THAT(type_info.params, IsEmpty());
}

struct ParseConstantTestCase {
std::string type;
std::string value;
Expand Down
Loading