dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
34.88k stars 9.85k forks source link

Provide api for building Json Pointers. #19211

Open bbarry opened 4 years ago

bbarry commented 4 years ago

Is your feature request related to a problem? Please describe.

The methods of JsonPatchDocument accept string path parameters which each accept strings with no additional validations.

In order to build various patches a user must build these strings appropriately. In my experience that often means joining a significant number of small strings together repeatedly with something like var path = prefix + "/" + Utilities.EncodeForJsonPointer(pathitem);.

Often I have paths where highly accessed short constant string tokens are used repeatedly and I've probably made some poor decisions in how to lay my code out to efficiently produce appropriate responses.

For example I might have a controller method that returns a document like this:

public ActionResult DoThing() {
    return JsonPatchDocument.Add("/" + Utilities.EncodeForJsonPointer(MyParameterObject.Bindings.DoThing) + "/-", new Thing());
}

My utility method here is encoding the property according to https://tools.ietf.org/html/rfc6901, effectively:

public static EncodeForJsonPointer(string input) => input.Replace("~", "~0").Replace("/", "~1");

Describe the solution you'd like

It would be nice if there was an easy to use api that provided some guidance on how to make these things.

Having a type that is not string in a common namespace that a library author or application dev might reasonably be expected to have at hand would encourage coupling to the improved type and discourage fixating on this primitive form.

Additional context

At the very least JsonPatchDocument utilizes string paths that are expected to be in a well known format yet I cannot find any documentation on starting from https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.jsonpatch.jsonpatchdocument if I didn't already know what I was doing with it.

javiercn commented 4 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to happen for the coming release. We will reassess the backlog following the current release and consider this item at that time. However, keep in mind that there are many other high priority features with which it will be competing for resources.