@@ -109,6 +109,27 @@ public static RouteHandlerBuilder ProducesProblem(this RouteHandlerBuilder build
109
109
return Produces ( builder , statusCode , typeof ( ProblemDetails ) , contentType ) ;
110
110
}
111
111
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="IEndpointConventionBuilder"/> that can be used to further customize the endpoint.</returns>
120
+ #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters
121
+ public static TBuilder ProducesProblem < TBuilder > ( this TBuilder builder , int statusCode , string ? contentType = null )
122
+ #pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters
123
+ where TBuilder : IEndpointConventionBuilder
124
+ {
125
+ if ( string . IsNullOrEmpty ( contentType ) )
126
+ {
127
+ contentType = "application/problem+json" ;
128
+ }
129
+
130
+ return builder . WithMetadata ( new ProducesResponseTypeMetadata ( statusCode , typeof ( ProblemDetails ) , [ contentType ] ) ) ;
131
+ }
132
+
112
133
/// <summary>
113
134
/// Adds an <see cref="IProducesResponseTypeMetadata"/> with a <see cref="HttpValidationProblemDetails"/> type
114
135
/// to <see cref="EndpointBuilder.Metadata"/> for all endpoints produced by <paramref name="builder"/>.
@@ -130,6 +151,30 @@ public static RouteHandlerBuilder ProducesValidationProblem(
130
151
return Produces ( builder , statusCode , typeof ( HttpValidationProblemDetails ) , contentType ) ;
131
152
}
132
153
154
+ /// <summary>
155
+ /// Adds an <see cref="IProducesResponseTypeMetadata"/> with a <see cref="HttpValidationProblemDetails"/> type
156
+ /// to <see cref="EndpointBuilder.Metadata"/> for all endpoints produced by <paramref name="builder"/>.
157
+ /// </summary>
158
+ /// <param name="builder">The <see cref="IEndpointConventionBuilder"/>.</param>
159
+ /// <param name="statusCode">The response status code. Defaults to <see cref="StatusCodes.Status400BadRequest"/>.</param>
160
+ /// <param name="contentType">The response content type. Defaults to "application/problem+json".</param>
161
+ /// <returns>A <see cref="IEndpointConventionBuilder"/> that can be used to further customize the endpoint.</returns>
162
+ #pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters
163
+ public static TBuilder ProducesValidationProblem < TBuilder > (
164
+ #pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters
165
+ this TBuilder builder ,
166
+ int statusCode = StatusCodes . Status400BadRequest ,
167
+ string ? contentType = null )
168
+ where TBuilder : IEndpointConventionBuilder
169
+ {
170
+ if ( string . IsNullOrEmpty ( contentType ) )
171
+ {
172
+ contentType = "application/problem+json" ;
173
+ }
174
+
175
+ return builder . WithMetadata ( new ProducesResponseTypeMetadata ( statusCode , typeof ( HttpValidationProblemDetails ) , [ contentType ] ) ) ;
176
+ }
177
+
133
178
/// <summary>
134
179
/// Adds the <see cref="ITagsMetadata"/> to <see cref="EndpointBuilder.Metadata"/> for all endpoints
135
180
/// produced by <paramref name="builder"/>.
0 commit comments