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

Remove additional text from property names before validation #266

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions ApiDoctor.Validation/DocFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ namespace ApiDoctor.Validation
using MarkdownDeep;
using Newtonsoft.Json;


/// <summary>
/// A documentation file that may contain one more resources or API methods
/// </summary>
Expand Down Expand Up @@ -503,7 +502,7 @@ protected string PreviewOfBlockContent(Block block)
return contentPreview;
}

protected Config.DocumentHeader CreateHeaderFromBlock(Block block)
protected static Config.DocumentHeader CreateHeaderFromBlock(Block block)
{
var header = new Config.DocumentHeader();
switch (block.BlockType)
Expand Down Expand Up @@ -1131,10 +1130,22 @@ private void PostProcessResources(List<ResourceDefinition> foundResources, List<
return;
}

var listOfTextToRemoveFromPropertyNames = DocSet.SchemaConfig?.TextToRemoveFromPropertyNames ?? [];
var parametersFromTableDefinition = table.Rows.Cast<ParameterDefinition>()
.Select(param =>
{
foreach (string text in listOfTextToRemoveFromPropertyNames)
{
param.Name = param.Name.Replace(text, "").Trim();
}
return param;
});


table.UsedIn.Add(onlyResource);
MergeParametersIntoCollection(
onlyResource.Parameters,
table.Rows.Cast<ParameterDefinition>(),
parametersFromTableDefinition,
issues.For(onlyResource.Name),
addMissingParameters: true,
expectedInResource: true,
Expand Down
3 changes: 2 additions & 1 deletion ApiDoctor.Validation/DocSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ public bool ScanDocumentation(string tags, IssueLogger issues)
$"Missing value for referenced base type in resource {resource.Name}");
}

var docIssues = issues.For(resource.SourceFile.DisplayName);
foreach (var param in resource.Parameters)
{
if (param.Type?.CustomTypeName != null)
Expand All @@ -423,7 +424,7 @@ public bool ScanDocumentation(string tags, IssueLogger issues)
{
if (string.IsNullOrWhiteSpace(resource.BaseType) || !resource.ResolvedBaseTypeReference.HasOrInheritsProperty(param.Name))
{
issues.Error(ValidationErrorCode.AdditionalPropertyDetected,
docIssues.Error(ValidationErrorCode.AdditionalPropertyDetected,
$"Property '{param.Name}' found in resource definition for '{resource.Name}', but not described in markdown table.");
}
}
Expand Down
17 changes: 12 additions & 5 deletions ApiDoctor.Validation/OData/Transformation/SchemaConfigFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ public class SchemaConfig
{
public SchemaConfig()
{
RequiredYamlHeaders = new string[] {};
FoldersToSkip = new List<string>();
FilesToSkip = new List<string>();
TreatErrorsAsWarningsWorkloads = new List<string>();
SkipPermissionTableUpdateForWorkloads = new List<string>();
RequiredYamlHeaders = [];
FoldersToSkip = [];
FilesToSkip = [];
TreatErrorsAsWarningsWorkloads = [];
SkipPermissionTableUpdateForWorkloads = [];

}

/// <summary>
Expand Down Expand Up @@ -103,6 +104,12 @@ public SchemaConfig()
/// </summary>
[JsonProperty("skipPermissionTableUpdateForWorkloads")]
public List<string> SkipPermissionTableUpdateForWorkloads { get; set; }

/// <summary>
/// Text to remove from property names
/// </summary>
[JsonProperty("textToRemoveFromPropertyNames")]
public List<string> TextToRemoveFromPropertyNames { get; set; }
}

public class SchemaDiffConfig
Expand Down
Loading