From b81607dc259eb1c169772680c89a67ed77225ff3 Mon Sep 17 00:00:00 2001 From: Hardik K Date: Sat, 7 Nov 2026 12:26:55 +0530 Subject: [PATCH 1/6] fix(validations): include properties segment in ValidateSchemaPropertyHasValue pointer Enter the properties segment before property.Key when validating that schema properties have values so the generated error JSON pointer conforms to RFC 6901 and correctly navigates to the property within the schema object. Signed-off-by: Hardik K --- src/Microsoft.OpenApi/Validations/Rules/OpenApiSchemaRules.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.OpenApi/Validations/Rules/OpenApiSchemaRules.cs b/src/Microsoft.OpenApi/Validations/Rules/OpenApiSchemaRules.cs index eff687253..7c3a92934 100644 --- a/src/Microsoft.OpenApi/Validations/Rules/OpenApiSchemaRules.cs +++ b/src/Microsoft.OpenApi/Validations/Rules/OpenApiSchemaRules.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. using System.Collections.Generic; @@ -28,6 +28,7 @@ public static class OpenApiSchemaRules foreach (var property in schema.Properties .Where(entry => entry.Value is null)) { + context.Enter(OpenApiConstants.Properties); context.Enter(property.Key); context.CreateError(nameof(ValidateSchemaPropertyHasValue), string.Format(SRResource.Validation_SchemaPropertyObjectRequired, @@ -35,6 +36,7 @@ public static class OpenApiSchemaRules ? schemaReference.Reference.Id : string.Empty, property.Key)); context.Exit(); + context.Exit(); } } }); From 5e4848a39bf41d03d9effa6cd79dd8af5251e92b Mon Sep 17 00:00:00 2001 From: Hardik K Date: Sat, 7 Nov 2026 12:28:09 +0530 Subject: [PATCH 2/6] test(validations): update ValidateNullProperty to assert properties segment in error pointer Update the expected JSON pointer in ValidateNullProperty from #/schemas/schema1/property1 to #/schemas/schema1/properties/property1 to verify that the properties navigation segment is included in the error pointer. Signed-off-by: Hardik K --- .../Validations/OpenApiSchemaValidationTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.OpenApi.Tests/Validations/OpenApiSchemaValidationTests.cs b/test/Microsoft.OpenApi.Tests/Validations/OpenApiSchemaValidationTests.cs index 7f5cd47e2..c86d13fb8 100644 --- a/test/Microsoft.OpenApi.Tests/Validations/OpenApiSchemaValidationTests.cs +++ b/test/Microsoft.OpenApi.Tests/Validations/OpenApiSchemaValidationTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. using System; @@ -209,7 +209,7 @@ public void ValidateNullProperty() Assert.NotEmpty(validator.Errors); Assert.Equivalent(new List { - new OpenApiValidatorError(nameof(OpenApiSchemaRules.ValidateSchemaPropertyHasValue),"#/schemas/schema1/property1", + new OpenApiValidatorError(nameof(OpenApiSchemaRules.ValidateSchemaPropertyHasValue),"#/schemas/schema1/properties/property1", string.Format(SRResource.Validation_SchemaPropertyObjectRequired, string.Empty, "property1")) }, validator.Errors); From bfaf815c04cc993adc0317a5ff68c6e20c84326d Mon Sep 17 00:00:00 2001 From: Hardik K Date: Sat, 7 Nov 2026 12:29:56 +0530 Subject: [PATCH 3/6] test(validations): add unit test for standalone schema null property pointer Add unit test ValidateSchemaPropertyHasValueShouldReportErrorWithPropertiesPath verifying that validating a standalone schema with a null property produces an error pointer anchored at #/properties/name. Signed-off-by: Hardik K --- .../OpenApiSchemaValidationTests.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/Microsoft.OpenApi.Tests/Validations/OpenApiSchemaValidationTests.cs b/test/Microsoft.OpenApi.Tests/Validations/OpenApiSchemaValidationTests.cs index c86d13fb8..bef509527 100644 --- a/test/Microsoft.OpenApi.Tests/Validations/OpenApiSchemaValidationTests.cs +++ b/test/Microsoft.OpenApi.Tests/Validations/OpenApiSchemaValidationTests.cs @@ -557,6 +557,31 @@ public void ValidateSchemaDiscriminatorChecksOneOfAnyOfAndAllOf() Assert.Empty(validator.Errors); } + [Fact] + public void ValidateSchemaPropertyHasValueShouldReportErrorWithPropertiesPath() + { + // Arrange + var schema = new OpenApiSchema + { + Type = JsonSchemaType.Object, + Properties = new Dictionary + { + ["id"] = new OpenApiSchema { Type = JsonSchemaType.Integer }, + ["name"] = null! + } + }; + + // Act + var validator = new OpenApiValidator(ValidationRuleSet.GetDefaultRuleSet()); + var walker = new OpenApiWalker(validator); + walker.Walk((IOpenApiSchema)schema); + + // Assert + var error = Assert.Single(validator.Errors); + Assert.Equal(nameof(OpenApiSchemaRules.ValidateSchemaPropertyHasValue), error.RuleName); + Assert.Equal("#/properties/name", error.Pointer); + } + private static OpenApiSchema CreateSchemaChain(int depth, string discriminatorName) { var root = new OpenApiSchema(); From 5189ec286adf3511695544e6d2d908f6b6d15806 Mon Sep 17 00:00:00 2001 From: Hardik K Date: Sat, 7 Nov 2026 12:32:30 +0530 Subject: [PATCH 4/6] test(validations): add regression test for multiple null properties error pointers Add ValidateSchemaPropertyHasValueWithMultipleNullPropertiesShouldIncludePropertiesSegmentForEach to verify that each null property in a schema receives its own error pointer with the properties path segment. Signed-off-by: Hardik K --- .../OpenApiSchemaValidationTests.cs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/Microsoft.OpenApi.Tests/Validations/OpenApiSchemaValidationTests.cs b/test/Microsoft.OpenApi.Tests/Validations/OpenApiSchemaValidationTests.cs index bef509527..58e1d8656 100644 --- a/test/Microsoft.OpenApi.Tests/Validations/OpenApiSchemaValidationTests.cs +++ b/test/Microsoft.OpenApi.Tests/Validations/OpenApiSchemaValidationTests.cs @@ -582,6 +582,34 @@ public void ValidateSchemaPropertyHasValueShouldReportErrorWithPropertiesPath() Assert.Equal("#/properties/name", error.Pointer); } + [Fact] + public void ValidateSchemaPropertyHasValueWithMultipleNullPropertiesShouldIncludePropertiesSegmentForEach() + { + // Arrange + var schema = new OpenApiSchema + { + Type = JsonSchemaType.Object, + Properties = new Dictionary + { + ["first"] = null!, + ["valid"] = new OpenApiSchema { Type = JsonSchemaType.String }, + ["second"] = null! + } + }; + + // Act + var validator = new OpenApiValidator(ValidationRuleSet.GetDefaultRuleSet()); + var walker = new OpenApiWalker(validator); + walker.Walk((IOpenApiSchema)schema); + + // Assert + var errors = validator.Errors.ToList(); + Assert.Equal(2, errors.Count); + Assert.All(errors, e => Assert.Equal(nameof(OpenApiSchemaRules.ValidateSchemaPropertyHasValue), e.RuleName)); + Assert.Contains(errors, e => e.Pointer == "#/properties/first"); + Assert.Contains(errors, e => e.Pointer == "#/properties/second"); + } + private static OpenApiSchema CreateSchemaChain(int depth, string discriminatorName) { var root = new OpenApiSchema(); From dfa55074e9f5cf136a98a1512f577b887fd3cfb0 Mon Sep 17 00:00:00 2001 From: Hardik K Date: Sat, 7 Nov 2026 12:35:32 +0530 Subject: [PATCH 5/6] test(validations): add integration tests for document schema and operation response property pointers Add integration tests verifying full JSON pointer accuracy for null schema properties inside document components (#/components/schemas/User/properties/nullProp) and nested under operation responses (#/paths/~1items/get/responses/200/content/application~1json/schema/properties/missingSchema). Signed-off-by: Hardik K --- .../OpenApiSchemaValidationTests.cs | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/test/Microsoft.OpenApi.Tests/Validations/OpenApiSchemaValidationTests.cs b/test/Microsoft.OpenApi.Tests/Validations/OpenApiSchemaValidationTests.cs index 58e1d8656..c0ecc7888 100644 --- a/test/Microsoft.OpenApi.Tests/Validations/OpenApiSchemaValidationTests.cs +++ b/test/Microsoft.OpenApi.Tests/Validations/OpenApiSchemaValidationTests.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net.Http; using System.Text.Json.Nodes; using Xunit; @@ -610,6 +611,93 @@ public void ValidateSchemaPropertyHasValueWithMultipleNullPropertiesShouldInclud Assert.Contains(errors, e => e.Pointer == "#/properties/second"); } + [Fact] + public void ValidateSchemaPropertyHasValueInDocumentComponentsShouldReportFullPointer() + { + // Arrange + var document = new OpenApiDocument + { + Info = new OpenApiInfo { Title = "Test API", Version = "1.0.0" }, + Components = new OpenApiComponents + { + Schemas = new Dictionary + { + ["User"] = new OpenApiSchema + { + Type = JsonSchemaType.Object, + Properties = new Dictionary + { + ["nullProp"] = null! + } + } + } + } + }; + + // Act + var validator = new OpenApiValidator(ValidationRuleSet.GetDefaultRuleSet()); + var walker = new OpenApiWalker(validator); + walker.Walk(document); + + // Assert + var error = Assert.Single(validator.Errors); + Assert.Equal(nameof(OpenApiSchemaRules.ValidateSchemaPropertyHasValue), error.RuleName); + Assert.Equal("#/components/schemas/User/properties/nullProp", error.Pointer); + } + + [Fact] + public void ValidateSchemaPropertyHasValueInOperationResponseShouldReportFullPointer() + { + // Arrange + var document = new OpenApiDocument + { + Info = new OpenApiInfo { Title = "Test API", Version = "1.0.0" }, + Paths = new OpenApiPaths + { + ["/items"] = new OpenApiPathItem + { + Operations = new Dictionary + { + [HttpMethod.Get] = new OpenApiOperation + { + Responses = new OpenApiResponses + { + ["200"] = new OpenApiResponse + { + Description = "OK", + Content = new Dictionary + { + ["application/json"] = new OpenApiMediaType + { + Schema = new OpenApiSchema + { + Type = JsonSchemaType.Object, + Properties = new Dictionary + { + ["missingSchema"] = null! + } + } + } + } + } + } + } + } + } + } + }; + + // Act + var validator = new OpenApiValidator(ValidationRuleSet.GetDefaultRuleSet()); + var walker = new OpenApiWalker(validator); + walker.Walk(document); + + // Assert + var error = Assert.Single(validator.Errors); + Assert.Equal(nameof(OpenApiSchemaRules.ValidateSchemaPropertyHasValue), error.RuleName); + Assert.Equal("#/paths/~1items/get/responses/200/content/application~1json/schema/properties/missingSchema", error.Pointer); + } + private static OpenApiSchema CreateSchemaChain(int depth, string discriminatorName) { var root = new OpenApiSchema(); From fc8f7a47bb9351d10ba4a01c82dd2b533d7f7323 Mon Sep 17 00:00:00 2001 From: Hardik K Date: Sat, 7 Nov 2026 12:36:18 +0530 Subject: [PATCH 6/6] docs(validations): document JSON pointer path segment in ValidateSchemaPropertyHasValue Update XML doc comments on ValidateSchemaPropertyHasValue to explain that error pointers include the properties segment under RFC 6901 / JSON Schema conventions. Signed-off-by: Hardik K --- src/Microsoft.OpenApi/Validations/Rules/OpenApiSchemaRules.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.OpenApi/Validations/Rules/OpenApiSchemaRules.cs b/src/Microsoft.OpenApi/Validations/Rules/OpenApiSchemaRules.cs index 7c3a92934..b062741b2 100644 --- a/src/Microsoft.OpenApi/Validations/Rules/OpenApiSchemaRules.cs +++ b/src/Microsoft.OpenApi/Validations/Rules/OpenApiSchemaRules.cs @@ -17,7 +17,8 @@ namespace Microsoft.OpenApi public static class OpenApiSchemaRules { /// - /// Validates Schema Property has value + /// Validates that each property defined in a schema's properties dictionary has a non-null schema value. + /// When a property entry value is null, reports a validation error with a JSON pointer anchored under the properties segment. /// public static ValidationRule ValidateSchemaPropertyHasValue => new(nameof(ValidateSchemaPropertyHasValue),