/// <summary> /// This rule passes if the paths contain reference to exactly one of the namespace resources /// </summary> /// <param name="paths"></param> /// <returns></returns> public override bool IsValid(Dictionary <string, Dictionary <string, Operation> > paths, RuleContext context, out object[] formatParameters) { IEnumerable <string> resourceProviders = ValidationUtilities.GetResourceProviders(paths); formatParameters = new [] { string.Join(", ", resourceProviders) }; return(resourceProviders.ToList().Count <= 1); }
/// <summary> /// This rule passes if the paths contain reference to exactly one of the namespace resources /// </summary> /// <param name="paths"></param> /// <returns></returns> public override bool IsValid(Dictionary <string, Dictionary <string, Operation> > paths, RuleContext context, out object[] formatParameters) { IEnumerable <string> resourceProviders = ValidationUtilities.GetResourceProviders(paths); string resourceProviderNamespace = ValidationUtilities.GetRPNamespaceFromFilePath(context.File.ToString()); formatParameters = new[] { string.Join(", ", resourceProviders) }; string lastResourceProvider = resourceProviders?.ToList().Count() > 0 ? resourceProviders.Last() : null; return(resourceProviders.ToList().Count <= 1 || lastResourceProvider == resourceProviderNamespace); }
/// <summary> /// Validates if the Operations API has been implemented /// </summary> /// <param name="paths">API paths</param> /// <returns>true if the operations API has been implemented. false otherwise.</returns> public override bool IsValid(Dictionary <string, Dictionary <string, Operation> > paths, RuleContext context, out object[] formatParameters) { string[] operationPathsEndingWithOperations = paths.Keys.Where(x => x.Trim().ToLower().EndsWith("/operations")).ToArray(); IEnumerable <string> resourceProviders = ValidationUtilities.GetResourceProviders(paths); // We'll check for only one RP in the swagger as other rules can validate having many RPs in one swagger string resourceProvider = resourceProviders?.ToList().Count > 0 ? resourceProviders.First() : null; string operationApiPath = string.Format("/providers/{0}/operations", resourceProvider); formatParameters = new object[] { }; foreach (string operationPath in operationPathsEndingWithOperations) { if (operationPath.EndsWith(operationApiPath)) { return(true); } } formatParameters = new string[] { operationApiPath }; return(false); }