@@ -42,11 +42,11 @@ public static RouteHandlerBuilder ExcludeFromDescription(this RouteHandlerBuilde
42
42
#pragma warning disable RS0026
43
43
public static RouteHandlerBuilder Produces < TResponse > ( this RouteHandlerBuilder builder ,
44
44
#pragma warning restore RS0026
45
- int statusCode = StatusCodes . Status200OK ,
45
+ int statusCode = StatusCodes . Status200OK ,
46
46
string ? contentType = null ,
47
47
params string [ ] additionalContentTypes )
48
48
{
49
- return Produces ( builder , statusCode , typeof ( TResponse ) , contentType , additionalContentTypes ) ;
49
+ return Produces ( builder , statusCode , null , typeof ( TResponse ) , contentType , additionalContentTypes ) ;
50
50
}
51
51
52
52
/// <summary>
@@ -55,14 +55,16 @@ public static RouteHandlerBuilder Produces<TResponse>(this RouteHandlerBuilder b
55
55
/// </summary>
56
56
/// <param name="builder">The <see cref="RouteHandlerBuilder"/>.</param>
57
57
/// <param name="statusCode">The response status code.</param>
58
+ /// <param name="description">The response status code.</param>
58
59
/// <param name="responseType">The type of the response. Defaults to null.</param>
59
60
/// <param name="contentType">The response content type. Defaults to "application/json" if responseType is not null, otherwise defaults to null.</param>
60
61
/// <param name="additionalContentTypes">Additional response content types the endpoint produces for the supplied status code.</param>
61
62
/// <returns>A <see cref="RouteHandlerBuilder"/> that can be used to further customize the endpoint.</returns>
62
63
#pragma warning disable RS0026
63
64
public static RouteHandlerBuilder Produces ( this RouteHandlerBuilder builder ,
64
65
#pragma warning restore RS0026
65
- int statusCode ,
66
+ int statusCode ,
67
+ string ? description = null ,
66
68
Type ? responseType = null ,
67
69
string ? contentType = null ,
68
70
params string [ ] additionalContentTypes )
@@ -74,7 +76,13 @@ public static RouteHandlerBuilder Produces(this RouteHandlerBuilder builder,
74
76
75
77
if ( contentType is null )
76
78
{
77
- builder . WithMetadata ( new ProducesResponseTypeMetadata ( responseType ?? typeof ( void ) , statusCode ) ) ;
79
+ builder . WithMetadata ( new ProducesResponseTypeMetadata ( responseType ?? typeof ( void ) , statusCode , description ) ) ;
80
+ return builder ;
81
+ }
82
+
83
+ if ( description is not null )
84
+ {
85
+ builder . WithMetadata ( new ProducesResponseTypeMetadata ( responseType ?? typeof ( void ) , description , statusCode , contentType , additionalContentTypes ) ) ;
78
86
return builder ;
79
87
}
80
88
@@ -209,6 +217,94 @@ public static RouteHandlerBuilder Accepts(this RouteHandlerBuilder builder,
209
217
return builder ;
210
218
}
211
219
220
+ /// <summary>
221
+ /// Adds <see cref="IExampleMetadata"/> to <see cref="EndpointBuilder.Metadata"/> representing
222
+ /// an example of the parameter for all builders produced by <paramref name="builder"/>.
223
+ /// </summary>
224
+ /// <param name="builder">The <see cref="RouteHandlerBuilder"/>.</param>
225
+ /// <param name="parameterName">A string representing the name of the parameter associated with the example.</param>
226
+ /// <param name="summary">A string representing a summary of the example.</param>
227
+ /// <param name="description">A string representing a detailed description of the example.</param>
228
+ /// <param name="value">An object representing the example associated with a particualr type.</param>
229
+ /// <returns>A <see cref="RouteHandlerBuilder"/> that can be used to further customize the endpoint.</returns>
230
+ public static RouteHandlerBuilder WithParameterExample ( this RouteHandlerBuilder builder , string parameterName , string summary , string description , object value )
231
+ {
232
+ builder . WithMetadata ( new ExampleAttribute ( summary , description , value ) { ParameterName = parameterName } ) ;
233
+ return builder ;
234
+ }
235
+
236
+ /// <summary>
237
+ /// Adds <see cref="IExampleMetadata"/> to <see cref="EndpointBuilder.Metadata"/> representing
238
+ /// an example of the parameter for all builders produced by <paramref name="builder"/>.
239
+ /// </summary>
240
+ /// <param name="builder">The <see cref="RouteHandlerBuilder"/>.</param>
241
+ /// <param name="parameterName">A string representing the name of the parameter associated with the example.</param>
242
+ /// <param name="summary">A string representing a summary of the example.</param>
243
+ /// <param name="description">A string representing a detailed description of the example.</param>
244
+ /// <param name="externalValue">A string pointing to a reference of the example.</param>
245
+ /// <returns>A <see cref="RouteHandlerBuilder"/> that can be used to further customize the endpoint.</returns>
246
+ public static RouteHandlerBuilder WithParameterExample ( this RouteHandlerBuilder builder , string parameterName , string summary , string description , string externalValue )
247
+ {
248
+ builder . WithMetadata ( new ExampleAttribute ( summary , description , externalValue ) { ParameterName = parameterName } ) ;
249
+ return builder ;
250
+ }
251
+
252
+ /// <summary>
253
+ /// Adds <see cref="IExampleMetadata"/> to <see cref="EndpointBuilder.Metadata"/> representing
254
+ /// an example of the response type for all builders produced by <paramref name="builder"/>.
255
+ /// </summary>
256
+ /// <param name="builder">The <see cref="RouteHandlerBuilder"/>.</param>
257
+ /// <param name="summary">A string representing a summary of the example.</param>
258
+ /// <param name="description">A string representing a detailed description of the example.</param>
259
+ /// <param name="value">An object representing the example associated with a particualr type.</param>
260
+ /// <returns>A <see cref="RouteHandlerBuilder"/> that can be used to further customize the endpoint.</returns>
261
+ public static RouteHandlerBuilder WithResponseExample ( this RouteHandlerBuilder builder , string summary , string description , object value )
262
+ {
263
+ builder . WithMetadata ( new ExampleAttribute ( summary , description , value ) ) ;
264
+ return builder ;
265
+ }
266
+
267
+ /// <summary>
268
+ /// Adds <see cref="IExampleMetadata"/> to <see cref="EndpointBuilder.Metadata"/> representing
269
+ /// an example of the response type for all builders produced by <paramref name="builder"/>.
270
+ /// </summary>
271
+ /// <param name="builder">The <see cref="RouteHandlerBuilder"/>.</param>
272
+ /// <param name="summary">A string representing a summary of the example.</param>
273
+ /// <param name="description">A string representing a detailed description of the example.</param>
274
+ /// <param name="externalValue">A string pointing to a reference of the example.</param>
275
+ /// <returns>A <see cref="RouteHandlerBuilder"/> that can be used to further customize the endpoint.</returns>
276
+ public static RouteHandlerBuilder WithResponseExample ( this RouteHandlerBuilder builder , string summary , string description , string externalValue )
277
+ {
278
+ builder . WithMetadata ( new ExampleAttribute ( summary , description , externalValue ) ) ;
279
+ return builder ;
280
+ }
281
+
282
+ /// <summary>
283
+ /// Adds <see cref="IDescriptionMetadata"/> to <see cref="EndpointBuilder.Metadata"/> for all builders
284
+ /// produced by <paramref name="builder"/>.
285
+ /// </summary>
286
+ /// <param name="builder">The <see cref="RouteHandlerBuilder"/>.</param>
287
+ /// <param name="description">A string representing a detailed description of the endpoint.</param>
288
+ /// <returns>A <see cref="RouteHandlerBuilder"/> that can be used to further customize the endpoint.</returns>
289
+ public static RouteHandlerBuilder WithDescription ( this RouteHandlerBuilder builder , string description )
290
+ {
291
+ builder . WithMetadata ( new DescriptionAttribute ( description ) ) ;
292
+ return builder ;
293
+ }
294
+
295
+ /// <summary>
296
+ /// Adds <see cref="ISummaryMetadata"/> to <see cref="EndpointBuilder.Metadata"/> for all builders
297
+ /// produced by <paramref name="builder"/>.
298
+ /// </summary>
299
+ /// <param name="builder">The <see cref="RouteHandlerBuilder"/>.</param>
300
+ /// <param name="summary">A string representation a brief description of the endpoint.</param>
301
+ /// <returns>A <see cref="RouteHandlerBuilder"/> that can be used to further customize the endpoint.</returns>
302
+ public static RouteHandlerBuilder WithSummary ( this RouteHandlerBuilder builder , string summary )
303
+ {
304
+ builder . WithMetadata ( new SummaryAttribute ( summary ) ) ;
305
+ return builder ;
306
+ }
307
+
212
308
private static string [ ] GetAllContentTypes ( string contentType , string [ ] additionalContentTypes )
213
309
{
214
310
var allContentTypes = new string [ additionalContentTypes . Length + 1 ] ;
0 commit comments