Table of Contents

Struct InputPointer

Namespace
Trellis
Assembly
Trellis.Core.dll

A pointer into a structured input document, expressed as an RFC 6901 JSON Pointer. Used by validation errors to identify the location of an offending value.

public readonly record struct InputPointer : IEquatable<InputPointer>
Implements
Inherited Members

Examples

new InputPointer("/email")
new InputPointer("/items/0/quantity")
new InputPointer("")            // root

Constructors

InputPointer(string)

Initializes a new instance of the InputPointer struct.

public InputPointer(string Path)

Parameters

Path string

The JSON Pointer path (e.g. "/email", "/items/0/quantity"). The root of the input is "".

Exceptions

ArgumentNullException

Path is null.

ArgumentException

Path is not an RFC 6901 JSON Pointer.

InputPointer(string, InputLocation)

Initializes a new instance of the InputPointer struct with an explicit input location.

public InputPointer(string Path, InputLocation In)

Parameters

Path string

The JSON Pointer path. For Query, Path and Header this is a single escaped token naming the parameter; prefer ForQuery(string), ForPath(string) and ForHeader(string), which do that escaping.

In InputLocation

Which part of the input the value came from.

Exceptions

ArgumentNullException

Path is null.

ArgumentException

Path is not an RFC 6901 JSON Pointer.

Properties

In

Gets which part of the input the value came from. Defaults to Unspecified, which projects as "unknown".

public InputLocation In { get; init; }

Property Value

InputLocation

Path

Gets the JSON Pointer path. A default InputPointer is observed as the root pointer ("").

public string Path { get; init; }

Property Value

string

Root

A pointer to the root of the input document.

public static InputPointer Root { get; }

Property Value

InputPointer

Methods

AppendIndex(int)

Appends a non-negative collection index using invariant decimal formatting. Preserves In.

public InputPointer AppendIndex(int index)

Parameters

index int

The zero-based collection index.

Returns

InputPointer

A new pointer beneath this pointer.

Exceptions

ArgumentOutOfRangeException

index is negative.

AppendProperty(string)

Appends one literal property-name segment, escaping '~' and '/' per RFC 6901. Preserves In and does not reinterpret a leading slash as a pointer.

public InputPointer AppendProperty(string propertyName)

Parameters

propertyName string

The literal name. Empty addresses a property named "".

Returns

InputPointer

A new pointer beneath this pointer.

Exceptions

ArgumentNullException

propertyName is null.

Deconstruct(out string)

Deconstructs the pointer into its JSON Pointer path.

public void Deconstruct(out string Path)

Parameters

Path string

The JSON Pointer path.

Deconstruct(out string, out InputLocation)

Deconstructs the pointer into its JSON Pointer path and input location.

public void Deconstruct(out string Path, out InputLocation In)

Parameters

Path string

The JSON Pointer path.

In InputLocation

Which part of the input the value came from.

Equals(InputPointer)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(InputPointer other)

Parameters

other InputPointer

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Remarks

Identity is Path and In. Path alone would make pointers that project to different wire locations compare equal, which would let de-duplication collapse distinct failures into one.

ForBody(string)

Builds a body pointer, stamping Body.

public static InputPointer ForBody(string jsonPointer)

Parameters

jsonPointer string

A simple property name or full JSON Pointer.

Returns

InputPointer

An InputPointer located in the request body.

Remarks

This takes a pointer, not a name, with escaping semantics identical to ForProperty(string): a leading '/' is passed through as an already-formed pointer, so ForBody("/items/0/quantity") addresses a nested value rather than a field literally named /items/0/quantity. It is therefore exempt from the single-token escaping applied by ForQuery(string), ForPath(string) and ForHeader(string).

Empty input yields the root path stamped Body, which is deliberately not Root: the root pointer is the documented idiom for a whole-body violation, and stamping it is what lets such a violation project as body rather than unknown.

ForHeader(string)

Builds a pointer to a request header, stamping Header.

public static InputPointer ForHeader(string name)

Parameters

name string

The header name.

Returns

InputPointer

An InputPointer located in the request headers.

Remarks

See ForName(string, InputLocation) for the escaping rules.

Exceptions

ArgumentException

name is null or empty.

ForPath(string)

Builds a pointer to a route (path) parameter, stamping Path.

public static InputPointer ForPath(string name)

Parameters

name string

The parameter name.

Returns

InputPointer

An InputPointer located in the route.

Remarks

See ForName(string, InputLocation) for the escaping rules.

Exceptions

ArgumentException

name is null or empty.

ForProperty(string)

Builds an InputPointer from a property name, prepending "/" if the value is not already a JSON Pointer.

public static InputPointer ForProperty(string propertyName)

Parameters

propertyName string

A simple property name or full JSON Pointer.

Returns

InputPointer

An InputPointer.

Remarks

When the input is a simple property name (does not start with '/'), the special characters defined by RFC 6901 §3 are escaped: '~' becomes "~0" and '/' becomes "~1". The order is significant — '~' is escaped first so that an already-introduced "~1" from a slash escape is not re-escaped as "~01". Inputs that already start with '/' are assumed to be a fully-formed JSON Pointer (e.g. produced by JsonPointerNormalizer) and are passed through unchanged.

ForQuery(string)

Builds a pointer to a query-string parameter, stamping Query.

public static InputPointer ForQuery(string name)

Parameters

name string

The parameter name.

Returns

InputPointer

An InputPointer located in the query string.

Remarks

See ForName(string, InputLocation) for the escaping rules.

Exceptions

ArgumentException

name is null or empty.

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

ToString()

Returns the fully qualified type name of this instance.

public override string ToString()

Returns

string

The fully qualified type name.