@@ -34,38 +34,6 @@ public static TBuilder ExcludeFromDescription<TBuilder>(this TBuilder builder) w
34
34
public static RouteHandlerBuilder ExcludeFromDescription ( this RouteHandlerBuilder builder )
35
35
=> ExcludeFromDescription < RouteHandlerBuilder > ( builder ) ;
36
36
37
- /// <summary>
38
- /// Adds an <see cref="IProducesResponseTypeMetadata"/> to <see cref="EndpointBuilder.Metadata"/> for all endpoints
39
- /// produced by <paramref name="builder"/>.
40
- /// </summary>
41
- /// <param name="builder">The <see cref="IEndpointConventionBuilder"/>.</param>
42
- /// <param name="responseType">The type of the response. Defaults to null.</param>
43
- /// <param name="statusCode">The response status code.</param>
44
- /// <param name="contentType">The response content type. Defaults to "application/json" if responseType is not null, otherwise defaults to null.</param>
45
- /// <param name="additionalContentTypes">Additional response content types the endpoint produces for the supplied status code.</param>
46
- /// <returns>A <see cref="RouteHandlerBuilder"/> that can be used to further customize the endpoint.</returns>
47
- #pragma warning disable RS0026
48
- public static TBuilder Produces < TBuilder > (
49
- #pragma warning restore RS0026
50
- this TBuilder builder ,
51
- Type ? responseType = null ,
52
- int statusCode = StatusCodes . Status200OK ,
53
- string ? contentType = null ,
54
- params string [ ] additionalContentTypes ) where TBuilder : IEndpointConventionBuilder
55
- {
56
- if ( responseType is Type && string . IsNullOrEmpty ( contentType ) )
57
- {
58
- contentType = "application/json" ;
59
- }
60
-
61
- if ( contentType is null )
62
- {
63
- return builder . WithMetadata ( new ProducesResponseTypeMetadata ( responseType ?? typeof ( void ) , statusCode ) ) ;
64
- }
65
-
66
- return builder . WithMetadata ( new ProducesResponseTypeMetadata ( responseType ?? typeof ( void ) , statusCode , contentType , additionalContentTypes ) ) ;
67
- }
68
-
69
37
/// <summary>
70
38
/// Adds an <see cref="IProducesResponseTypeMetadata"/> to <see cref="EndpointBuilder.Metadata"/> for all endpoints
71
39
/// produced by <paramref name="builder"/>.
@@ -84,7 +52,7 @@ public static RouteHandlerBuilder Produces<TResponse>(
84
52
string ? contentType = null ,
85
53
params string [ ] additionalContentTypes )
86
54
{
87
- return Produces ( builder , typeof ( TResponse ) , statusCode , contentType , additionalContentTypes ) ;
55
+ return Produces ( builder , statusCode , typeof ( TResponse ) , contentType , additionalContentTypes ) ;
88
56
}
89
57
90
58
/// <summary>
@@ -106,30 +74,17 @@ public static RouteHandlerBuilder Produces(
106
74
string ? contentType = null ,
107
75
params string [ ] additionalContentTypes )
108
76
{
109
- return Produces ( builder , responseType , statusCode , contentType , additionalContentTypes ) ;
110
- }
77
+ if ( responseType is Type && string . IsNullOrEmpty ( contentType ) )
78
+ {
79
+ contentType = "application/json" ;
80
+ }
111
81
112
- /// <summary>
113
- /// Adds an <see cref="IProducesResponseTypeMetadata"/> with a <see cref="ProblemDetails"/> type
114
- /// to <see cref="EndpointBuilder.Metadata"/> for all endpoints produced by <paramref name="builder"/>.
115
- /// </summary>
116
- /// <param name="builder">The <see cref="IEndpointConventionBuilder"/>.</param>
117
- /// <param name="statusCode">The response status code.</param>
118
- /// <param name="contentType">The response content type. Defaults to "application/problem+json".</param>
119
- /// <returns>A <see cref="RouteHandlerBuilder"/> that can be used to further customize the endpoint.</returns>
120
- #pragma warning disable RS0026
121
- public static TBuilder ProducesProblem < TBuilder > (
122
- #pragma warning restore RS0026
123
- this TBuilder builder ,
124
- int statusCode ,
125
- string ? contentType = null ) where TBuilder : IEndpointConventionBuilder
126
- {
127
- if ( string . IsNullOrEmpty ( contentType ) )
82
+ if ( contentType is null )
128
83
{
129
- contentType = "application/problem+json" ;
84
+ return builder . WithMetadata ( new ProducesResponseTypeMetadata ( responseType ?? typeof ( void ) , statusCode ) ) ;
130
85
}
131
86
132
- return Produces ( builder , typeof ( ProblemDetails ) , statusCode , contentType ) ;
87
+ return builder . WithMetadata ( new ProducesResponseTypeMetadata ( responseType ?? typeof ( void ) , statusCode , contentType , additionalContentTypes ) ) ;
133
88
}
134
89
135
90
/// <summary>
@@ -141,45 +96,27 @@ public static TBuilder ProducesProblem<TBuilder>(
141
96
/// <param name="contentType">The response content type. Defaults to "application/problem+json".</param>
142
97
/// <returns>A <see cref="RouteHandlerBuilder"/> that can be used to further customize the endpoint.</returns>
143
98
public static RouteHandlerBuilder ProducesProblem ( this RouteHandlerBuilder builder , int statusCode , string ? contentType = null )
144
- => ProducesProblem < RouteHandlerBuilder > ( builder , statusCode , contentType ) ;
99
+ => ProducesProblem ( builder , statusCode , contentType ) ;
145
100
146
101
/// <summary>
147
102
/// Adds an <see cref="IProducesResponseTypeMetadata"/> with a <see cref="HttpValidationProblemDetails"/> type
148
103
/// to <see cref="EndpointBuilder.Metadata"/> for all endpoints produced by <paramref name="builder"/>.
149
104
/// </summary>
150
- /// <param name="builder">The <see cref="IEndpointConventionBuilder "/>.</param>
105
+ /// <param name="builder">The <see cref="RouteHandlerBuilder "/>.</param>
151
106
/// <param name="statusCode">The response status code. Defaults to <see cref="StatusCodes.Status400BadRequest"/>.</param>
152
107
/// <param name="contentType">The response content type. Defaults to "application/problem+json".</param>
153
108
/// <returns>A <see cref="RouteHandlerBuilder"/> that can be used to further customize the endpoint.</returns>
154
- #pragma warning disable RS0026
155
- public static TBuilder ProducesValidationProblem < TBuilder > (
156
- #pragma warning restore RS0026
157
- this TBuilder builder ,
109
+ public static RouteHandlerBuilder ProducesValidationProblem (
110
+ this RouteHandlerBuilder builder ,
158
111
int statusCode = StatusCodes . Status400BadRequest ,
159
- string ? contentType = null ) where TBuilder : IEndpointConventionBuilder
112
+ string ? contentType = null )
160
113
{
161
114
if ( string . IsNullOrEmpty ( contentType ) )
162
115
{
163
116
contentType = "application/problem+json" ;
164
117
}
165
118
166
- return Produces ( builder , typeof ( HttpValidationProblemDetails ) , statusCode , contentType ) ;
167
- }
168
-
169
- /// <summary>
170
- /// Adds an <see cref="IProducesResponseTypeMetadata"/> with a <see cref="HttpValidationProblemDetails"/> type
171
- /// to <see cref="EndpointBuilder.Metadata"/> for all endpoints produced by <paramref name="builder"/>.
172
- /// </summary>
173
- /// <param name="builder">The <see cref="RouteHandlerBuilder"/>.</param>
174
- /// <param name="statusCode">The response status code. Defaults to <see cref="StatusCodes.Status400BadRequest"/>.</param>
175
- /// <param name="contentType">The response content type. Defaults to "application/problem+json".</param>
176
- /// <returns>A <see cref="RouteHandlerBuilder"/> that can be used to further customize the endpoint.</returns>
177
- public static RouteHandlerBuilder ProducesValidationProblem (
178
- this RouteHandlerBuilder builder ,
179
- int statusCode = StatusCodes . Status400BadRequest ,
180
- string ? contentType = null )
181
- {
182
- return ProducesValidationProblem < RouteHandlerBuilder > ( builder , statusCode , contentType ) ;
119
+ return Produces ( builder , statusCode , typeof ( HttpValidationProblemDetails ) , contentType ) ;
183
120
}
184
121
185
122
/// <summary>
@@ -212,45 +149,6 @@ public static TBuilder WithTags<TBuilder>(this TBuilder builder, params string[]
212
149
public static RouteHandlerBuilder WithTags ( this RouteHandlerBuilder builder , params string [ ] tags )
213
150
=> WithTags < RouteHandlerBuilder > ( builder , tags ) ;
214
151
215
- /// <summary>
216
- /// Adds <see cref="IAcceptsMetadata"/> to <see cref="EndpointBuilder.Metadata"/> for all endpoints
217
- /// produced by <paramref name="builder"/>.
218
- /// </summary>
219
- /// <param name="builder">The <see cref="IEndpointConventionBuilder"/>.</param>
220
- /// <param name="requestType">The type of the request body.</param>
221
- /// <param name="isOptional">Sets a value that determines if the request body is optional.</param>
222
- /// <param name="contentType">The request content type that the endpoint accepts.</param>
223
- /// <param name="additionalContentTypes">The list of additional request content types that the endpoint accepts.</param>
224
- /// <returns>A <see cref="RouteHandlerBuilder"/> that can be used to further customize the endpoint.</returns>
225
- public static TBuilder Accepts < TBuilder > (
226
- this TBuilder builder ,
227
- Type requestType ,
228
- bool isOptional ,
229
- string contentType ,
230
- params string [ ] additionalContentTypes ) where TBuilder : IEndpointConventionBuilder
231
- {
232
- var contentTypes = GetAllContentTypes ( contentType , additionalContentTypes ) ;
233
- return builder . WithMetadata ( new AcceptsMetadata ( requestType , isOptional , contentTypes ) ) ;
234
- }
235
-
236
- /// <summary>
237
- /// Adds <see cref="IAcceptsMetadata"/> to <see cref="EndpointBuilder.Metadata"/> for all endpoints
238
- /// produced by <paramref name="builder"/>.
239
- /// </summary>
240
- /// <param name="builder">The <see cref="IEndpointConventionBuilder"/>.</param>
241
- /// <param name="requestType">The type of the request body.</param>
242
- /// <param name="contentType">The request content type that the endpoint accepts.</param>
243
- /// <param name="additionalContentTypes">The list of additional request content types that the endpoint accepts.</param>
244
- /// <returns>A <see cref="RouteHandlerBuilder"/> that can be used to further customize the endpoint.</returns>
245
- public static TBuilder Accepts < TBuilder > (
246
- this TBuilder builder ,
247
- Type requestType ,
248
- string contentType ,
249
- params string [ ] additionalContentTypes ) where TBuilder : IEndpointConventionBuilder
250
- {
251
- return Accepts ( builder , requestType , isOptional : false , contentType , additionalContentTypes ) ;
252
- }
253
-
254
152
/// <summary>
255
153
/// Adds <see cref="IAcceptsMetadata"/> to <see cref="EndpointBuilder.Metadata"/> for all endpoints
256
154
/// produced by <paramref name="builder"/>.
@@ -265,7 +163,7 @@ public static RouteHandlerBuilder Accepts<TRequest>(
265
163
string contentType ,
266
164
params string [ ] additionalContentTypes ) where TRequest : notnull
267
165
{
268
- return Accepts < RouteHandlerBuilder > ( builder , typeof ( TRequest ) , contentType , additionalContentTypes ) ;
166
+ return Accepts ( builder , typeof ( TRequest ) , contentType , additionalContentTypes ) ;
269
167
}
270
168
271
169
/// <summary>
@@ -284,7 +182,7 @@ public static RouteHandlerBuilder Accepts<TRequest>(
284
182
string contentType ,
285
183
params string [ ] additionalContentTypes ) where TRequest : notnull
286
184
{
287
- return Accepts < RouteHandlerBuilder > ( builder , typeof ( TRequest ) , isOptional , contentType , additionalContentTypes ) ;
185
+ return Accepts ( builder , typeof ( TRequest ) , isOptional , contentType , additionalContentTypes ) ;
288
186
}
289
187
290
188
/// <summary>
@@ -302,7 +200,7 @@ public static RouteHandlerBuilder Accepts(
302
200
string contentType ,
303
201
params string [ ] additionalContentTypes )
304
202
{
305
- return Accepts < RouteHandlerBuilder > ( builder , requestType , contentType , additionalContentTypes ) ;
203
+ return Accepts ( builder , requestType , isOptional : false , contentType , additionalContentTypes ) ;
306
204
}
307
205
308
206
/// <summary>
@@ -322,7 +220,8 @@ public static RouteHandlerBuilder Accepts(
322
220
string contentType ,
323
221
params string [ ] additionalContentTypes )
324
222
{
325
- return Accepts < RouteHandlerBuilder > ( builder , requestType , isOptional , contentType , additionalContentTypes ) ;
223
+ var contentTypes = GetAllContentTypes ( contentType , additionalContentTypes ) ;
224
+ return builder . WithMetadata ( new AcceptsMetadata ( requestType , isOptional , contentTypes ) ) ;
326
225
}
327
226
328
227
/// <summary>
0 commit comments