Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
265 changes: 259 additions & 6 deletions src/Microsoft.AspNetCore.OData/Microsoft.AspNetCore.OData.xml

Large diffs are not rendered by default.

29 changes: 28 additions & 1 deletion src/Microsoft.AspNetCore.OData/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,30 @@ Microsoft.AspNetCore.OData.ODataMiniOptions.SetNoDollarQueryOptions(bool enableN
Microsoft.AspNetCore.OData.ODataMiniOptions.SetVersion(Microsoft.OData.ODataVersion version) -> Microsoft.AspNetCore.OData.ODataMiniOptions
Microsoft.AspNetCore.OData.ODataMiniOptions.SkipToken() -> Microsoft.AspNetCore.OData.ODataMiniOptions
Microsoft.AspNetCore.OData.ODataMiniOptions.Version.get -> Microsoft.OData.ODataVersion
Microsoft.AspNetCore.OData.Query.ComputeQueryOption.TryValidate(Microsoft.AspNetCore.OData.Query.Validator.ODataValidationSettings validationSettings, out System.Collections.Generic.IEnumerable<string> validationErrors) -> bool
Microsoft.AspNetCore.OData.Query.CountQueryOption.TryValidate(Microsoft.AspNetCore.OData.Query.Validator.ODataValidationSettings validationSettings, out System.Collections.Generic.IEnumerable<string> validationErrors) -> bool
Microsoft.AspNetCore.OData.Query.FilterQueryOption.TryValidate(Microsoft.AspNetCore.OData.Query.Validator.ODataValidationSettings validationSettings, out System.Collections.Generic.IEnumerable<string> validationErrors) -> bool
Microsoft.AspNetCore.OData.Query.IODataQueryEndpointFilter
Microsoft.AspNetCore.OData.Query.IODataQueryEndpointFilter.OnFilterExecutedAsync(object responseValue, Microsoft.AspNetCore.OData.Extensions.ODataQueryFilterInvocationContext context) -> System.Threading.Tasks.ValueTask<object>
Microsoft.AspNetCore.OData.Query.IODataQueryEndpointFilter.OnFilterExecutingAsync(Microsoft.AspNetCore.OData.Extensions.ODataQueryFilterInvocationContext context) -> System.Threading.Tasks.ValueTask
Microsoft.AspNetCore.OData.Query.ODataQueryEndpointFilter
Microsoft.AspNetCore.OData.Query.ODataQueryEndpointFilter.ODataQueryEndpointFilter() -> void
Microsoft.AspNetCore.OData.Query.ODataQueryEndpointFilter.QuerySettings.get -> Microsoft.AspNetCore.OData.Query.ODataQuerySettings
Microsoft.AspNetCore.OData.Query.ODataQueryEndpointFilter.ValidationSettings.get -> Microsoft.AspNetCore.OData.Query.Validator.ODataValidationSettings
Microsoft.AspNetCore.OData.Query.SearchQueryOption.TryValidate(Microsoft.AspNetCore.OData.Query.Validator.ODataValidationSettings validationSettings, out System.Collections.Generic.IEnumerable<string> validationErrors) -> bool
Microsoft.AspNetCore.OData.Query.SelectExpandQueryOption.TryValidate(Microsoft.AspNetCore.OData.Query.Validator.ODataValidationSettings validationSettings, out System.Collections.Generic.IEnumerable<string> validationErrors) -> bool
Microsoft.AspNetCore.OData.Query.SkipQueryOption.TryValidate(Microsoft.AspNetCore.OData.Query.Validator.ODataValidationSettings validationSettings, out System.Collections.Generic.IEnumerable<string> validationErrors) -> bool
Microsoft.AspNetCore.OData.Query.SkipTokenQueryOption.TryValidate(Microsoft.AspNetCore.OData.Query.Validator.ODataValidationSettings validationSettings, out System.Collections.Generic.IEnumerable<string> validationErrors) -> bool
Microsoft.AspNetCore.OData.Query.TopQueryOption.TryValidate(Microsoft.AspNetCore.OData.Query.Validator.ODataValidationSettings validationSettings, out System.Collections.Generic.IEnumerable<string> validationErrors) -> bool
Microsoft.AspNetCore.OData.Query.Validator.IComputeQueryValidator.TryValidate(Microsoft.AspNetCore.OData.Query.ComputeQueryOption computeQueryOption, Microsoft.AspNetCore.OData.Query.Validator.ODataValidationSettings validationSettings, out System.Collections.Generic.IEnumerable<string> validationErrors) -> bool
Microsoft.AspNetCore.OData.Query.Validator.ICountQueryValidator.TryValidate(Microsoft.AspNetCore.OData.Query.CountQueryOption countQueryOption, Microsoft.AspNetCore.OData.Query.Validator.ODataValidationSettings validationSettings, out System.Collections.Generic.IEnumerable<string> validationErrors) -> bool
Microsoft.AspNetCore.OData.Query.Validator.IFilterQueryValidator.TryValidate(Microsoft.AspNetCore.OData.Query.FilterQueryOption filterQueryOption, Microsoft.AspNetCore.OData.Query.Validator.ODataValidationSettings validationSettings, out System.Collections.Generic.IEnumerable<string> validationErrors) -> bool
Microsoft.AspNetCore.OData.Query.Validator.IODataQueryValidator.TryValidate(Microsoft.AspNetCore.OData.Query.ODataQueryOptions options, Microsoft.AspNetCore.OData.Query.Validator.ODataValidationSettings validationSettings, out System.Collections.Generic.IEnumerable<string> validationErrors) -> bool
Microsoft.AspNetCore.OData.Query.Validator.IOrderByQueryValidator.TryValidate(Microsoft.AspNetCore.OData.Query.OrderByQueryOption orderByOption, Microsoft.AspNetCore.OData.Query.Validator.ODataValidationSettings validationSettings, out System.Collections.Generic.IEnumerable<string> validationErrors) -> bool
Microsoft.AspNetCore.OData.Query.Validator.ISearchQueryValidator.TryValidate(Microsoft.AspNetCore.OData.Query.SearchQueryOption searchQueryOption, Microsoft.AspNetCore.OData.Query.Validator.ODataValidationSettings validationSettings, out System.Collections.Generic.IEnumerable<string> validationErrors) -> bool
Microsoft.AspNetCore.OData.Query.Validator.ISelectExpandQueryValidator.TryValidate(Microsoft.AspNetCore.OData.Query.SelectExpandQueryOption selectExpandQueryOption, Microsoft.AspNetCore.OData.Query.Validator.ODataValidationSettings validationSettings, out System.Collections.Generic.IEnumerable<string> validationErrors) -> bool
Microsoft.AspNetCore.OData.Query.Validator.ISkipQueryValidator.TryValidate(Microsoft.AspNetCore.OData.Query.SkipQueryOption skipQueryOption, Microsoft.AspNetCore.OData.Query.Validator.ODataValidationSettings validationSettings, out System.Collections.Generic.IEnumerable<string> validationErrors) -> bool
Microsoft.AspNetCore.OData.Query.Validator.ISkipTokenQueryValidator.TryValidate(Microsoft.AspNetCore.OData.Query.SkipTokenQueryOption skipToken, Microsoft.AspNetCore.OData.Query.Validator.ODataValidationSettings validationSettings, out System.Collections.Generic.IEnumerable<string> validationErrors) -> bool
Microsoft.AspNetCore.OData.Query.Wrapper.SelectExpandWrapperConverter
Microsoft.AspNetCore.OData.Query.Wrapper.SelectExpandWrapperConverter.SelectExpandWrapperConverter() -> void
Microsoft.AspNetCore.OData.Results.IODataResult
Expand Down Expand Up @@ -85,4 +102,14 @@ virtual Microsoft.AspNetCore.OData.Query.ODataQueryEndpointFilter.GetModel(Syste
virtual Microsoft.AspNetCore.OData.Query.ODataQueryEndpointFilter.InvokeAsync(Microsoft.AspNetCore.Http.EndpointFilterInvocationContext invocationContext, Microsoft.AspNetCore.Http.EndpointFilterDelegate next) -> System.Threading.Tasks.ValueTask<object>
virtual Microsoft.AspNetCore.OData.Query.ODataQueryEndpointFilter.OnFilterExecutedAsync(object responseValue, Microsoft.AspNetCore.OData.Extensions.ODataQueryFilterInvocationContext context) -> System.Threading.Tasks.ValueTask<object>
virtual Microsoft.AspNetCore.OData.Query.ODataQueryEndpointFilter.OnFilterExecutingAsync(Microsoft.AspNetCore.OData.Extensions.ODataQueryFilterInvocationContext context) -> System.Threading.Tasks.ValueTask
virtual Microsoft.AspNetCore.OData.Query.ODataQueryEndpointFilter.ValidateQuery(Microsoft.AspNetCore.Http.HttpContext httpContext, Microsoft.AspNetCore.OData.Query.ODataQueryOptions queryOptions) -> void
virtual Microsoft.AspNetCore.OData.Query.ODataQueryEndpointFilter.ValidateQuery(Microsoft.AspNetCore.Http.HttpContext httpContext, Microsoft.AspNetCore.OData.Query.ODataQueryOptions queryOptions) -> void
virtual Microsoft.AspNetCore.OData.Query.ODataQueryOptions.TryValidate(Microsoft.AspNetCore.OData.Query.Validator.ODataValidationSettings validationSettings, out System.Collections.Generic.IEnumerable<string> validationErrors) -> bool
virtual Microsoft.AspNetCore.OData.Query.Validator.ComputeQueryValidator.TryValidate(Microsoft.AspNetCore.OData.Query.ComputeQueryOption computeQueryOption, Microsoft.AspNetCore.OData.Query.Validator.ODataValidationSettings validationSettings, out System.Collections.Generic.IEnumerable<string> validationErrors) -> bool
virtual Microsoft.AspNetCore.OData.Query.Validator.CountQueryValidator.TryValidate(Microsoft.AspNetCore.OData.Query.CountQueryOption countQueryOption, Microsoft.AspNetCore.OData.Query.Validator.ODataValidationSettings validationSettings, out System.Collections.Generic.IEnumerable<string> validationErrors) -> bool
virtual Microsoft.AspNetCore.OData.Query.Validator.FilterQueryValidator.TryValidate(Microsoft.AspNetCore.OData.Query.FilterQueryOption filterQueryOption, Microsoft.AspNetCore.OData.Query.Validator.ODataValidationSettings validationSettings, out System.Collections.Generic.IEnumerable<string> validationErrors) -> bool
virtual Microsoft.AspNetCore.OData.Query.Validator.ODataQueryValidator.TryValidate(Microsoft.AspNetCore.OData.Query.ODataQueryOptions options, Microsoft.AspNetCore.OData.Query.Validator.ODataValidationSettings validationSettings, out System.Collections.Generic.IEnumerable<string> validationErrors) -> bool
virtual Microsoft.AspNetCore.OData.Query.Validator.OrderByQueryValidator.TryValidate(Microsoft.AspNetCore.OData.Query.OrderByQueryOption orderByOption, Microsoft.AspNetCore.OData.Query.Validator.ODataValidationSettings validationSettings, out System.Collections.Generic.IEnumerable<string> validationErrors) -> bool
virtual Microsoft.AspNetCore.OData.Query.Validator.SelectExpandQueryValidator.TryValidate(Microsoft.AspNetCore.OData.Query.SelectExpandQueryOption selectExpandQueryOption, Microsoft.AspNetCore.OData.Query.Validator.ODataValidationSettings validationSettings, out System.Collections.Generic.IEnumerable<string> validationErrors) -> bool
virtual Microsoft.AspNetCore.OData.Query.Validator.SkipQueryValidator.TryValidate(Microsoft.AspNetCore.OData.Query.SkipQueryOption skipQueryOption, Microsoft.AspNetCore.OData.Query.Validator.ODataValidationSettings validationSettings, out System.Collections.Generic.IEnumerable<string> validationErrors) -> bool
virtual Microsoft.AspNetCore.OData.Query.Validator.SkipTokenQueryValidator.TryValidate(Microsoft.AspNetCore.OData.Query.SkipTokenQueryOption skipToken, Microsoft.AspNetCore.OData.Query.Validator.ODataValidationSettings validationSettings, out System.Collections.Generic.IEnumerable<string> validationErrors) -> bool
virtual Microsoft.AspNetCore.OData.Query.Validator.TopQueryValidator.TryValidate(Microsoft.AspNetCore.OData.Query.TopQueryOption topQueryOption, Microsoft.AspNetCore.OData.Query.Validator.ODataValidationSettings validationSettings, out System.Collections.Generic.IEnumerable<string> validationErrors) -> bool
26 changes: 26 additions & 0 deletions src/Microsoft.AspNetCore.OData/Query/ODataQueryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,32 @@ public virtual void Validate(ODataValidationSettings validationSettings)
}
}

/// <summary>
/// Attempts to validate all OData queries, including $skip, $top, $orderby and $filter, based on the given <paramref name="validationSettings"/>.
/// </summary>
/// <param name="validationSettings">The <see cref="ODataValidationSettings"/> instance which contains all the validation settings.</param>
/// <param name="validationErrors">When this method returns, contains a collection of validation errors encountered, or an empty collection if validation succeeds.</param>
/// <returns><see langword="true"/> if the validation was successful or no validator is configured; otherwise, <see
/// langword="false"/> if validation failed.</returns>
public virtual bool TryValidate(ODataValidationSettings validationSettings, out IEnumerable<string> validationErrors)
{
if(validationSettings == null)
{
validationErrors = new[] { Error.ArgumentNull(nameof(validationSettings)).Message };
return false;
}

this.Context.ValidationSettings = validationSettings;

if (Validator != null && !Validator.TryValidate(this, validationSettings, out validationErrors))
{
return false;
}

validationErrors = Array.Empty<string>();
return true;
}

private static void ThrowIfEmpty(string queryValue, string queryName)
{
if (String.IsNullOrWhiteSpace(queryValue))
Expand Down
24 changes: 24 additions & 0 deletions src/Microsoft.AspNetCore.OData/Query/Query/ComputeQueryOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.OData.Query.Validator;
using Microsoft.OData.Edm;
using Microsoft.OData.UriParser;
Expand Down Expand Up @@ -137,4 +138,27 @@ public void Validate(ODataValidationSettings validationSettings)
Validator.Validate(this, validationSettings);
}
}

/// <summary>
/// Attempts to validate the $compute query based on the given <paramref name="validationSettings"/>. It throws an ODataException if validation failed.
/// </summary>
/// <param name="validationSettings">The <see cref="ODataValidationSettings"/> instance which contains all the validation settings.</param>
/// <param name="validationErrors">When this method returns, contains a collection of validation errors encountered, or an empty collection if validation succeeds.</param>
/// <returns><see langword="true"/> if the validation succeeded; otherwise, <see langword="false"/>.</returns>
public bool TryValidate(ODataValidationSettings validationSettings, out IEnumerable<string> validationErrors)
{
if (validationSettings == null)
{
validationErrors = new[] { Error.ArgumentNull(nameof(validationSettings)).Message };
return false;
}

if (Validator != null && !Validator.TryValidate(this, validationSettings, out validationErrors))
{
return false;
}

validationErrors = Array.Empty<string>();
return true;
}
}
24 changes: 24 additions & 0 deletions src/Microsoft.AspNetCore.OData/Query/Query/CountQueryOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,30 @@ public void Validate(ODataValidationSettings validationSettings)
}
}

/// <summary>
/// Attempts to validate the count query based on the given <paramref name="validationSettings"/>.
/// It throws an ODataException if validation failed.
/// </summary>
/// <param name="validationSettings">The <see cref="ODataValidationSettings"/> instance which contains all the validation settings.</param>
/// <param name="validationErrors">When this method returns, contains a collection of validation errors encountered, or an empty collection if validation succeeds.</param>
/// <returns><see langword="true"/> if the validation succeeded; otherwise, <see langword="false"/>.</returns>
public bool TryValidate(ODataValidationSettings validationSettings, out IEnumerable<string> validationErrors)
{
if (validationSettings == null)
{
validationErrors = new[] { Error.ArgumentNull(nameof(validationSettings)).Message };
return false;
}

if (Validator != null && !Validator.TryValidate(this, validationSettings, out validationErrors))
{
return false;
}

validationErrors = Array.Empty<string>();
return true;
}

/// <summary>
/// Gets the number of entities that satisfy the given query if the response should include a count query option, or <c>null</c> otherwise.
/// </summary>
Expand Down
23 changes: 23 additions & 0 deletions src/Microsoft.AspNetCore.OData/Query/Query/FilterQueryOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,27 @@ public void Validate(ODataValidationSettings validationSettings)
Validator.Validate(this, validationSettings);
}
}

/// <summary>
/// Attempts to validate the filter query based on the given <paramref name="validationSettings"/>. It throws an ODataException if validation failed.
/// </summary>
/// <param name="validationSettings">The <see cref="ODataValidationSettings"/> instance which contains all the validation settings.</param>
/// <param name="validationErrors">When this method returns, contains a collection of validation errors encountered, or an empty collection if validation succeeds.</param>
/// <returns><see langword="true"/> if the validation succeeded; otherwise, <see langword="false"/>.</returns>
public bool TryValidate(ODataValidationSettings validationSettings, out IEnumerable<string> validationErrors)
{
if (validationSettings == null)
{
validationErrors = new[] { Error.ArgumentNull(nameof(validationSettings)).Message };
return false;
}

if (Validator != null && !Validator.TryValidate(this, validationSettings, out validationErrors))
{
return false;
}

validationErrors = Array.Empty<string>();
return true;
}
}
23 changes: 23 additions & 0 deletions src/Microsoft.AspNetCore.OData/Query/Query/OrderByQueryOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,29 @@ public void Validate(ODataValidationSettings validationSettings)
}
}

/// <summary>
/// Attempts to validate the orderby query based on the given <paramref name="validationSettings"/>. It throws an ODataException if validation failed.
/// </summary>
/// <param name="validationSettings">The <see cref="ODataValidationSettings"/> instance which contains all the validation settings.</param>
/// <param name="validationErrors">When this method returns, contains a collection of validation errors encountered, or an empty collection if validation succeeds.</param>
/// <returns><see langword="true"/> if the validation succeeded; otherwise, <see langword="false"/>.</returns>
public bool TryValidate(ODataValidationSettings validationSettings, out IEnumerable<string> validationErrors)
{
if (validationSettings == null)
{
validationErrors = new[] { Error.ArgumentNull(nameof(validationSettings)).Message };
return false;
}

if (Validator != null && !Validator.TryValidate(this, validationSettings, out validationErrors))
{
return false;
}

validationErrors = Array.Empty<string>();
return true;
}

private IOrderedQueryable ApplyToCore(IQueryable query, ODataQuerySettings querySettings)
{
if (Context.ElementClrType == null)
Expand Down
26 changes: 26 additions & 0 deletions src/Microsoft.AspNetCore.OData/Query/Query/SearchQueryOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,30 @@ public void Validate(ODataValidationSettings validationSettings)
validator.Validate(this, validationSettings);
}
}

/// <summary>
/// Attempts to validate the $search query based on the given <paramref name="validationSettings"/>. It throws an ODataException if validation failed.
/// </summary>
/// <param name="validationSettings">The <see cref="ODataValidationSettings"/> instance which contains all the validation settings.</param>
/// <param name="validationErrors">When this method returns, contains a collection of validation errors encountered, or an empty collection if validation succeeds.</param>
/// <returns><see langword="true"/> if the validation succeeded; otherwise, <see langword="false"/>.</returns>
public bool TryValidate(ODataValidationSettings validationSettings, out IEnumerable<string> validationErrors)
{
if (validationSettings == null)
{
validationErrors = new[] { Error.ArgumentNull(nameof(validationSettings)).Message };
return false;
}

ISearchQueryValidator validator = Context.GetSearchQueryValidator();

// If the developer doesn't provide the search validator, let's ignore the $search validation.
if (validator != null && !validator.TryValidate(this, validationSettings, out validationErrors))
{
return false;
}

validationErrors = Array.Empty<string>();
return true;
}
}
Loading