@@ -471,13 +471,15 @@ 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
{
@@ -488,6 +490,27 @@ public static IResult Problem(
488
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" ,
@@ -504,24 +527,47 @@ public static IResult Problem(
504
527
/// <param name="statusCode">The status code.</param>
505
528
/// <param name="title">The value for <see cref="ProblemDetails.Title" />.</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
545
Title = title ,
521
546
Type = type ,
522
- Status = statusCode ,
547
+ Status = statusCode
523
548
} ;
524
549
550
+ if ( extensions is not null )
551
+ {
552
+ foreach ( var extension in extensions )
553
+ {
554
+ problemDetails . Extensions . Add ( extension ) ;
555
+ }
556
+ }
557
+
558
+ return new ObjectResult ( problemDetails )
559
+ {
560
+ ContentType = "application/problem+json" ,
561
+ } ;
562
+ }
563
+
564
+ /// <summary>
565
+ /// Produces a <see cref="HttpValidationProblemDetails"/> response.
566
+ /// </summary>
567
+ /// <param name="problemDetails">The <see cref="HttpValidationProblemDetails"/> object to produce a response from.</param>
568
+ /// <returns>The created <see cref="IResult"/> for the response.</returns>
569
+ public static IResult ValidationProblem ( HttpValidationProblemDetails problemDetails )
570
+ {
525
571
return new ObjectResult ( problemDetails )
526
572
{
527
573
ContentType = "application/problem+json" ,
0 commit comments