diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ISMActionsParser.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ISMActionsParser.kt index e520c58ff..9b0160658 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ISMActionsParser.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ISMActionsParser.kt @@ -91,9 +91,9 @@ class ISMActionsParser private constructor() { Action.CUSTOM_ACTION_FIELD -> { // The "custom" wrapper allows extensions to create arbitrary actions without updating the config mappings // We consume the full custom wrapper and parse the action in this step - XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.nextToken(), xcp) - val customActionType = xcp.currentName() XContentParserUtils.ensureExpectedToken(XContentParser.Token.FIELD_NAME, xcp.nextToken(), xcp) + val customActionType = xcp.currentName() + XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.nextToken(), xcp) action = parseAction(xcp, totalActions, customActionType) XContentParserUtils.ensureExpectedToken(XContentParser.Token.END_OBJECT, xcp.nextToken(), xcp) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/extension/ISMActionsParserTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/extension/ISMActionsParserTests.kt index 69d238aa5..103cd92a9 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/extension/ISMActionsParserTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/extension/ISMActionsParserTests.kt @@ -72,4 +72,19 @@ class ISMActionsParserTests : OpenSearchTestCase() { assertEquals("Round tripping custom action doesn't work", customAction.convertToMap(), parsedCustomAction.convertToMap()) assertTrue("Custom action did not have custom keyword after parsing", parsedCustomAction.convertToMap().containsKey("custom")) } + + fun `test parsing custom action with custom flag`() { + val customActionParser = SampleCustomActionParser() + ISMActionsParser.instance.addParser(customActionParser, extensionName) + val customAction = SampleCustomActionParser.SampleCustomAction(randomInt(), 0) + customAction.customAction = true + + val customActionString = "{\"retry\":{\"count\":3,\"backoff\":\"exponential\",\"delay\":\"1m\"},\"custom\": {\"some_custom_action\":{\"some_int_field\":${customAction.someInt}}}}" + val parser = XContentType.JSON.xContent().createParser(xContentRegistry(), LoggingDeprecationHandler.INSTANCE, customActionString) + parser.nextToken() + val parsedCustomAction = ISMActionsParser.instance.parse(parser, 1) + assertTrue("Action was not set to be custom after parsing", parsedCustomAction.customAction) + assertEquals("Round tripping custom action doesn't work", customAction.convertToMap(), parsedCustomAction.convertToMap()) + assertTrue("Custom action did not have custom keyword after parsing", parsedCustomAction.convertToMap().containsKey("custom")) + } }