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

ForgeSchemaValidator Fails in Validating Schemas with Parallel Action or Subroutine elements #58

Open
nibalach opened this issue May 3, 2024 · 2 comments

Comments

@nibalach
Copy link

nibalach commented May 3, 2024

The checked-in validation rules don't seem to account for the ability to define parallel actions.
The validation rules only expects one action to be defined: ForgeSchemaValidationRules.json

ForgeSchemaValidator returns validation errors for the following schema:

{
    "RootTreeNodeKey": "Root",
    "Tree": {
        "Root": {
            "Type": "Action",
            "Actions": {
                "EvacuateAction_Evacuate": {
                    "Action": "EvacuateAction"
                },
                "NotifyCustomerAction_Evacuate": {
                    "Action": "NotifyCustomerAction",
                    "Properties": "Notify customer in parallel with the impact."
                }
            }
        }
    }
}

but after removing the parallel action, the validation passes:

{
    "RootTreeNodeKey": "Root",
    "Tree": {
        "Root": {
            "Type": "Action",
            "Actions": {
                "EvacuateAction_Evacuate": {
                    "Action": "EvacuateAction"
                }
            }
        }
    }
}

Validation Errors:

[
    {
        "Message": "JSON is valid against no schemas from 'oneOf'.",
        "LineNumber": 1,
        "LinePosition": 25,
        "Path": "Root.Tree.Root",
        "Value": null,
        "SchemaId": "#/definitions/TreeNodeDefinition",
        "SchemaBaseUri": "file://ForgeSchemaValidationRules.json",
        "ErrorType": "oneOf",
        "ChildErrors": [
            {
                "Message": "Value \"Action\" is not defined in enum.",
                "LineNumber": 1,
                "LinePosition": 40,
                "Path": "Root.Tree.Root.Type",
                "Value": "Action",
                "SchemaId": "#/definitions/SubroutineTypeNodeDefinition/properties/Type",
                "SchemaBaseUri": "file://ForgeSchemaValidationRules.json",
                "ErrorType": "enum",
                "ChildErrors": []
            },
            {
                "Message": "Value \"Action\" is not defined in enum.",
                "LineNumber": 1,
                "LinePosition": 40,
                "Path": "Root.Tree.Root.Type",
                "Value": "Action",
                "SchemaId": "#/definitions/LeafTypeNodeDefinition/properties/Type",
                "SchemaBaseUri": "file://ForgeSchemaValidationRules.json",
                "ErrorType": "enum",
                "ChildErrors": []
            },
            {
                "Message": "Value \"Action\" is not defined in enum.",
                "LineNumber": 1,
                "LinePosition": 40,
                "Path": "Root.Tree.Root.Type",
                "Value": "Action",
                "SchemaId": "#/definitions/SelectionTypeNodeDefinition/properties/Type",
                "SchemaBaseUri": "file://ForgeSchemaValidationRules.json",
                "ErrorType": "enum",
                "ChildErrors": []
            },
            {
                "Message": "Property 'Actions' has not been defined and the schema does not allow additional properties.",
                "LineNumber": 1,
                "LinePosition": 51,
                "Path": "Root.Tree.Root.Actions",
                "Value": "Actions",
                "SchemaId": "#/definitions/SelectionTypeNodeDefinition",
                "SchemaBaseUri": "file://ForgeSchemaValidationRules.json",
                "ErrorType": "additionalProperties",
                "ChildErrors": []
            },
            {
                "Message": "Value \"EvacuateAction\" is not defined in enum.",
                "LineNumber": 1,
                "LinePosition": 104,
                "Path": "Root.Tree.Root.Actions.EvacuateAction_Evacuate.Action",
                "Value": "EvacuateAction",
                "SchemaId": "#/definitions/LeafNodeSummaryActionDefinition/properties/Action",
                "SchemaBaseUri": "file://ForgeSchemaValidationRules.json",
                "ErrorType": "enum",
                "ChildErrors": []
            },
            {
                "Message": "Required properties are missing from object: Input.",
                "LineNumber": 1,
                "LinePosition": 79,
                "Path": "Root.Tree.Root.Actions.EvacuateAction_Evacuate",
                "Value": [
                    "Input"
                ],
                "SchemaId": "#/definitions/LeafNodeSummaryActionDefinition",
                "SchemaBaseUri": "file://ForgeSchemaValidationRules.json",
                "ErrorType": "required",
                "ChildErrors": []
            },
            {
                "Message": "Value \"NotifyCustomerAction\" is not defined in enum.",
                "LineNumber": 1,
                "LinePosition": 170,
                "Path": "Root.Tree.Root.Actions.NotifyCustomerAction_Evacuate.Action",
                "Value": "NotifyCustomerAction",
                "SchemaId": "#/definitions/LeafNodeSummaryActionDefinition/properties/Action",
                "SchemaBaseUri": "file://ForgeSchemaValidationRules.json",
                "ErrorType": "enum",
                "ChildErrors": []
            },
            {
                "Message": "Property 'Properties' has not been defined and the schema does not allow additional properties.",
                "LineNumber": 1,
                "LinePosition": 184,
                "Path": "Root.Tree.Root.Actions.NotifyCustomerAction_Evacuate.Properties",
                "Value": "Properties",
                "SchemaId": "#/definitions/LeafNodeSummaryActionDefinition",
                "SchemaBaseUri": "file://ForgeSchemaValidationRules.json",
                "ErrorType": "additionalProperties",
                "ChildErrors": []
            },
            {
                "Message": "JSON does not match schema from 'else'.",
                "LineNumber": 1,
                "LinePosition": 139,
                "Path": "Root.Tree.Root.Actions.NotifyCustomerAction_Evacuate",
                "Value": null,
                "SchemaId": "#/definitions/ActionDefinition",
                "SchemaBaseUri": "file://ForgeSchemaValidationRules.json",
                "ErrorType": "else",
                "ChildErrors": [
                    {
                        "Message": "Invalid type. Expected Object but got String.",
                        "LineNumber": 1,
                        "LinePosition": 230,
                        "Path": "Root.Tree.Root.Actions.NotifyCustomerAction_Evacuate.Properties",
                        "Value": "Notify customer in parallel with the impact.",
                        "SchemaId": "#/definitions/ActionDefinition/properties/Properties",
                        "SchemaBaseUri": "file://ForgeSchemaValidationRules.json",
                        "ErrorType": "type",
                        "ChildErrors": []
                    },
                    {
                        "Message": "Value \"NotifyCustomerAction\" is not defined in enum.",
                        "LineNumber": 1,
                        "LinePosition": 170,
                        "Path": "Root.Tree.Root.Actions.NotifyCustomerAction_Evacuate.Action",
                        "Value": "NotifyCustomerAction",
                        "SchemaId": "#/definitions/SubroutineActionDefinition/allOf/1/properties/Action",
                        "SchemaBaseUri": "file://ForgeSchemaValidationRules.json",
                        "ErrorType": "enum",
                        "ChildErrors": []
                    },
                    {
                        "Message": "Invalid type. Expected Object but got String.",
                        "LineNumber": 1,
                        "LinePosition": 230,
                        "Path": "Root.Tree.Root.Actions.NotifyCustomerAction_Evacuate.Properties",
                        "Value": "Notify customer in parallel with the impact.",
                        "SchemaId": "#/definitions/ActionDefinition/properties/Properties",
                        "SchemaBaseUri": "file://ForgeSchemaValidationRules.json",
                        "ErrorType": "type",
                        "ChildErrors": []
                    }
                ]
            },
            {
                "Message": "Required properties are missing from object: Input.",
                "LineNumber": 1,
                "LinePosition": 139,
                "Path": "Root.Tree.Root.Actions.NotifyCustomerAction_Evacuate",
                "Value": [
                    "Input"
                ],
                "SchemaId": "#/definitions/LeafNodeSummaryActionDefinition",
                "SchemaBaseUri": "file://ForgeSchemaValidationRules.json",
                "ErrorType": "required",
                "ChildErrors": []
            },
            {
                "Message": "JSON does not match all schemas from 'allOf'. Invalid schema indexes: 1.",
                "LineNumber": 1,
                "LinePosition": 52,
                "Path": "Root.Tree.Root.Actions",
                "Value": null,
                "SchemaId": "#/definitions/ActionTypeNodeDefinition/properties/Actions",
                "SchemaBaseUri": "file://ForgeSchemaValidationRules.json",
                "ErrorType": "allOf",
                "ChildErrors": [
                    {
                        "Message": "Invalid type. Expected Object but got String.",
                        "LineNumber": 1,
                        "LinePosition": 230,
                        "Path": "Root.Tree.Root.Actions.NotifyCustomerAction_Evacuate.Properties",
                        "Value": "Notify customer in parallel with the impact.",
                        "SchemaId": "#/definitions/ActionDefinition/properties/Properties",
                        "SchemaBaseUri": "file://ForgeSchemaValidationRules.json",
                        "ErrorType": "type",
                        "ChildErrors": []
                    }
                ]
            },
            {
                "Message": "Object property count 2 exceeds maximum count of 1.",
                "LineNumber": 1,
                "LinePosition": 52,
                "Path": "Root.Tree.Root.Actions",
                "Value": 2,
                "SchemaId": "#/definitions/LeafTypeNodeDefinition/properties/Actions",
                "SchemaBaseUri": "file://ForgeSchemaValidationRules.json",
                "ErrorType": "maxProperties",
                "ChildErrors": []
            },
            {
                "Message": "Required properties are missing from object: ChildSelector.",
                "LineNumber": 1,
                "LinePosition": 25,
                "Path": "Root.Tree.Root",
                "Value": [
                    "ChildSelector"
                ],
                "SchemaId": "#/definitions/SelectionTypeNodeDefinition",
                "SchemaBaseUri": "file://ForgeSchemaValidationRules.json",
                "ErrorType": "required",
                "ChildErrors": []
            }
        ]
    }
]
@TravisOnGit
Copy link
Member

Ack, that's odd. I'll get to this later in the week. Thanks for calling this out.

@nibalach
Copy link
Author

nibalach commented May 4, 2024

I think the issue might be with the Properties element on the action node.

The schema validation somehow doesn’t seem to like single-line elements like Properties and Input on the action nodes.

Removing the Properties element seems to pass the schema validation:

{
    "RootTreeNodeKey": "Root",
    "Tree": {
        "Root": {
            "Type": "Action",
            "Actions": {
                "EvacuateAction_Evacuate": {
                    "Action": "EvacuateAction"
                },
                "NotifyCustomerAction_Evacuate": {
                    "Action": "NotifyCustomerAction"
                }
            }
        }
    }
}

Also observed it failing with a single-line Input property:

{
    "RootTreeNodeKey": "Root",
    "Tree": {
        "Root": {
            "Type": "Action",
            "Actions": {
                "EvacuateAction_Evacuate": {
                    "Action": "EvacuateAction"
                },
                "NotifyCustomerAction_Evacuate": {
                    "Action": "NotifyCustomerAction",
                    "Input": "C#|true"
                }
            }
        }
    }
}

But configuring the Input as a complex object with braces seems to pass the validation:

{
  "RootTreeNodeKey": "Root",
  "Tree": {
    "Root": {
      "Type": "Action",
      "Actions": {
        "EvacuateAction_Evacuate": {
          "Action": "EvacuateAction"
        },
        "NotifyCustomerAction_Evacuate": {
          "Action": "NotifyCustomerAction",
          "Input": {
            "myInput": "C#|true"
          }
        }
      }
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants