Skip to content

Commit f7416da

Browse files
committed
Changed code to follow overload rules and fix compile issues
1 parent 442d101 commit f7416da

File tree

14 files changed

+25
-58
lines changed

14 files changed

+25
-58
lines changed

src/Http/Http.Abstractions/src/Metadata/ProducesResponseTypeMetadata.cs

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ public sealed class ProducesResponseTypeMetadata : IProducesResponseTypeMetadata
2121
/// <param name="statusCode">The HTTP response status code.</param>
2222
/// <param name="type">The <see cref="Type"/> of object that is going to be written in the response.</param>
2323
/// <param name="contentTypes">Content types supported by the response.</param>
24-
public ProducesResponseTypeMetadata(int statusCode, Type? type = null, string[]? contentTypes = null)
24+
/// <param name="description">The description of the response.</param>
25+
public ProducesResponseTypeMetadata(int statusCode, Type? type = null, string[]? contentTypes = null, string? description = null)
2526
{
2627
StatusCode = statusCode;
2728
Type = type;
29+
Description = description;
2830

2931
if (contentTypes is null || contentTypes.Length == 0)
3032
{
@@ -50,58 +52,22 @@ static void ValidateContentType(string type)
5052
}
5153
}
5254

55+
// 9.0 BACKCOMPAT OVERLOAD -- DO NOT TOUCH
5356
/// <summary>
5457
/// Initializes an instance of <see cref="ProducesResponseTypeMetadata"/>.
5558
/// </summary>
5659
/// <param name="statusCode">The HTTP response status code.</param>
5760
/// <param name="type">The <see cref="Type"/> of object that is going to be written in the response.</param>
58-
/// <param name="description">The descrption of the response.</param>
5961
/// <param name="contentTypes">Content types supported by the response.</param>
60-
public ProducesResponseTypeMetadata(int statusCode, Type? type = null, string? description = null, string[]? contentTypes = null)
61-
{
62-
StatusCode = statusCode;
63-
Type = type;
64-
Description = description;
65-
66-
if (contentTypes is null || contentTypes.Length == 0)
67-
{
68-
ContentTypes = Enumerable.Empty<string>();
69-
}
70-
else
71-
{
72-
for (var i = 0; i < contentTypes.Length; i++)
73-
{
74-
MediaTypeHeaderValue.Parse(contentTypes[i]);
75-
ValidateContentType(contentTypes[i]);
76-
}
77-
78-
ContentTypes = contentTypes;
79-
}
80-
81-
static void ValidateContentType(string type)
82-
{
83-
if (type.Contains('*', StringComparison.OrdinalIgnoreCase))
84-
{
85-
throw new InvalidOperationException($"Could not parse '{type}'. Content types with wildcards are not supported.");
86-
}
87-
}
88-
}
62+
public ProducesResponseTypeMetadata(int statusCode, Type? type = null, string[]? contentTypes = null) : this(statusCode, type, contentTypes, description: null) { }
8963

9064
// Only for internal use where validation is unnecessary.
91-
private ProducesResponseTypeMetadata(int statusCode, Type? type, IEnumerable<string> contentTypes)
65+
private ProducesResponseTypeMetadata(int statusCode, Type? type, IEnumerable<string> contentTypes, string? description = null)
9266
{
9367
Type = type;
9468
StatusCode = statusCode;
9569
ContentTypes = contentTypes;
96-
}
97-
98-
// Only for internal use where validation is unnecessary.
99-
private ProducesResponseTypeMetadata(int statusCode, Type? type, string? description, IEnumerable<string> contentTypes)
100-
{
101-
Type = type;
102-
StatusCode = statusCode;
10370
Description = description;
104-
ContentTypes = contentTypes;
10571
}
10672

10773
/// <summary>
@@ -127,9 +93,8 @@ private ProducesResponseTypeMetadata(int statusCode, Type? type, string? descrip
12793
/// <inheritdoc/>
12894
public override string ToString()
12995
{
130-
return DebuggerHelpers.GetDebugText(nameof(StatusCode), StatusCode, nameof(ContentTypes), ContentTypes, nameof(Type), Type, nameof(Description), Description, includeNullValues: false, prefix: "Produces");
96+
return DebuggerHelpers.GetDebugText(nameof(StatusCode), StatusCode, nameof(ContentTypes), ContentTypes, nameof(Type), Type, includeNullValues: false, prefix: "Produces");
13197
}
13298

133-
internal static ProducesResponseTypeMetadata CreateUnvalidated(Type? type, int statusCode, IEnumerable<string> contentTypes) => new(statusCode, type, contentTypes);
134-
internal static ProducesResponseTypeMetadata CreateUnvalidated(Type? type, int statusCode, string? description, IEnumerable<string> contentTypes) => new(statusCode, type, description, contentTypes);
99+
internal static ProducesResponseTypeMetadata CreateUnvalidated(Type? type, int statusCode, IEnumerable<string> contentTypes, string? description) => new(statusCode, type, contentTypes, description);
135100
}

src/Http/Http.Abstractions/src/PublicAPI.Unshipped.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ Microsoft.AspNetCore.Http.Metadata.IParameterBindingMetadata.Name.get -> string!
1313
Microsoft.AspNetCore.Http.Metadata.IParameterBindingMetadata.ParameterInfo.get -> System.Reflection.ParameterInfo!
1414
Microsoft.AspNetCore.Http.ProducesResponseTypeMetadata.Description.get -> string?
1515
Microsoft.AspNetCore.Http.Metadata.IProducesResponseTypeMetadata.Description.get -> string?
16+
*REMOVED*Microsoft.AspNetCore.Http.ProducesResponseTypeMetadata.ProducesResponseTypeMetadata(int statusCode, System.Type? type = null, string![]? contentTypes = null) -> void
17+
Microsoft.AspNetCore.Http.ProducesResponseTypeMetadata.ProducesResponseTypeMetadata(int statusCode, System.Type? type = null, string![]? contentTypes = null, string? description = null) -> void

src/Http/Http.Extensions/src/RequestDelegateFactory.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ private static RequestDelegateFactoryContext CreateFactoryContext(RequestDelegat
274274
var serviceProvider = options?.ServiceProvider ?? options?.EndpointBuilder?.ApplicationServices ?? EmptyServiceProvider.Instance;
275275
var endpointBuilder = options?.EndpointBuilder ?? new RdfEndpointBuilder(serviceProvider);
276276
var jsonSerializerOptions = serviceProvider.GetService<IOptions<JsonOptions>>()?.Value.SerializerOptions ?? JsonOptions.DefaultSerializerOptions;
277-
var formDataMapperOptions = new FormDataMapperOptions();;
277+
var formDataMapperOptions = new FormDataMapperOptions(); ;
278278

279279
var factoryContext = new RequestDelegateFactoryContext
280280
{
@@ -1039,15 +1039,15 @@ private static void PopulateBuiltInResponseTypeMetadata(Type returnType, Endpoin
10391039

10401040
if (returnType == typeof(string))
10411041
{
1042-
builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(type: typeof(string), statusCode: 200, PlaintextContentType));
1042+
builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(type: typeof(string), statusCode: 200, PlaintextContentType, description: null));
10431043
}
10441044
else if (returnType == typeof(void))
10451045
{
1046-
builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(returnType, statusCode: 200, PlaintextContentType));
1046+
builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(returnType, statusCode: 200, PlaintextContentType), description: null);
10471047
}
10481048
else
10491049
{
1050-
builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(returnType, statusCode: 200, DefaultAcceptsAndProducesContentType));
1050+
builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(returnType, statusCode: 200, DefaultAcceptsAndProducesContentType), description: null);
10511051
}
10521052
}
10531053

src/Http/Http.Results/src/AcceptedAtRouteOfT.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,6 @@ static void IEndpointMetadataProvider.PopulateMetadata(MethodInfo method, Endpoi
122122
ArgumentNullException.ThrowIfNull(method);
123123
ArgumentNullException.ThrowIfNull(builder);
124124

125-
builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(typeof(TValue), StatusCodes.Status202Accepted, ContentTypeConstants.ApplicationJsonContentTypes));
125+
builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(typeof(TValue), StatusCodes.Status202Accepted, ContentTypeConstants.ApplicationJsonContentTypes, description: null));
126126
}
127127
}

src/Http/Http.Results/src/AcceptedOfT.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,6 @@ static void IEndpointMetadataProvider.PopulateMetadata(MethodInfo method, Endpoi
100100
ArgumentNullException.ThrowIfNull(method);
101101
ArgumentNullException.ThrowIfNull(builder);
102102

103-
builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(typeof(TValue), StatusCodes.Status202Accepted, ContentTypeConstants.ApplicationJsonContentTypes));
103+
builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(typeof(TValue), StatusCodes.Status202Accepted, ContentTypeConstants.ApplicationJsonContentTypes, description: null));
104104
}
105105
}

src/Http/Http.Results/src/BadRequestOfT.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,6 @@ static void IEndpointMetadataProvider.PopulateMetadata(MethodInfo method, Endpoi
6565
ArgumentNullException.ThrowIfNull(method);
6666
ArgumentNullException.ThrowIfNull(builder);
6767

68-
builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(typeof(TValue), StatusCodes.Status400BadRequest, ContentTypeConstants.ApplicationJsonContentTypes));
68+
builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(typeof(TValue), StatusCodes.Status400BadRequest, ContentTypeConstants.ApplicationJsonContentTypes, description: null));
6969
}
7070
}

src/Http/Http.Results/src/ConflictOfT.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,6 @@ static void IEndpointMetadataProvider.PopulateMetadata(MethodInfo method, Endpoi
6565
ArgumentNullException.ThrowIfNull(method);
6666
ArgumentNullException.ThrowIfNull(builder);
6767

68-
builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(typeof(TValue), StatusCodes.Status409Conflict, ContentTypeConstants.ApplicationJsonContentTypes));
68+
builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(typeof(TValue), StatusCodes.Status409Conflict, ContentTypeConstants.ApplicationJsonContentTypes, description: null));
6969
}
7070
}

src/Http/Http.Results/src/CreatedAtRouteOfT.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,6 @@ static void IEndpointMetadataProvider.PopulateMetadata(MethodInfo method, Endpoi
125125
ArgumentNullException.ThrowIfNull(method);
126126
ArgumentNullException.ThrowIfNull(builder);
127127

128-
builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(typeof(TValue), StatusCodes.Status201Created, ContentTypeConstants.ApplicationJsonContentTypes));
128+
builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(typeof(TValue), StatusCodes.Status201Created, ContentTypeConstants.ApplicationJsonContentTypes, description: null));
129129
}
130130
}

src/Http/Http.Results/src/CreatedOfT.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,6 @@ static void IEndpointMetadataProvider.PopulateMetadata(MethodInfo method, Endpoi
9999
ArgumentNullException.ThrowIfNull(method);
100100
ArgumentNullException.ThrowIfNull(builder);
101101

102-
builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(typeof(TValue), StatusCodes.Status201Created, ContentTypeConstants.ApplicationJsonContentTypes));
102+
builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(typeof(TValue), StatusCodes.Status201Created, ContentTypeConstants.ApplicationJsonContentTypes, description: null));
103103
}
104104
}

src/Http/Http.Results/src/InternalServerErrorOfT.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,6 @@ static void IEndpointMetadataProvider.PopulateMetadata(MethodInfo method, Endpoi
6565
ArgumentNullException.ThrowIfNull(method);
6666
ArgumentNullException.ThrowIfNull(builder);
6767

68-
builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(typeof(TValue), StatusCodes.Status500InternalServerError, ContentTypeConstants.ApplicationJsonContentTypes));
68+
builder.Metadata.Add(ProducesResponseTypeMetadata.CreateUnvalidated(typeof(TValue), StatusCodes.Status500InternalServerError, ContentTypeConstants.ApplicationJsonContentTypes, description: null));
6969
}
7070
}

0 commit comments

Comments
 (0)