Skip to content

fix(validations): include properties segment in ValidateSchemaPropertyHasValue pointer - #3165

Open
Hardik K (hardikkaurani) wants to merge 6 commits into
microsoft:mainfrom
hardikkaurani:fix/schema-property-has-value-pointer-path
Open

Hardik K (hardikkaurani) wants to merge 6 commits into
microsoft:mainfrom
hardikkaurani:fix/schema-property-has-value-pointer-path

Conversation

@hardikkaurani

Copy link
Copy Markdown
Contributor

Summary

When validating that schema properties have non-null values, OpenApiSchemaRules.ValidateSchemaPropertyHasValue enters each property key (context.Enter(property.Key)) directly without first entering the properties segment (OpenApiConstants.Properties).

This caused the resulting OpenApiValidatorError.Pointer to omit the properties navigation segment (for example, generating #/schemas/schema1/property1 instead of #/schemas/schema1/properties/property1, or #/components/schemas/User/nullProp instead of #/components/schemas/User/properties/nullProp). In RFC 6901 JSON Pointers and OpenAPI/JSON Schema models, properties must be indexed under /properties/{propertyName}.

Changes

  • In OpenApiSchemaRules.ValidateSchemaPropertyHasValue, entered OpenApiConstants.Properties before entering property.Key (and exited both accordingly).
  • Updated existing ValidateNullProperty test to verify the corrected pointer path #/schemas/schema1/properties/property1.
  • Added unit and regression tests for standalone schemas, multiple null properties, and end-to-end documents (components and operation responses).
  • Updated XML documentation on ValidateSchemaPropertyHasValue.

Verification

  • Ran the full test suite (dotnet test), all 1963 tests across the solution pass.
  • Verified 0 warnings and 0 errors during build and packaging.

…yHasValue 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 <hardikkaurani1@gmail.com>
…egment 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 <hardikkaurani1@gmail.com>
…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 <hardikkaurani1@gmail.com>
…rror 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 <hardikkaurani1@gmail.com>
…ation 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 <hardikkaurani1@gmail.com>
…maPropertyHasValue

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 <hardikkaurani1@gmail.com>
@hardikkaurani
Hardik K (hardikkaurani) requested a review from a team as a code owner November 7, 2026 07:08
Copilot AI balanced review requested due to automatic review settings November 7, 2026 07:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@hardikkaurani

Copy link
Copy Markdown
Contributor Author

Hi Vincent Biret (@baywet),

Following up on the pointer accuracy discussion noted in #2806, I noticed ValidateSchemaPropertyHasValue in OpenApiSchemaRules was entering the individual property key directly (context.Enter(property.Key)) without first entering OpenApiConstants.Properties.

As a result, validation error pointers for null schema properties omitted the properties segment (e.g. pointing to #/components/schemas/User/nullProp or #/schemas/schema1/property1 instead of #/components/schemas/User/properties/nullProp / #/schemas/schema1/properties/property1). RFC 6901 JSON pointer navigation requires the properties segment to accurately address the property in the schema object.

This PR wraps the error generation with context.Enter(OpenApiConstants.Properties) / context.Exit(), updates the existing ValidateNullProperty assertion, and adds unit and integration tests covering standalone, multi-property, and document-level scenarios.

Whenever you have some time to take a look, I'd appreciate your feedback. Thanks!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants