Example #1
0
        // Verifies if a tracked resource has a corresponding patch operation
        public override IEnumerable <ValidationMessage> GetValidationMessages(Dictionary <string, Schema> definitions, RuleContext context)
        {
            ServiceDefinition       serviceDefinition = (ServiceDefinition)context.Root;
            IEnumerable <Operation> patchOperations   = ValidationUtilities.GetOperationsByRequestMethod("patch", serviceDefinition);
            var respDefinitions = ValidationUtilities.GetResponseModelDefinitions(serviceDefinition);

            foreach (KeyValuePair <string, Schema> definition in definitions)
            {
                if (respDefinitions.Contains(definition.Key) && ValidationUtilities.IsTrackedResource(definition.Value, definitions))
                {
                    if (!patchOperations.Any(op => (op.Responses["200"]?.Schema?.Reference?.StripDefinitionPath()) == definition.Key))
                    {
                        // if no patch operation returns current tracked resource as a response,
                        // the tracked resource does not have a corresponding patch operation
                        yield return(new ValidationMessage(new FileObjectPath(context.File, context.Path), this, definition.Key.StripDefinitionPath()));
                    }
                }
            }
        }
        // Verifies if a tracked resource has a corresponding get operation
        public override IEnumerable <ValidationMessage> GetValidationMessages(Dictionary <string, Schema> definitions, RuleContext context)
        {
            ServiceDefinition       serviceDefinition = (ServiceDefinition)context.Root;
            IEnumerable <Operation> getOperations     = ValidationUtilities.GetOperationsByRequestMethod("get", serviceDefinition);
            // filter out the model definitions that are not being returned as a response
            var respDefinitions = ValidationUtilities.GetResponseModelDefinitions(serviceDefinition);

            foreach (KeyValuePair <string, Schema> definition in definitions)
            {
                if (respDefinitions.Contains(definition.Key) && ValidationUtilities.IsTrackedResource(definition.Value, definitions))
                {
                    // check for 200 status response models since they correspond to a successful get operation
                    if (!getOperations.Any(op => (op.Responses["200"]?.Schema?.Reference?.StripDefinitionPath()) == definition.Key))
                    {
                        // if no GET operation returns current tracked resource as a response,
                        // the tracked resource does not have a corresponding get operation
                        yield return(new ValidationMessage(new FileObjectPath(context.File, context.Path), this, definition.Key.StripDefinitionPath()));
                    }
                }
            }
        }