Skip to content

Commit

Permalink
[AOT] Enable analysis and annotate Http.Results
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK committed Jan 13, 2023
1 parent a527ac5 commit e2494f1
Show file tree
Hide file tree
Showing 17 changed files with 436 additions and 34 deletions.
1 change: 1 addition & 0 deletions eng/TrimmableProjects.props
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<TrimmableProject Include="Microsoft.AspNetCore.Http.Abstractions" />
<TrimmableProject Include="Microsoft.AspNetCore.Http.Extensions" />
<TrimmableProject Include="Microsoft.AspNetCore.Http.Features" />
<TrimmableProject Include="Microsoft.AspNetCore.Http.Results" />
<TrimmableProject Include="Microsoft.AspNetCore.Http" />
<TrimmableProject Include="Microsoft.AspNetCore.Metadata" />
<TrimmableProject Include="Microsoft.AspNetCore.Routing.Abstractions" />
Expand Down
18 changes: 16 additions & 2 deletions src/Http/Http.Results/src/AcceptedAtRoute.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http.Metadata;
Expand All @@ -22,11 +23,24 @@ public sealed class AcceptedAtRoute : IResult, IEndpointMetadataProvider, IStatu
/// provided.
/// </summary>
/// <param name="routeValues">The route data to use for generating the URL.</param>
[RequiresUnreferencedCode(RouteValueDictionaryTrimmerWarning.Warning)]
internal AcceptedAtRoute(object? routeValues)
: this(routeName: null, routeValues: routeValues)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="AcceptedAtRoute"/> class with the values
/// provided.
/// </summary>
/// <param name="routeName">The name of the route to use for generating the URL.</param>
/// <param name="routeValues">The route data to use for generating the URL.</param>
[RequiresUnreferencedCode(RouteValueDictionaryTrimmerWarning.Warning)]
internal AcceptedAtRoute(string? routeName, object? routeValues)
: this(routeName, new RouteValueDictionary(routeValues))
{
}

/// <summary>
/// Initializes a new instance of the <see cref="AcceptedAtRoute"/> class with the values
/// provided.
Expand All @@ -35,10 +49,10 @@ internal AcceptedAtRoute(object? routeValues)
/// <param name="routeValues">The route data to use for generating the URL.</param>
internal AcceptedAtRoute(
string? routeName,
object? routeValues)
RouteValueDictionary routeValues)
{
RouteName = routeName;
RouteValues = new RouteValueDictionary(routeValues);
RouteValues = routeValues;
}

/// <summary>
Expand Down
19 changes: 17 additions & 2 deletions src/Http/Http.Results/src/AcceptedAtRouteOfT.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http.Metadata;
Expand All @@ -24,11 +25,25 @@ public sealed class AcceptedAtRoute<TValue> : IResult, IEndpointMetadataProvider
/// </summary>
/// <param name="routeValues">The route data to use for generating the URL.</param>
/// <param name="value">The value to format in the entity body.</param>
[RequiresUnreferencedCode(RouteValueDictionaryTrimmerWarning.Warning)]
internal AcceptedAtRoute(object? routeValues, TValue? value)
: this(routeName: null, routeValues: routeValues, value: value)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="AcceptedAtRoute"/> class with the values
/// provided.
/// </summary>
/// <param name="routeName">The name of the route to use for generating the URL.</param>
/// <param name="routeValues">The route data to use for generating the URL.</param>
/// <param name="value">The value to format in the entity body.</param>
[RequiresUnreferencedCode(RouteValueDictionaryTrimmerWarning.Warning)]
internal AcceptedAtRoute(string? routeName, object? routeValues, TValue? value)
: this(routeName, new RouteValueDictionary(routeValues), value)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="AcceptedAtRoute"/> class with the values
/// provided.
Expand All @@ -38,12 +53,12 @@ internal AcceptedAtRoute(object? routeValues, TValue? value)
/// <param name="value">The value to format in the entity body.</param>
internal AcceptedAtRoute(
string? routeName,
object? routeValues,
RouteValueDictionary routeValues,
TValue? value)
{
Value = value;
RouteName = routeName;
RouteValues = new RouteValueDictionary(routeValues);
RouteValues = routeValues;
HttpResultsHelper.ApplyProblemDetailsDefaultsIfNeeded(Value, StatusCode);
}

Expand Down
18 changes: 16 additions & 2 deletions src/Http/Http.Results/src/CreatedAtRoute.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http.Metadata;
Expand All @@ -22,11 +23,24 @@ public sealed class CreatedAtRoute : IResult, IEndpointMetadataProvider, IStatus
/// provided.
/// </summary>
/// <param name="routeValues">The route data to use for generating the URL.</param>
[RequiresUnreferencedCode(RouteValueDictionaryTrimmerWarning.Warning)]
internal CreatedAtRoute(object? routeValues)
: this(routeName: null, routeValues: routeValues)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="CreatedAtRoute"/> class with the values
/// provided.
/// </summary>
/// <param name="routeName">The name of the route to use for generating the URL.</param>
/// <param name="routeValues">The route data to use for generating the URL.</param>
[RequiresUnreferencedCode(RouteValueDictionaryTrimmerWarning.Warning)]
internal CreatedAtRoute(string? routeName, object? routeValues)
: this(routeName, new RouteValueDictionary(routeValues))
{
}

/// <summary>
/// Initializes a new instance of the <see cref="CreatedAtRoute"/> class with the values
/// provided.
Expand All @@ -35,10 +49,10 @@ internal CreatedAtRoute(object? routeValues)
/// <param name="routeValues">The route data to use for generating the URL.</param>
internal CreatedAtRoute(
string? routeName,
object? routeValues)
RouteValueDictionary routeValues)
{
RouteName = routeName;
RouteValues = new RouteValueDictionary(routeValues);
RouteValues = routeValues;
}

/// <summary>
Expand Down
19 changes: 17 additions & 2 deletions src/Http/Http.Results/src/CreatedAtRouteOfT.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http.Metadata;
Expand All @@ -24,11 +25,25 @@ public sealed class CreatedAtRoute<TValue> : IResult, IEndpointMetadataProvider,
/// </summary>
/// <param name="routeValues">The route data to use for generating the URL.</param>
/// <param name="value">The value to format in the entity body.</param>
[RequiresUnreferencedCode(RouteValueDictionaryTrimmerWarning.Warning)]
internal CreatedAtRoute(object? routeValues, TValue? value)
: this(routeName: null, routeValues: routeValues, value: value)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="CreatedAtRoute"/> class with the values
/// provided.
/// </summary>
/// <param name="routeName">The name of the route to use for generating the URL.</param>
/// <param name="routeValues">The route data to use for generating the URL.</param>
/// <param name="value">The value to format in the entity body.</param>
[RequiresUnreferencedCode(RouteValueDictionaryTrimmerWarning.Warning)]
internal CreatedAtRoute(string? routeName, object? routeValues, TValue? value)
: this(routeName, new RouteValueDictionary(routeValues), value)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="CreatedAtRoute"/> class with the values
/// provided.
Expand All @@ -38,12 +53,12 @@ internal CreatedAtRoute(object? routeValues, TValue? value)
/// <param name="value">The value to format in the entity body.</param>
internal CreatedAtRoute(
string? routeName,
object? routeValues,
RouteValueDictionary routeValues,
TValue? value)
{
Value = value;
RouteName = routeName;
RouteValues = new RouteValueDictionary(routeValues);
RouteValues = routeValues;
HttpResultsHelper.ApplyProblemDetailsDefaultsIfNeeded(Value, StatusCode);
}

Expand Down
8 changes: 8 additions & 0 deletions src/Http/Http.Results/src/HttpResultsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ public static Task WriteResultAsJsonAsync<T>(

// In this case the polymorphism is not
// relevant and we don't need to box.
#pragma warning disable IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code
#pragma warning disable IL3050 // Calling members annotated with 'RequiresDynamicCodeAttribute' may break functionality when AOT compiling.
return httpContext.Response.WriteAsJsonAsync(
value,
options: jsonSerializerOptions,
contentType: contentType);
#pragma warning restore IL3050 // Calling members annotated with 'RequiresDynamicCodeAttribute' may break functionality when AOT compiling.
#pragma warning restore IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code
}

var runtimeType = value.GetType();
Expand All @@ -48,11 +52,15 @@ public static Task WriteResultAsJsonAsync<T>(
// and avoid source generators issues.
// https://github.com/dotnet/aspnetcore/issues/43894
// https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-polymorphism
#pragma warning disable IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code
#pragma warning disable IL3050 // Calling members annotated with 'RequiresDynamicCodeAttribute' may break functionality when AOT compiling.
return httpContext.Response.WriteAsJsonAsync(
value,
runtimeType,
options: jsonSerializerOptions,
contentType: contentType);
#pragma warning restore IL3050 // Calling members annotated with 'RequiresDynamicCodeAttribute' may break functionality when AOT compiling.
#pragma warning restore IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code
}

public static Task WriteResultAsContentAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageTags>aspnetcore</PackageTags>
<IsPackable>false</IsPackable>
<Nullable>enable</Nullable>
<IsTrimmable>true</IsTrimmable>
<RootNamespace>Microsoft.AspNetCore.Http.Result</RootNamespace>
</PropertyGroup>

Expand Down
10 changes: 10 additions & 0 deletions src/Http/Http.Results/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ Microsoft.AspNetCore.Http.HttpResults.Utf8ContentHttpResult.ExecuteAsync(Microso
Microsoft.AspNetCore.Http.HttpResults.Utf8ContentHttpResult.ResponseContent.get -> System.ReadOnlyMemory<byte>
Microsoft.AspNetCore.Http.HttpResults.Utf8ContentHttpResult.StatusCode.get -> int?
static Microsoft.AspNetCore.Http.Results.Accepted<TValue>(string? uri = null, TValue? value = default(TValue?)) -> Microsoft.AspNetCore.Http.IResult!
static Microsoft.AspNetCore.Http.Results.AcceptedAtRoute(string? routeName, Microsoft.AspNetCore.Routing.RouteValueDictionary! routeValues, object? value = null) -> Microsoft.AspNetCore.Http.IResult!
static Microsoft.AspNetCore.Http.Results.AcceptedAtRoute<TValue>(string? routeName = null, object? routeValues = null, TValue? value = default(TValue?)) -> Microsoft.AspNetCore.Http.IResult!
static Microsoft.AspNetCore.Http.Results.AcceptedAtRoute<TValue>(string? routeName, Microsoft.AspNetCore.Routing.RouteValueDictionary! routeValues, TValue? value = default(TValue?)) -> Microsoft.AspNetCore.Http.IResult!
static Microsoft.AspNetCore.Http.Results.BadRequest<TValue>(TValue? error) -> Microsoft.AspNetCore.Http.IResult!
static Microsoft.AspNetCore.Http.Results.Conflict<TValue>(TValue? error) -> Microsoft.AspNetCore.Http.IResult!
static Microsoft.AspNetCore.Http.Results.Content(string? content, Microsoft.Net.Http.Headers.MediaTypeHeaderValue! contentType) -> Microsoft.AspNetCore.Http.IResult!
Expand All @@ -166,21 +168,29 @@ static Microsoft.AspNetCore.Http.Results.Created(string? uri, object? value) ->
static Microsoft.AspNetCore.Http.Results.Created(System.Uri? uri, object? value) -> Microsoft.AspNetCore.Http.IResult!
static Microsoft.AspNetCore.Http.Results.Created<TValue>(string? uri, TValue? value) -> Microsoft.AspNetCore.Http.IResult!
static Microsoft.AspNetCore.Http.Results.Created<TValue>(System.Uri? uri, TValue? value) -> Microsoft.AspNetCore.Http.IResult!
static Microsoft.AspNetCore.Http.Results.CreatedAtRoute(string? routeName, Microsoft.AspNetCore.Routing.RouteValueDictionary! routeValues, object? value = null) -> Microsoft.AspNetCore.Http.IResult!
static Microsoft.AspNetCore.Http.Results.CreatedAtRoute<TValue>(string? routeName = null, object? routeValues = null, TValue? value = default(TValue?)) -> Microsoft.AspNetCore.Http.IResult!
static Microsoft.AspNetCore.Http.Results.CreatedAtRoute<TValue>(string? routeName, Microsoft.AspNetCore.Routing.RouteValueDictionary! routeValues, TValue? value = default(TValue?)) -> Microsoft.AspNetCore.Http.IResult!
static Microsoft.AspNetCore.Http.Results.Json<TValue>(TValue? data, System.Text.Json.JsonSerializerOptions? options = null, string? contentType = null, int? statusCode = null) -> Microsoft.AspNetCore.Http.IResult!
static Microsoft.AspNetCore.Http.Results.NotFound<TValue>(TValue? value) -> Microsoft.AspNetCore.Http.IResult!
static Microsoft.AspNetCore.Http.Results.Ok<TValue>(TValue? value) -> Microsoft.AspNetCore.Http.IResult!
static Microsoft.AspNetCore.Http.Results.RedirectToRoute(string? routeName, Microsoft.AspNetCore.Routing.RouteValueDictionary? routeValues, bool permanent = false, bool preserveMethod = false, string? fragment = null) -> Microsoft.AspNetCore.Http.IResult!
static Microsoft.AspNetCore.Http.Results.Text(string? content, string? contentType = null, System.Text.Encoding? contentEncoding = null, int? statusCode = null) -> Microsoft.AspNetCore.Http.IResult!
static Microsoft.AspNetCore.Http.Results.Text(string? content, string? contentType, System.Text.Encoding? contentEncoding) -> Microsoft.AspNetCore.Http.IResult!
static Microsoft.AspNetCore.Http.Results.Text(System.ReadOnlySpan<byte> utf8Content, string? contentType = null, int? statusCode = null) -> Microsoft.AspNetCore.Http.IResult!
static Microsoft.AspNetCore.Http.Results.UnprocessableEntity<TValue>(TValue? error) -> Microsoft.AspNetCore.Http.IResult!
static Microsoft.AspNetCore.Http.TypedResults.AcceptedAtRoute(string? routeName, Microsoft.AspNetCore.Routing.RouteValueDictionary! routeValues) -> Microsoft.AspNetCore.Http.HttpResults.AcceptedAtRoute!
static Microsoft.AspNetCore.Http.TypedResults.AcceptedAtRoute<TValue>(TValue? value, string? routeName, Microsoft.AspNetCore.Routing.RouteValueDictionary! routeValues) -> Microsoft.AspNetCore.Http.HttpResults.AcceptedAtRoute<TValue>!
static Microsoft.AspNetCore.Http.TypedResults.Content(string? content, string? contentType = null, System.Text.Encoding? contentEncoding = null, int? statusCode = null) -> Microsoft.AspNetCore.Http.HttpResults.ContentHttpResult!
static Microsoft.AspNetCore.Http.TypedResults.Content(string? content, string? contentType, System.Text.Encoding? contentEncoding) -> Microsoft.AspNetCore.Http.HttpResults.ContentHttpResult!
static Microsoft.AspNetCore.Http.TypedResults.Created() -> Microsoft.AspNetCore.Http.HttpResults.Created!
static Microsoft.AspNetCore.Http.TypedResults.Created(string? uri) -> Microsoft.AspNetCore.Http.HttpResults.Created!
static Microsoft.AspNetCore.Http.TypedResults.Created(System.Uri? uri) -> Microsoft.AspNetCore.Http.HttpResults.Created!
static Microsoft.AspNetCore.Http.TypedResults.Created<TValue>(string? uri, TValue? value) -> Microsoft.AspNetCore.Http.HttpResults.Created<TValue>!
static Microsoft.AspNetCore.Http.TypedResults.Created<TValue>(System.Uri? uri, TValue? value) -> Microsoft.AspNetCore.Http.HttpResults.Created<TValue>!
static Microsoft.AspNetCore.Http.TypedResults.CreatedAtRoute(string? routeName, Microsoft.AspNetCore.Routing.RouteValueDictionary! routeValues) -> Microsoft.AspNetCore.Http.HttpResults.CreatedAtRoute!
static Microsoft.AspNetCore.Http.TypedResults.CreatedAtRoute<TValue>(TValue? value, string? routeName, Microsoft.AspNetCore.Routing.RouteValueDictionary! routeValues) -> Microsoft.AspNetCore.Http.HttpResults.CreatedAtRoute<TValue>!
static Microsoft.AspNetCore.Http.TypedResults.RedirectToRoute(string? routeName, Microsoft.AspNetCore.Routing.RouteValueDictionary? routeValues, bool permanent = false, bool preserveMethod = false, string? fragment = null) -> Microsoft.AspNetCore.Http.HttpResults.RedirectToRouteHttpResult!
static Microsoft.AspNetCore.Http.TypedResults.Text(string? content, string? contentType = null, System.Text.Encoding? contentEncoding = null, int? statusCode = null) -> Microsoft.AspNetCore.Http.HttpResults.ContentHttpResult!
static Microsoft.AspNetCore.Http.TypedResults.Text(string? content, string? contentType, System.Text.Encoding? contentEncoding) -> Microsoft.AspNetCore.Http.HttpResults.ContentHttpResult!
static Microsoft.AspNetCore.Http.TypedResults.Text(System.ReadOnlySpan<byte> utf8Content, string? contentType = null, int? statusCode = null) -> Microsoft.AspNetCore.Http.HttpResults.Utf8ContentHttpResult!
Expand Down
Loading

0 comments on commit e2494f1

Please sign in to comment.