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

Consumer Api: Improve tag validation on startup #1059

Merged
merged 3 commits into from
Feb 26, 2025
Merged
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
12 changes: 8 additions & 4 deletions Modules/Tags/src/Tags.Application/ApplicationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,23 @@ public class ContainsValidTagsAttribute : ValidationAttribute
return ValidationResult.Success;
}

private ValidationResult? ValidateTag(IEnumerable<string> nameParts, TagInfo tag)
private ValidationResult? ValidateTag(IEnumerable<string> propertyPath, TagInfo tag)
{
var notSupportedLanguages = tag.DisplayNames.Keys.Except(_supportedLanguages).ToList();
var notImplementedLanguages = _supportedLanguages.Except(tag.DisplayNames.Keys).ToList();

if (notSupportedLanguages.Count != 0)
return new ValidationResult($"The languages \"{Enumerate(notSupportedLanguages)}\" are unsupported", [GetPathOfProperty(nameParts)]);
return new ValidationResult($"The languages \"{Enumerate(notSupportedLanguages)}\" are unsupported", [GetPathOfProperty(propertyPath)]);
if (notImplementedLanguages.Count != 0)
return new ValidationResult($"A display name for the language(s) \"{Enumerate(notImplementedLanguages)}\" is required.", [GetPathOfProperty(nameParts)]);
return new ValidationResult($"A display name for the language(s) \"{Enumerate(notImplementedLanguages)}\" is required.", [GetPathOfProperty(propertyPath)]);

var tagName = propertyPath.Last();
if (propertyPath.Count() == 2 && tagName.Equals("x", StringComparison.OrdinalIgnoreCase))
return new ValidationResult("A first-level tag may not be equal to \"x\" or \"X\".", [GetPathOfProperty(propertyPath)]);

foreach (var (childName, child) in tag.Children)
{
var result = ValidateTag(nameParts.Append(childName), child);
var result = ValidateTag(propertyPath.Append(childName), child);
if (result != ValidationResult.Success) return result;
}

Expand Down