Skip to content

Commit

Permalink
Feature/440 documentation comments duplicated (#441)
Browse files Browse the repository at this point in the history
* Fixed bug: line spaces no longer being applied.

* Failing test added.

* Fixed bug #440

De-duplicated documentation when the property type is not reducible.

* Include all unreduced type short documentation.
  • Loading branch information
mwadams authored Oct 1, 2024
1 parent 5eea75c commit e256f9f
Show file tree
Hide file tree
Showing 1,620 changed files with 6,852 additions and 320 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#nullable enable

using System.Diagnostics.CodeAnalysis;

#if NET8_0_OR_GREATER
using System.Numerics;
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@ public ValidationContext Validate(in ValidationContext validationContext, Valida
}

JsonValueKind valueKind = this.ValueKind;

result = CorvusValidation.TypeValidationHandler(valueKind, result, level);

if (level == ValidationLevel.Flag && !result.IsValid)
{
return result;
}

result = CorvusValidation.NumberValidationHandler(this, valueKind, result, level);

if (level == ValidationLevel.Flag && !result.IsValid)
{
return result;
Expand Down Expand Up @@ -108,13 +111,15 @@ internal static ValidationContext NumberValidationHandler(
ValidationContext ignoredResult = validationContext;
ignoredResult = ignoredResult.WithResult(isValid: true, "Validation maximum - ignored because the value is not a number", "maximum");
ignoredResult = ignoredResult.WithResult(isValid: true, "Validation minimum - ignored because the value is not a number", "minimum");

return ignoredResult;
}

return validationContext;
}

ValidationContext result = validationContext;

if ((value.HasJsonElementBacking
? BinaryJsonNumber.Compare(value.AsJsonElement, Maximum)
: BinaryJsonNumber.Compare(value.AsBinaryJsonNumber, Maximum))<= 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public ValidationContext Validate(in ValidationContext validationContext, Valida
}

result = CorvusValidation.CompositionOneOfValidationHandler(this, result, level);

if (level == ValidationLevel.Flag && !result.IsValid)
{
return result;
Expand Down Expand Up @@ -67,14 +68,17 @@ internal static ValidationContext CompositionOneOfValidationHandler(
ValidationLevel level = ValidationLevel.Flag)
{
ValidationContext result = validationContext;

int oneOfFoundValid = 0;

ValidationContext oneOfChildContext0 = validationContext.CreateChildContext();
if (level > ValidationLevel.Basic)
{
oneOfChildContext0 = oneOfChildContext0.PushValidationLocationReducedPathModifier(new("#/oneOf/0/$ref"));
}

ValidationContext oneOfResult0 = value.As<Corvus.Json.Benchmarking.Models.V4.PersonNameElement>().Validate(oneOfChildContext0, level);

if (oneOfResult0.IsValid)
{
result = result.MergeChildContext(oneOfResult0, level >= ValidationLevel.Verbose);
Expand All @@ -95,6 +99,7 @@ internal static ValidationContext CompositionOneOfValidationHandler(
}

ValidationContext oneOfResult1 = value.As<Corvus.Json.Benchmarking.Models.V4.PersonNameElementArray>().Validate(oneOfChildContext1, level);

if (oneOfResult1.IsValid)
{
result = result.MergeChildContext(oneOfResult1, level >= ValidationLevel.Verbose);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Corvus.Json.Internal;

namespace Corvus.Json.Benchmarking.Models.V4;

/// <summary>
/// Generated from JSON Schema.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Corvus.Json;

namespace Corvus.Json.Benchmarking.Models.V4;

/// <summary>
/// Generated from JSON Schema.
/// </summary>
Expand All @@ -40,13 +41,16 @@ public ValidationContext Validate(in ValidationContext validationContext, Valida
}

JsonValueKind valueKind = this.ValueKind;

result = CorvusValidation.TypeValidationHandler(valueKind, result, level);

if (level == ValidationLevel.Flag && !result.IsValid)
{
return result;
}

result = CorvusValidation.FormatValidationHandler(this, valueKind, result, level);

if (level == ValidationLevel.Flag && !result.IsValid)
{
return result;
Expand Down Expand Up @@ -79,6 +83,7 @@ internal static ValidationContext TypeValidationHandler(
ValidationLevel level = ValidationLevel.Flag)
{
bool isValid = false;

ValidationContext localResultString = Corvus.Json.ValidateWithoutCoreType.TypeString(valueKind, ValidationContext.ValidContext, level, "type");
if (level == ValidationLevel.Flag && localResultString.IsValid)
{
Expand Down Expand Up @@ -145,6 +150,7 @@ internal static ValidationContext FormatValidationHandler(
{
ValidationContext ignoredResult = validationContext;
ignoredResult = ignoredResult.WithResult(isValid: true, $"Validation format - ignored 'date' because the value is of kind '{valueKind}' not 'String'.");

return ignoredResult;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Corvus.Json.Internal;

namespace Corvus.Json.Benchmarking.Models.V4;

/// <summary>
/// Generated from JSON Schema.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ public static Person Create(
{
var builder = ImmutableList.CreateBuilder<JsonObjectProperty>();
builder.Add(JsonPropertyNames.Name, name.AsAny);

if (dateOfBirth is not null)
{
builder.Add(JsonPropertyNames.DateOfBirth, dateOfBirth.Value.AsAny);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,17 @@ public ValidationContext Validate(in ValidationContext validationContext, Valida
}

JsonValueKind valueKind = this.ValueKind;
result = result.UsingEvaluatedProperties();

result = CorvusValidation.TypeValidationHandler(valueKind, result, level);

if (level == ValidationLevel.Flag && !result.IsValid)
{
return result;
}

result = CorvusValidation.ObjectValidationHandler(this, valueKind, result, level);

if (level == ValidationLevel.Flag && !result.IsValid)
{
return result;
Expand Down Expand Up @@ -98,17 +102,22 @@ internal static ValidationContext ObjectValidationHandler(
{
ValidationContext ignoredResult = validationContext;
ignoredResult = ignoredResult.WithResult(isValid: true, "Validation properties - ignored because the value is not an object", "properties");
ignoredResult = ignoredResult.WithResult(isValid: true, "Validation unevaluatedProperties - ignored because the value is not an object", "unevaluatedProperties");
ignoredResult = ignoredResult.WithResult(isValid: true, "Validation required - ignored because the value is not an object", "required");

return ignoredResult;
}

return validationContext;
}

bool hasSeenName = false;

int propertyCount = 0;
foreach (JsonObjectProperty property in value.EnumerateObject())
{
string? propertyNameAsString = null;

if (property.NameEquals(JsonPropertyNames.DateOfBirthUtf8, JsonPropertyNames.DateOfBirth))
{
result = result.WithLocalProperty(propertyCount);
Expand All @@ -124,6 +133,7 @@ internal static ValidationContext ObjectValidationHandler(
}

result = result.MergeResults(propertyResult.IsValid, level, propertyResult);

if (level > ValidationLevel.Basic)
{
result = result.PopLocation();
Expand All @@ -144,6 +154,7 @@ internal static ValidationContext ObjectValidationHandler(
}

result = result.MergeResults(propertyResult.IsValid, level, propertyResult);

if (level > ValidationLevel.Basic)
{
result = result.PopLocation();
Expand All @@ -164,6 +175,7 @@ internal static ValidationContext ObjectValidationHandler(
}

result = result.MergeResults(propertyResult.IsValid, level, propertyResult);

if (level > ValidationLevel.Basic)
{
result = result.PopLocation();
Expand All @@ -185,6 +197,7 @@ internal static ValidationContext ObjectValidationHandler(
}

result = result.MergeResults(propertyResult.IsValid, level, propertyResult);

if (level > ValidationLevel.Basic)
{
result = result.PopLocation();
Expand All @@ -205,10 +218,32 @@ internal static ValidationContext ObjectValidationHandler(
}

result = result.MergeResults(propertyResult.IsValid, level, propertyResult);

if (level > ValidationLevel.Basic)
{
result = result.PopLocation();
}
}
if (!result.HasEvaluatedLocalOrAppliedProperty(propertyCount))
{
if (level > ValidationLevel.Basic)
{
string localEvaluatedPropertyName = (propertyNameAsString ??= property.Name.GetString());
result = result.PushValidationLocationReducedPathModifierAndProperty(new JsonReference("#/unevaluatedProperties").AppendUnencodedPropertyNameToFragment(localEvaluatedPropertyName), localEvaluatedPropertyName);
}

result = property.Value.As<Corvus.Json.JsonNotAny>().Validate(result, level);
if (level == ValidationLevel.Flag && !result.IsValid)
{
return result;
}

if (level > ValidationLevel.Basic)
{
result = result.PopLocation();
}

result = result.WithLocalProperty(propertyCount);
}

propertyCount++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@ public ValidationContext Validate(in ValidationContext validationContext, Valida
}

JsonValueKind valueKind = this.ValueKind;

result = CorvusValidation.TypeValidationHandler(valueKind, result, level);

if (level == ValidationLevel.Flag && !result.IsValid)
{
return result;
}

result = CorvusValidation.ArrayValidationHandler(this, valueKind, result, level);

if (level == ValidationLevel.Flag && !result.IsValid)
{
return result;
Expand Down Expand Up @@ -98,6 +101,7 @@ internal static ValidationContext ArrayValidationHandler(
{
ValidationContext ignoredResult = validationContext;
ignoredResult = ignoredResult.WithResult(isValid: true, "Validation items - ignored because the value is not an array", "items");

return ignoredResult;
}

Expand Down Expand Up @@ -129,6 +133,7 @@ internal static ValidationContext ArrayValidationHandler(
}

result = result.WithLocalItemIndex(length);

if (level > ValidationLevel.Basic)
{
result = result.PopLocation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ public static PersonName Create(
{
var builder = ImmutableList.CreateBuilder<JsonObjectProperty>();
builder.Add(JsonPropertyNames.FamilyName, familyName.AsAny);

if (givenName is not null)
{
builder.Add(JsonPropertyNames.GivenName, givenName.Value.AsAny);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,16 @@ public ValidationContext Validate(in ValidationContext validationContext, Valida
}

JsonValueKind valueKind = this.ValueKind;

result = CorvusValidation.TypeValidationHandler(valueKind, result, level);

if (level == ValidationLevel.Flag && !result.IsValid)
{
return result;
}

result = CorvusValidation.ObjectValidationHandler(this, valueKind, result, level);

if (level == ValidationLevel.Flag && !result.IsValid)
{
return result;
Expand Down Expand Up @@ -104,13 +107,15 @@ internal static ValidationContext ObjectValidationHandler(
ValidationContext ignoredResult = validationContext;
ignoredResult = ignoredResult.WithResult(isValid: true, "Validation properties - ignored because the value is not an object", "properties");
ignoredResult = ignoredResult.WithResult(isValid: true, "Validation required - ignored because the value is not an object", "required");

return ignoredResult;
}

return validationContext;
}

bool hasSeenFamilyName = false;

int propertyCount = 0;
foreach (JsonObjectProperty property in value.EnumerateObject())
{
Expand All @@ -130,6 +135,7 @@ internal static ValidationContext ObjectValidationHandler(
}

result = result.MergeResults(propertyResult.IsValid, level, propertyResult);

if (level > ValidationLevel.Basic)
{
result = result.PopLocation();
Expand All @@ -150,6 +156,7 @@ internal static ValidationContext ObjectValidationHandler(
}

result = result.MergeResults(propertyResult.IsValid, level, propertyResult);

if (level > ValidationLevel.Basic)
{
result = result.PopLocation();
Expand All @@ -170,6 +177,7 @@ internal static ValidationContext ObjectValidationHandler(
}

result = result.MergeResults(propertyResult.IsValid, level, propertyResult);

if (level > ValidationLevel.Basic)
{
result = result.PopLocation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@ public ValidationContext Validate(in ValidationContext validationContext, Valida
}

JsonValueKind valueKind = this.ValueKind;

result = CorvusValidation.TypeValidationHandler(valueKind, result, level);

if (level == ValidationLevel.Flag && !result.IsValid)
{
return result;
}

result = CorvusValidation.StringValidationHandler(this, valueKind, result, level);

if (level == ValidationLevel.Flag && !result.IsValid)
{
return result;
Expand Down Expand Up @@ -108,6 +111,7 @@ internal static ValidationContext StringValidationHandler(
ValidationContext ignoredResult = validationContext;
ignoredResult = ignoredResult.WithResult(isValid: true, "Validation maxLength - ignored because the value is not a string", "maxLength");
ignoredResult = ignoredResult.WithResult(isValid: true, "Validation minLength - ignored because the value is not a string", "minLength");

return ignoredResult;
}

Expand All @@ -116,12 +120,14 @@ internal static ValidationContext StringValidationHandler(

ValidationContext result = validationContext;
value.TryGetValue(StringValidator, new Corvus.Json.Validate.ValidationContextWrapper(result, level), out result);

return result;

static bool StringValidator(ReadOnlySpan<char> input, in Corvus.Json.Validate.ValidationContextWrapper context, out ValidationContext result)
{
int length = Corvus.Json.Validate.CountRunes(input);
result = context.Context;

if (context.Level > ValidationLevel.Basic)
{
result = result.PushValidationLocationReducedPathModifier(new("#/maxLength"));
Expand Down
Loading

0 comments on commit e256f9f

Please sign in to comment.