@@ -471,23 +471,46 @@ public static IResult UnprocessableEntity(object? error = null)
471
471
/// <param name="instance">The value for <see cref="ProblemDetails.Instance" />.</param>
472
472
/// <param name="title">The value for <see cref="ProblemDetails.Title" />.</param>
473
473
/// <param name="type">The value for <see cref="ProblemDetails.Type" />.</param>
474
+ /// <param name="extensions">The value for <see cref="ProblemDetails.Extensions" />.</param>
474
475
/// <returns>The created <see cref="IResult"/> for the response.</returns>
475
476
public static IResult Problem (
476
477
string ? detail = null ,
477
478
string ? instance = null ,
478
479
int ? statusCode = null ,
479
480
string ? title = null ,
480
- string ? type = null )
481
+ string ? type = null ,
482
+ IDictionary < string , object ? > ? extensions = null )
481
483
{
482
484
var problemDetails = new ProblemDetails
483
485
{
484
486
Detail = detail ,
485
487
Instance = instance ,
486
488
Status = statusCode ,
487
489
Title = title ,
488
- Type = type
490
+ Type = type ,
489
491
} ;
490
492
493
+ if ( extensions is not null )
494
+ {
495
+ foreach ( var extension in extensions )
496
+ {
497
+ problemDetails . Extensions . Add ( extension ) ;
498
+ }
499
+ }
500
+
501
+ return new ObjectResult ( problemDetails )
502
+ {
503
+ ContentType = "application/problem+json" ,
504
+ } ;
505
+ }
506
+
507
+ /// <summary>
508
+ /// Produces a <see cref="ProblemDetails"/> response.
509
+ /// </summary>
510
+ /// <param name="problemDetails">The <see cref="ProblemDetails"/> object to produce a response from.</param>
511
+ /// <returns>The created <see cref="IResult"/> for the response.</returns>
512
+ public static IResult Problem ( ProblemDetails problemDetails )
513
+ {
491
514
return new ObjectResult ( problemDetails )
492
515
{
493
516
ContentType = "application/problem+json" ,
@@ -502,25 +525,36 @@ public static IResult Problem(
502
525
/// <param name="detail">The value for <see cref="ProblemDetails.Detail" />.</param>
503
526
/// <param name="instance">The value for <see cref="ProblemDetails.Instance" />.</param>
504
527
/// <param name="statusCode">The status code.</param>
505
- /// <param name="title">The value for <see cref="ProblemDetails.Title" />.</param>
528
+ /// <param name="title">The value for <see cref="ProblemDetails.Title" />. Defaults to "One or more validation errors occurred." </param>
506
529
/// <param name="type">The value for <see cref="ProblemDetails.Type" />.</param>
530
+ /// <param name="extensions">The value for <see cref="ProblemDetails.Extensions" />.</param>
507
531
/// <returns>The created <see cref="IResult"/> for the response.</returns>
508
532
public static IResult ValidationProblem (
509
533
IDictionary < string , string [ ] > errors ,
510
534
string ? detail = null ,
511
535
string ? instance = null ,
512
536
int ? statusCode = null ,
513
537
string ? title = null ,
514
- string ? type = null )
538
+ string ? type = null ,
539
+ IDictionary < string , object ? > ? extensions = null )
515
540
{
516
541
var problemDetails = new HttpValidationProblemDetails ( errors )
517
542
{
518
543
Detail = detail ,
519
544
Instance = instance ,
520
- Title = title ,
521
545
Type = type ,
522
546
Status = statusCode ,
523
547
} ;
548
+
549
+ problemDetails . Title = title ?? problemDetails . Title ;
550
+
551
+ if ( extensions is not null )
552
+ {
553
+ foreach ( var extension in extensions )
554
+ {
555
+ problemDetails . Extensions . Add ( extension ) ;
556
+ }
557
+ }
524
558
525
559
return new ObjectResult ( problemDetails )
526
560
{
0 commit comments