-
Notifications
You must be signed in to change notification settings - Fork 279
Adding pagination limits. #2153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
1aa7cd8
Adding pagination limits.
rohkhann 78587e9
Reverting changes to entity.cs
rohkhann d2dda1e
Dotnet format.
rohkhann ab731e4
Adding parser.
rohkhann ffa4501
Adding test cases.
rohkhann 15e99dc
Fix test case.
rohkhann e6f19ab
Rest api tests.
rohkhann 5b8fae8
fixing test case.
rohkhann 28b610b
RuntimeConfigValidator.
rohkhann bab107e
Fixing test cases.
rohkhann 8f6d725
dotnet format.
rohkhann d6dc671
fixing test.
rohkhann 7fa2a46
Removed the default parameters.
rohkhann 253ef06
Merge branch 'main' into rohkhann/AddingPaginationLimits
rohkhann b57b01f
Merge branch 'main' into rohkhann/AddingPaginationLimits
rohkhann a884bfe
Apply suggestions from code review
rohkhann 02729a3
Addressing test cases
rohkhann c39c271
Merging
rohkhann 3650a69
Addressing comments.
rohkhann b232ae4
ConfigValidationTests.
rohkhann 1a46095
Merge branch 'main' into rohkhann/AddingPaginationLimits
rohkhann c38ee07
Update src/Core/Configurations/RuntimeConfigProvider.cs
rohkhann b9d50e2
Apply suggestions from code review
rohkhann c2d4e51
Addressing comments.
rohkhann 3a2281b
Merging.
rohkhann 36b2c1b
Apply suggestions from code review
rohkhann 23bf680
Addressing comments.
rohkhann d395135
Merge branch 'rohkhann/AddingPaginationLimits' of https://github.com/…
rohkhann 9492e49
Addressing comment.
rohkhann 122cd1c
fixing comments.
rohkhann dbd90b6
Fixing the ODataVisitorTests.
rohkhann 6915880
Fixing issues while parsing the runtimeconfig.
rohkhann 833f041
Set default page size cosmos.
rohkhann e19bcbc
fixing merge conflicts.
rohkhann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
using System.Net; | ||
using System.Text.Json.Serialization; | ||
using Azure.DataApiBuilder.Service.Exceptions; | ||
|
||
namespace Azure.DataApiBuilder.Config.ObjectModel; | ||
|
||
/// <summary> | ||
/// Pagination options for the dab setup. | ||
/// Properties are nullable to support DAB CLI merge config | ||
/// expected behavior. | ||
/// </summary> | ||
public record PaginationOptions | ||
{ | ||
/// <summary> | ||
/// Default page size. | ||
/// </summary> | ||
public const uint DEFAULT_PAGE_SIZE = 100; | ||
|
||
/// <summary> | ||
/// Max page size. | ||
/// </summary> | ||
public const uint MAX_PAGE_SIZE = 100000; | ||
|
||
/// <summary> | ||
/// The default page size for pagination. | ||
/// </summary> | ||
[JsonPropertyName("default-page-size")] | ||
public int? DefaultPageSize { get; init; } = null; | ||
|
||
/// <summary> | ||
/// The max page size for pagination. | ||
/// </summary> | ||
[JsonPropertyName("max-page-size")] | ||
public int? MaxPageSize { get; init; } = null; | ||
|
||
[JsonConstructor] | ||
public PaginationOptions(int? DefaultPageSize = null, int? MaxPageSize = null) | ||
{ | ||
if (MaxPageSize is not null) | ||
{ | ||
ValidatePageSize((int)MaxPageSize); | ||
this.MaxPageSize = MaxPageSize == -1 ? Int32.MaxValue : (int)MaxPageSize; | ||
UserProvidedMaxPageSize = true; | ||
} | ||
else | ||
{ | ||
this.MaxPageSize = (int)MAX_PAGE_SIZE; | ||
} | ||
|
||
if (DefaultPageSize is not null) | ||
{ | ||
ValidatePageSize((int)DefaultPageSize); | ||
this.DefaultPageSize = DefaultPageSize == -1 ? (int)this.MaxPageSize : (int)DefaultPageSize; | ||
UserProvidedDefaultPageSize = true; | ||
} | ||
else | ||
{ | ||
this.DefaultPageSize = (int)DEFAULT_PAGE_SIZE; | ||
} | ||
|
||
if (this.DefaultPageSize > this.MaxPageSize) | ||
rohkhann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
throw new DataApiBuilderException( | ||
message: "Pagination options invalid. The default page size cannot be greater than max page size", | ||
statusCode: HttpStatusCode.ServiceUnavailable, | ||
subStatusCode: DataApiBuilderException.SubStatusCodes.ConfigValidationError); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Flag which informs CLI and JSON serializer whether to write default page size. | ||
/// property and value to the runtime config file. | ||
/// When user doesn't provide the default-page-size property/value, which signals DAB to use the default, | ||
/// the DAB CLI should not write the default value to a serialized config. | ||
/// This is because the user's intent is to use DAB's default value which could change | ||
/// and DAB CLI writing the property and value would lose the user's intent. | ||
/// This is because if the user were to use the CLI created config, a default-page-size | ||
/// property/value specified would be interpreted by DAB as "user explicitly default-page-size." | ||
/// </summary> | ||
[JsonIgnore(Condition = JsonIgnoreCondition.Always)] | ||
[MemberNotNullWhen(true, nameof(DefaultPageSize))] | ||
public bool UserProvidedDefaultPageSize { get; init; } = false; | ||
|
||
/// <summary> | ||
/// Flag which informs CLI and JSON serializer whether to write max-page-size | ||
/// property and value to the runtime config file. | ||
/// When user doesn't provide the max-page-size property/value, which signals DAB to use the default, | ||
/// the DAB CLI should not write the default value to a serialized config. | ||
/// This is because the user's intent is to use DAB's default value which could change | ||
/// and DAB CLI writing the property and value would lose the user's intent. | ||
/// This is because if the user were to use the CLI created config, a max-page-size | ||
/// property/value specified would be interpreted by DAB as "user explicitly max-page-size." | ||
/// </summary> | ||
[JsonIgnore(Condition = JsonIgnoreCondition.Always)] | ||
[MemberNotNullWhen(true, nameof(MaxPageSize))] | ||
public bool UserProvidedMaxPageSize { get; init; } = false; | ||
|
||
private static void ValidatePageSize(int pageSize) | ||
rohkhann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
if (pageSize < -1 || pageSize == 0 || pageSize > Int32.MaxValue) | ||
{ | ||
throw new DataApiBuilderException( | ||
message: "Pagination options invalid. Page size arguments cannot be 0, exceed max int value or be less than -1", | ||
statusCode: HttpStatusCode.ServiceUnavailable, | ||
subStatusCode: DataApiBuilderException.SubStatusCodes.ConfigValidationError); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.