示例#1
0
        private protected override void ExecuteRuleLogic()
        {
            foreach (KeyValuePair <string, OpenApiPathItem> path in Contract.Paths)
            {
                if (Supressions.IsSupressed(ruleName, path.Key))
                {
                    continue;
                }

                string[] pathSplited = path.Key.Split('/');

                foreach (string pathSegment in pathSplited)
                {
                    if (!string.IsNullOrEmpty(pathSegment) &&
                        !pathSegment.Contains("{") &&
                        !pathSegment.GetCaseType(caseTypeTolerateNumber).Contains(caseType))
                    {
                        listResult.Add(
                            new ResultItem(this)
                        {
                            Description = Description
                                          .Replace("{0}", caseType.GetEnumDescription())
                                          .Replace("{1}", example),
                            Value = ResultItem.FormatValue(path: path.Key, pathSegment: pathSegment)
                        });
                    }
                }
            }
        }
        private protected override void ExecuteRuleLogic()
        {
            IEnumerable <IGrouping <string, OpenApiDocumentExtensions.Property> > propertiesByPath = Contract
                                                                                                     .GetAllBodyProperties(RuleSettings, Cache).GroupBy(
                prop => prop.Path + "|" + prop.Operation + "|" + prop.ResponseCode + "|" + prop.Content,
                prop => prop);

            foreach (IGrouping <string, OpenApiDocumentExtensions.Property> properties in propertiesByPath)
            {
                if (Supressions.IsSupressed(ruleName, properties.First().Path, properties.First().Operation,
                                            string.Empty,
                                            properties.First().ResponseCode))
                {
                    continue;
                }

                if (
                    properties.First().Level == OpenApiDocumentExtensions.Property.ProcessingLevel.Response &&
                    properties.First().ResponseCode != null &&
                    properties.First().ResponseCode != "204" &&
                    (properties.First().ResponseCode.StartsWith("2") || properties.First().ResponseCode.StartsWith("3")) &&
                    properties.All(prop => prop.Name != idPropertyName))
                {
                    listResult.Add(
                        new ResultItem(this)
                    {
                        Description = Description.Replace("{0}", idPropertyName),
                        Details     = Details.Replace("{0}", idPropertyName),
                        Value       = ResultItem.FormatValue(path: properties.First().Path, method: properties.First().Operation, response: properties.First().ResponseCode)
                    });
                }
            }
        }
        private protected override void ExecuteRuleLogic()
        {
            IEnumerable <IGrouping <string, OpenApiDocumentExtensions.Property> > propertiesByPath = Contract
                                                                                                     .GetAllBodyProperties(RuleSettings, Cache).GroupBy(
                prop => prop.Path + "|" + prop.Operation + "|" + prop.ResponseCode + "|" + prop.Content,
                prop => prop);

            foreach (IGrouping <string, OpenApiDocumentExtensions.Property> properties in propertiesByPath)
            {
                foreach (OpenApiDocumentExtensions.Property property in properties)
                //            foreach (OpenApiDocumentExtensions.Property property in contract.GetAllBodyProperties())
                {
                    if (Supressions.IsSupressed(ruleName, property.Path, property.Operation, string.Empty,
                                                property.ResponseCode, property.FullName))
                    {
                        continue;
                    }

                    if (
                        property.Level == OpenApiDocumentExtensions.Property.ProcessingLevel.Response &&
                        property.ResponseCode != null &&
                        (property.ResponseCode.StartsWith("4") || property.ResponseCode.StartsWith("5"))
                        && //There aren't any property not contained on the default ones.
                        obligatoryErrorProperties
                        .Concat(nonObligatoryErrorProperties)
                        .Except(properties.Select(p => p.FullName)).Any()
                        && //All obligatory properties are defined.
                        obligatoryErrorProperties.Intersect(properties.Select(p => p.FullName)).Count() !=
                        obligatoryErrorProperties.Length
                        )
                    {
                        listResult.Add(
                            new ResultItem(this)
                        {
                            Details = Details
                                      .Replace("{0}",
                                               string.Join(", ", obligatoryErrorProperties.Concat(nonObligatoryErrorProperties))),
                            Value = ResultItem.FormatValue(path: property.Path, method: property.Operation, response: property.ResponseCode)
                        });
                        break;
                    }
                }
            }
        }
        private protected override void ExecuteRuleLogic()
        {
            IEnumerable <IGrouping <string, OpenApiDocumentExtensions.Property> > propertiesByPath = Contract
                                                                                                     .GetAllBodyProperties(RuleSettings, Cache).GroupBy(
                prop => prop.Path + "|" + prop.Operation + "|" + prop.ResponseCode + "|" + prop.Content,
                prop => prop);

            foreach (IGrouping <string, OpenApiDocumentExtensions.Property> properties in propertiesByPath)
            {
                foreach (OpenApiDocumentExtensions.Property property in properties)
                {
                    if (Supressions.IsSupressed(ruleName, property.Path, property.Operation, string.Empty,
                                                property.ResponseCode, property.FullName))
                    {
                        continue;
                    }

                    if (
                        property.FullName.StartsWith($"{messagesEnvelopePropertyName}.") &&
                        property.Name != messagesEnvelopePropertyName &&
                        properties
                        .Any(prop =>
                             !propertiesInMessages
                             .Contains(prop.Name)        //any property not contained in pagination ones
                             )
                        )
                    {
                        listResult.Add(
                            new ResultItem(this)
                        {
                            Description = Description.Replace("{0}", messagesEnvelopePropertyName),
                            Details     = Details
                                          .Replace("{0}", messagesEnvelopePropertyName)
                                          .Replace("{1}", string.Join(", ", propertiesInMessages)),
                            Value = ResultItem.FormatValue(path: properties.First().Path, method: properties.First().Operation, response: properties.First().ResponseCode)
                        });
                        break;
                    }
                }
            }
        }