Skip to content

OpenApiWalker doesn't construct JSON pointer correctly #2780

@davidrea-MS

Description

@davidrea-MS

Describe the bug
When OpenApiWalker calls OpenApiVisitorBase.Enter(), it encodes / to ~1 but neglects to encode the ~ char first, inside the ReplaceSlashes() helper function. This results in the OpenApiVisitorBase.PathString property occasionally generating an invalid JSON pointer, such as during any of the built-in validation rules.

This can be seen by creating a document with a validation error under a property that contains a '~' in the name, and looking at the resulting OpenApiError.Pointer.

OpenApi File To Reproduce

{
    "openapi": "3.0.0",
    "info": {
      "title": "Test",
      "version": "1.0.0"
    },
    "paths": {},
    "components": {
      "schemas": {
        "my~schema": {
          "type": "object",
          "properties": {
            "goodProp": {
              "type": "string"
            },
            "nullProp": null
          }
        }
      }
    }
  }

Expected behavior
When validated with ValidationRuleSet.GetDefaultRuleSet(), validator should return an OpenApiError with the Pointer set to #/components/schemas/my~0schema/nullProp.
Instead, the Pointer is currently set to #/components/schemas/my~schema/nullProp, which is not a valid pointer.

Why is this a problem
The current format where tildas are not escaped is ambiguous. There's no way to distinguish between an encoded / and a literal ~1 string.
This prevents other tooling from being able to use the JSON pointer to highlight problems in the document.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions