/// <summary> /// Validates whether property names are camelCase in body parameters. /// </summary> public override IEnumerable <ValidationMessage> GetValidationMessages(Dictionary <string, Operation> path, RuleContext context) { foreach (string operation in path.Keys) { if (path[operation]?.Parameters != null) { for (var i = 0; i < path[operation].Parameters.Count; ++i) { if (path[operation].Parameters[i].In == ParameterLocation.Body && path[operation].Parameters[i].Schema?.Properties != null) { foreach (KeyValuePair <string, Schema> prop in path[operation].Parameters[i].Schema?.Properties) { if (!ValidationUtilities.IsODataProperty(prop.Key) && !ValidationUtilities.IsNameCamelCase(prop.Key)) { yield return(new ValidationMessage(new FileObjectPath(context.File, context.Path.AppendProperty(operation).AppendProperty("parameters").AppendIndex(i).AppendProperty("schema").AppendProperty("properties").AppendProperty(prop.Key)), this, prop.Key, ValidationUtilities.GetCamelCasedSuggestion(prop.Key))); } } } } } } }
public void CorrectlyCasesExamples(string input, string expectedOutput) { Assert.Equal(expectedOutput, ValidationUtilities.GetCamelCasedSuggestion(input)); }
/// <summary> /// Validates whether property names are camelCase for definitions. /// </summary> public override IEnumerable <ValidationMessage> GetValidationMessages(Dictionary <string, Schema> definitions, RuleContext context) { foreach (KeyValuePair <string, Schema> definition in definitions) { if (definition.Value.Properties != null) { foreach (KeyValuePair <string, Schema> prop in definition.Value.Properties) { if (!ValidationUtilities.IsNameCamelCase(prop.Key)) { yield return(new ValidationMessage(new FileObjectPath(context.File, context.Path), this, prop.Key, definition.Key, ValidationUtilities.GetCamelCasedSuggestion(prop.Key))); } } } } }
///// <summary> ///// Validates whether property names are camelCase in body parameters. ///// </summary> public override IEnumerable <ValidationMessage> GetValidationMessages(Dictionary <string, Operation> path, RuleContext context) { foreach (string operation in path.Keys) { if (path[operation]?.Parameters != null) { foreach (SwaggerParameter param in path[operation].Parameters) { if (param.In == ParameterLocation.Body && param.Schema?.Properties != null) { foreach (KeyValuePair <string, Schema> prop in param.Schema?.Properties) { if (!ValidationUtilities.IsNameCamelCase(prop.Key)) { yield return(new ValidationMessage(new FileObjectPath(context.File, context.Path), this, prop.Key, ValidationUtilities.GetCamelCasedSuggestion(prop.Key))); } } } } } } }