diff --git a/data-prepper-plugins/mutate-event-processors/src/main/java/org/opensearch/dataprepper/plugins/processor/mutateevent/RenameKeyProcessor.java b/data-prepper-plugins/mutate-event-processors/src/main/java/org/opensearch/dataprepper/plugins/processor/mutateevent/RenameKeyProcessor.java index b4bddc6acb..6699f409cb 100644 --- a/data-prepper-plugins/mutate-event-processors/src/main/java/org/opensearch/dataprepper/plugins/processor/mutateevent/RenameKeyProcessor.java +++ b/data-prepper-plugins/mutate-event-processors/src/main/java/org/opensearch/dataprepper/plugins/processor/mutateevent/RenameKeyProcessor.java @@ -47,10 +47,10 @@ public RenameKeyProcessor(final PluginMetrics pluginMetrics, final RenameKeyProc entry.getRenameWhen())); } if (entry.getFromKey() == null && entry.getFromKeyPattern() == null) { - throw new InvalidPluginConfigurationException("Either from_key or from_key_pattern must be specified. Both cannot be set together."); + throw new InvalidPluginConfigurationException("Either from_key or from_key_regex must be specified. "); } if (entry.getFromKey() != null && entry.getFromKeyPattern() != null) { - throw new InvalidPluginConfigurationException("Only one of from_key or from_key_pattern should be specified."); + throw new InvalidPluginConfigurationException("Only one of from_key or from_key_regex should be specified."); } }); } diff --git a/data-prepper-plugins/mutate-event-processors/src/main/java/org/opensearch/dataprepper/plugins/processor/mutateevent/RenameKeyProcessorConfig.java b/data-prepper-plugins/mutate-event-processors/src/main/java/org/opensearch/dataprepper/plugins/processor/mutateevent/RenameKeyProcessorConfig.java index 74533481fd..af73e21b81 100644 --- a/data-prepper-plugins/mutate-event-processors/src/main/java/org/opensearch/dataprepper/plugins/processor/mutateevent/RenameKeyProcessorConfig.java +++ b/data-prepper-plugins/mutate-event-processors/src/main/java/org/opensearch/dataprepper/plugins/processor/mutateevent/RenameKeyProcessorConfig.java @@ -13,6 +13,7 @@ import jakarta.validation.Valid; import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; +import org.opensearch.dataprepper.model.annotations.AlsoRequired; import org.opensearch.dataprepper.model.annotations.ExampleValues; import org.opensearch.dataprepper.model.annotations.ExampleValues.Example; import org.opensearch.dataprepper.model.event.EventKey; @@ -27,13 +28,24 @@ public class RenameKeyProcessorConfig { @JsonPropertyOrder public static class Entry { - @JsonProperty("from_key") - @JsonPropertyDescription("The key of the entry to be renamed.") + static final String FROM_KEY = "from_key"; + static final String FROM_KEY_REGEX = "from_key_regex"; + @JsonProperty(defaultValue = FROM_KEY) + @JsonPropertyDescription("The key of the entry to be renamed. " + + "This field cannot be defined along with from_key_regex.") + @AlsoRequired(values = { + @AlsoRequired.Required(name = FROM_KEY_REGEX, allowedValues = {"null"}) + }) @EventKeyConfiguration({EventKeyFactory.EventAction.GET, EventKeyFactory.EventAction.DELETE}) private EventKey fromKey; - @JsonProperty("from_key_regex") - @JsonPropertyDescription("The regex pattern of the key of the entry to be renamed.") + + @JsonProperty(defaultValue = FROM_KEY_REGEX) + @JsonPropertyDescription("The regex pattern of the key of the entry to be renamed. " + + "This field cannot be defined along with from_key.") + @AlsoRequired(values = { + @AlsoRequired.Required(name = FROM_KEY, allowedValues = {"null"}) + }) private String fromKeyRegex; @NotEmpty