Skip to content

Read Order from endpoint manifest in StaticAssetEndpointFactory#65975

Open
javiercn wants to merge 1 commit intomainfrom
javiercn/endpoint-order
Open

Read Order from endpoint manifest in StaticAssetEndpointFactory#65975
javiercn wants to merge 1 commit intomainfrom
javiercn/endpoint-order

Conversation

@javiercn
Copy link
Copy Markdown
Member

Summary

Add support for reading the Order property from the static assets endpoint manifest and applying it to the generated RouteEndpoint instances.

Changes

  • StaticAssetDescriptor.cs — Added string? Order property with freeze support and JsonIgnore(WhenWritingNull). Follows the same pattern as Quality on selectors (string in JSON, parsed to the target type at point of use).
  • StaticAssetEndpointFactory.cs — Parse Order from the descriptor and use it as the RouteEndpoint.Order. Falls back to -100 when absent (preserving existing behavior).
  • PublicAPI.Unshipped.txt — Declared the new public API surface.
  • StaticAssetsIntegrationTests.cs — Two new integration tests:
    • EndpointOrder_DefaultsToNegative100_WhenOrderNotSet — Verifies the default -100 order when no Order is specified.
    • EndpointOrder_UsesValueFromManifest_WhenOrderIsSet — Verifies that an explicit Order value (2147483647) is read and applied.

Motivation

This enables the SDK to control endpoint routing priority for scenarios like SPA fallback endpoints (Order = int.MaxValue) and default document endpoints, where the endpoint should match only after more specific routes have been evaluated.

Companion SDK PR: dotnet/sdk#53593

@github-actions github-actions bot added the needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically label Mar 25, 2026
@javiercn javiercn added area-routing and removed needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically labels Mar 25, 2026
@javiercn javiercn marked this pull request as ready for review March 25, 2026 17:35
Copilot AI review requested due to automatic review settings March 25, 2026 17:35
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for propagating endpoint routing Order from the static assets endpoint manifest into the generated RouteEndpoint instances, enabling SDK-controlled routing precedence (e.g., SPA fallbacks).

Changes:

  • Introduced StaticAssetDescriptor.Order (string-backed, JSON-serializable) with freeze support.
  • Updated StaticAssetEndpointFactory to parse and apply Order to RouteEndpointBuilder (defaulting to -100 when not specified).
  • Added integration tests validating default and explicit manifest-driven endpoint order, and updated public API declarations.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/StaticAssets/test/StaticAssetsIntegrationTests.cs Adds integration tests verifying default order and manifest-specified order behavior.
src/StaticAssets/src/StaticAssetEndpointFactory.cs Applies manifest-provided order to RouteEndpoint.Order with a default fallback.
src/StaticAssets/src/StaticAssetDescriptor.cs Adds new Order property with JSON behavior and freeze semantics.
src/StaticAssets/src/PublicAPI.Unshipped.txt Declares newly added public API surface for StaticAssetDescriptor.Order.

Comment on lines +27 to +28
// If the endpoint has an explicit order (e.g., SPA fallback endpoints), use that instead.
!string.IsNullOrEmpty(resource.Order) && int.TryParse(resource.Order, CultureInfo.InvariantCulture, out var order) ? order : -100);
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When resource.Order is present but not a valid int, this silently falls back to -100, which can mask a bad/corrupt manifest and produce unexpected routing precedence. Consider treating invalid non-empty values as an error (e.g., throw with route/manifest context, or at least log) and only default to -100 when the value is null/empty.

Copilot uses AI. Check for mistakes.
@@ -24,7 +24,8 @@ public Endpoint Create(StaticAssetDescriptor resource, List<Action<EndpointBuild
// Static resources always take precedence over default routes to mimic the behavior of UseStaticFiles.
// We give a -100 order to ensure that they are selected under normal circumstances, but leave a small lee-way
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in comment: "lee-way" should be "leeway".

Suggested change
// We give a -100 order to ensure that they are selected under normal circumstances, but leave a small lee-way
// We give a -100 order to ensure that they are selected under normal circumstances, but leave a small leeway

Copilot uses AI. Check for mistakes.
Comment on lines +23 to +31
/// <summary>
/// The order of the endpoint in the routing table. When null or empty, the default order of -100 is used.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? Order
{
get => _order;
set => _order = !_isFrozen ? value : throw new InvalidOperationException("StaticAssetDescriptor is frozen and doesn't accept further changes");
}
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a public API and the property type is string?, the XML docs should clarify the expected format/range (e.g., invariant-culture integer that must fit in int) and what happens when an invalid value is provided. Right now it's easy for consumers to set a non-numeric value without realizing it will be ignored/defaulted at endpoint creation time.

Copilot uses AI. Check for mistakes.
Add string? Order property to StaticAssetDescriptor with freeze support
and JsonIgnore(WhenWritingNull). StaticAssetEndpointFactory parses it to
int at point of use (consistent with how Quality is handled on selectors),
falling back to -100 when absent.

This enables SPA fallback endpoints (Order=int.MaxValue) and default
document endpoints to have configurable routing priority.

Includes two integration tests:
- EndpointOrder_DefaultsToNegative100_WhenOrderNotSet
- EndpointOrder_UsesValueFromManifest_WhenOrderIsSet
@javiercn javiercn force-pushed the javiercn/endpoint-order branch from 8dddabb to bb414f8 Compare March 28, 2026 15:11
@javiercn javiercn requested a review from a team March 30, 2026 10:16
Copy link
Copy Markdown
Member

@maraf maraf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants