1+ using System ;
2+ using System . Collections . Generic ;
3+
4+ namespace Simplify . Web . Swagger ;
5+
6+ /// <summary>
7+ /// A filter that specifies the type of the value and status code returned by the controller.
8+ /// </summary>
9+ [ AttributeUsage ( AttributeTargets . Class , AllowMultiple = true , Inherited = true ) ]
10+ public class ProducesResponseAttribute : Attribute
11+ {
12+ /// <summary>
13+ /// Initializes an instance of <see cref="ProducesResponseAttribute"/>.
14+ /// </summary>
15+ /// <param name="statusCode">The HTTP response status code.</param>
16+ /// <param name="contentType">The content type associated with the response.</param>
17+ /// <param name="additionalContentTypes">Additional content types supported by the response.</param>
18+ public ProducesResponseAttribute ( int statusCode , string ? contentType , params string [ ] additionalContentTypes ) :
19+ this ( statusCode , null , contentType , additionalContentTypes )
20+ {
21+ }
22+
23+ /// <summary>
24+ /// Initializes an instance of <see cref="ProducesResponseAttribute"/>.
25+ /// </summary>
26+ /// <param name="statusCode">The HTTP response status code.</param>
27+ /// <param name="type">The <see cref="Type"/> of object that is going to be written in the response.</param>
28+ /// <param name="contentType">The content type associated with the response.</param>
29+ /// <param name="additionalContentTypes">Additional content types supported by the response.</param>
30+ public ProducesResponseAttribute ( int statusCode , Type ? type = null , string ? contentType = null , params string [ ] additionalContentTypes )
31+ {
32+ StatusCode = statusCode ;
33+ Type = type ;
34+
35+ if ( ! string . IsNullOrEmpty ( contentType ) )
36+ ContentTypes . Add ( contentType ! ) ;
37+
38+ for ( var i = 0 ; i < additionalContentTypes . Length ; i ++ )
39+ {
40+ if ( string . IsNullOrEmpty ( additionalContentTypes [ i ] ) )
41+ continue ;
42+
43+ ContentTypes . Add ( additionalContentTypes [ i ] ) ;
44+ }
45+ }
46+
47+ /// <summary>
48+ /// Gets the HTTP status code of the response.
49+ /// </summary>
50+ public int StatusCode { get ; }
51+
52+ /// <summary>
53+ /// Gets the type of the value returned by a controller.
54+ /// </summary>
55+ public Type ? Type { get ; }
56+
57+ /// <summary>
58+ /// Gets the HTTP content types of the response
59+ /// </summary>
60+ public IList < string > ContentTypes { get ; } = new List < string > ( ) ;
61+ }
0 commit comments