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
76 changes: 73 additions & 3 deletions src/cfnlint/data/schemas/other/step_functions/statemachine.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,86 @@
"choice": {
"$ref": "#/definitions/common",
"additionalProperties": false,
"allOf": [
{
"if": {
"properties": {
"QueryLanguage": {
"const": "JSONata"
}
},
"required": [
"QueryLanguage"
]
},
"then": {
"properties": {
"Choices": {
"items": {
"$ref": "#/definitions/choice/definitions/JSONataChoice"
},
"type": "array"
}
}
}
},
{
"if": {
"oneOf": [
{
"properties": {
"QueryLanguage": {
"const": "JSONPath"
}
},
"required": [
"QueryLanguage"
]
},
{
"not": {
"required": [
"QueryLanguage"
]
}
}
]
},
"then": {
"properties": {
"Choices": {
"items": {
"$ref": "#/definitions/choice/definitions/Operator"
},
"type": "array"
}
}
}
}
],
"definitions": {
"Assign": {
"type": "object"
},
"Condition": {
"type": "string"
},
"JSONataChoice": {
"properties": {
"Condition": {
"type": "string"
},
"Next": {
"pattern": "^.{1,128}$",
"type": "string"
}
},
"required": [
"Condition",
"Next"
],
"type": "object"
},
"Operator": {
"properties": {
"And": {
Expand Down Expand Up @@ -205,9 +278,6 @@
"type": "object"
},
"Choices": {
"items": {
"$ref": "#/definitions/choice/definitions/Operator"
},
"type": "array"
},
"Comment": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,23 @@ def _convert_schema_to_jsonata(self):
},
},
]
schema["definitions"]["choice"]["allOf"] = [
{
"properties": {
"Choices": {
"items": {
"properties": {
"Condition": {"type": "string"},
"Next": {"pattern": "^.{1,128}$", "type": "string"},
},
"additionalProperties": False,
"required": ["Condition", "Next"],
"type": "object",
}
}
}
}
]
return schema

def _clean_schema(self, validator: Validator, instance: Any):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,38 @@ def rule():
}
],
},
"Choices1": {
"Type": "Choice",
"Choices": [
{
"Condition": "BatchJobNotification",
"Next": "Notify Success",
}
],
"Next": "Notify Success",
"QueryLanguage": "JSONata",
},
"Choices2": {
"Type": "Choice",
"Choices": [
{
"Condition": "BatchJobNotification",
"Next": "Notify Success",
}
],
"Next": "Notify Success",
},
"Choices3": {
"Type": "Choice",
"Choices": [
{
"And": "BatchJobNotification",
"Next": "Notify Success",
}
],
"Next": "Notify Success",
"QueryLanguage": "JSONata",
},
"Notify Success": {
"Type": "Task",
"Resource": "arn:aws:states:::sns:publish",
Expand Down Expand Up @@ -857,6 +889,67 @@ def rule():
["Definition", "States", "Submit Batch Job 3", "Arguments"]
),
),
ValidationError(
(
"Only one of ['And', 'BooleanEquals', 'BooleanEqualsPath', 'IsBoolean', 'IsNull', "
"'IsNumeric', 'IsPresent', 'IsString', 'IsTimestamp', 'Not', 'NumericEquals', "
"'NumericEqualsPath', 'NumericGreaterThan', 'NumericGreaterThanPath', "
"'NumericGreaterThanEquals', 'NumericGreaterThanEqualsPath', 'NumericLessThan', "
"'NumericLessThanPath', 'NumericLessThanEquals', 'NumericLessThanEqualsPath', 'Or', "
"'StringEquals', 'StringEqualsPath', 'StringGreaterThan', 'StringGreaterThanPath', "
"'StringGreaterThanEquals', 'StringGreaterThanEqualsPath', 'StringLessThan', "
"'StringLessThanPath', 'StringLessThanEquals', 'StringLessThanEqualsPath', "
"'StringMatches', 'TimestampEquals', 'TimestampEqualsPath', 'TimestampGreaterThan', "
"'TimestampGreaterThanPath', 'TimestampGreaterThanEquals', 'TimestampGreaterThanEqualsPath', "
"'TimestampLessThan', 'TimestampLessThanPath', 'TimestampLessThanEquals', "
"'TimestampLessThanEqualsPath'] is a required property"
),
rule=StateMachineDefinition(),
validator="requiredXor",
schema_path=deque(
[
"properties",
"States",
"patternProperties",
"^.{1,128}$",
"allOf",
0,
"then",
"allOf",
1,
"then",
"properties",
"Choices",
"items",
"requiredXor",
]
),
path=deque(["Definition", "States", "Choices2", "Choices", 0]),
),
ValidationError(
("'Condition' is a required property"),
rule=StateMachineDefinition(),
validator="required",
schema_path=deque(
[
"properties",
"States",
"patternProperties",
"^.{1,128}$",
"allOf",
0,
"then",
"allOf",
0,
"then",
"properties",
"Choices",
"items",
"required",
]
),
path=deque(["Definition", "States", "Choices3", "Choices", 0]),
),
],
),
(
Expand Down Expand Up @@ -932,6 +1025,26 @@ def rule():
},
"End": True,
},
"Choices1": {
"Type": "Choice",
"Choices": [
{
"Condition": "{% $states.input.type != 'Private' %}",
"Next": "Notify Failure",
},
],
"End": True,
},
"Choices2": {
"Type": "Choice",
"Choices": [
{
"And": "{% $states.input.type != 'Private' %}",
"Next": "Notify Failure",
},
],
"End": True,
},
"Notify Failure": {
"Type": "Task",
"Resource": "arn:aws:states:::sns:publish",
Expand Down Expand Up @@ -1019,6 +1132,54 @@ def rule():
["Definition", "States", "Notify Success", "Parameters"]
),
),
ValidationError(
("'Condition' is a required property"),
rule=StateMachineDefinition(),
validator="required",
schema_path=deque(
[
"properties",
"States",
"patternProperties",
"^.{1,128}$",
"allOf",
0,
"then",
"allOf",
0,
"properties",
"Choices",
"items",
"required",
]
),
path=deque(["Definition", "States", "Choices2", "Choices", 0]),
),
ValidationError(
("Additional properties are not allowed ('And' was unexpected)"),
rule=StateMachineDefinition(),
validator="additionalProperties",
schema_path=deque(
[
"properties",
"States",
"patternProperties",
"^.{1,128}$",
"allOf",
0,
"then",
"allOf",
0,
"properties",
"Choices",
"items",
"additionalProperties",
]
),
path=deque(
["Definition", "States", "Choices2", "Choices", 0, "And"]
),
),
ValidationError(
(
"Additional properties are not allowed ('Parameters' was unexpected)"
Expand Down Expand Up @@ -1056,4 +1217,10 @@ def test_validate(
validator,
):
errs = list(rule.validate(validator, {}, instance, {}))
for i, err in enumerate(errs):
print(i)
print(err.message, err.message == expected[i].message)
print(err.path, err.path == expected[i].path)
print(err.schema_path, err.schema_path == expected[i].schema_path)
print(err.validator, err.validator == expected[i].validator)
assert errs == expected, f"{name!r} test failed with {errs!r}"
Loading