@@ -471,23 +471,46 @@ public static IResult UnprocessableEntity(object? error = null)
471471 /// <param name="instance">The value for <see cref="ProblemDetails.Instance" />.</param>
472472 /// <param name="title">The value for <see cref="ProblemDetails.Title" />.</param>
473473 /// <param name="type">The value for <see cref="ProblemDetails.Type" />.</param>
474+ /// <param name="extensions">The value for <see cref="ProblemDetails.Extensions" />.</param>
474475 /// <returns>The created <see cref="IResult"/> for the response.</returns>
475476 public static IResult Problem (
476477 string ? detail = null ,
477478 string ? instance = null ,
478479 int ? statusCode = null ,
479480 string ? title = null ,
480- string ? type = null )
481+ string ? type = null ,
482+ IDictionary < string , object ? > ? extensions = null )
481483 {
482484 var problemDetails = new ProblemDetails
483485 {
484486 Detail = detail ,
485487 Instance = instance ,
486488 Status = statusCode ,
487489 Title = title ,
488- Type = type
490+ Type = type ,
489491 } ;
490492
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+ {
491514 return new ObjectResult ( problemDetails )
492515 {
493516 ContentType = "application/problem+json" ,
@@ -502,25 +525,36 @@ public static IResult Problem(
502525 /// <param name="detail">The value for <see cref="ProblemDetails.Detail" />.</param>
503526 /// <param name="instance">The value for <see cref="ProblemDetails.Instance" />.</param>
504527 /// <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>
506529 /// <param name="type">The value for <see cref="ProblemDetails.Type" />.</param>
530+ /// <param name="extensions">The value for <see cref="ProblemDetails.Extensions" />.</param>
507531 /// <returns>The created <see cref="IResult"/> for the response.</returns>
508532 public static IResult ValidationProblem (
509533 IDictionary < string , string [ ] > errors ,
510534 string ? detail = null ,
511535 string ? instance = null ,
512536 int ? statusCode = null ,
513537 string ? title = null ,
514- string ? type = null )
538+ string ? type = null ,
539+ IDictionary < string , object ? > ? extensions = null )
515540 {
516541 var problemDetails = new HttpValidationProblemDetails ( errors )
517542 {
518543 Detail = detail ,
519544 Instance = instance ,
520- Title = title ,
521545 Type = type ,
522546 Status = statusCode ,
523547 } ;
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+ }
524558
525559 return new ObjectResult ( problemDetails )
526560 {
0 commit comments