using System;
using System.ComponentModel;
namespace PepperDash.Essentials.Core.Web.Attributes
{
///
/// Base class for HTTP method attributes
///
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public abstract class HttpMethodAttribute : Attribute
{
public string Method { get; }
protected HttpMethodAttribute(string method)
{
Method = method;
}
}
///
/// Indicates that a request handler supports HTTP GET operations
///
public class HttpGetAttribute : HttpMethodAttribute
{
public HttpGetAttribute() : base("GET") { }
}
///
/// Indicates that a request handler supports HTTP POST operations
///
public class HttpPostAttribute : HttpMethodAttribute
{
public HttpPostAttribute() : base("POST") { }
}
///
/// Indicates that a request handler supports HTTP PUT operations
///
public class HttpPutAttribute : HttpMethodAttribute
{
public HttpPutAttribute() : base("PUT") { }
}
///
/// Indicates that a request handler supports HTTP DELETE operations
///
public class HttpDeleteAttribute : HttpMethodAttribute
{
public HttpDeleteAttribute() : base("DELETE") { }
}
///
/// Provides OpenAPI operation metadata for a request handler
///
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public class OpenApiOperationAttribute : Attribute
{
///
/// A brief summary of what the operation does
///
public string Summary { get; set; }
///
/// A verbose explanation of the operation behavior
///
public string Description { get; set; }
///
/// Unique string used to identify the operation
///
public string OperationId { get; set; }
///
/// A list of tags for API documentation control
///
public string[] Tags { get; set; }
public OpenApiOperationAttribute()
{
}
}
///
/// Describes a response from an API operation
///
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public class OpenApiResponseAttribute : Attribute
{
///
/// The HTTP status code
///
public int StatusCode { get; }
///
/// A short description of the response
///
public string Description { get; set; }
///
/// The content type of the response
///
public string ContentType { get; set; } = "application/json";
///
/// The type that represents the response schema
///
public Type Type { get; set; }
public OpenApiResponseAttribute(int statusCode)
{
StatusCode = statusCode;
}
}
///
/// Indicates that an operation requires a request body
///
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public class OpenApiRequestBodyAttribute : Attribute
{
///
/// Determines if the request body is required
///
public bool Required { get; set; } = true;
///
/// The content type of the request body
///
public string ContentType { get; set; } = "application/json";
///
/// The type that represents the request body schema
///
public Type Type { get; set; }
///
/// Description of the request body
///
public string Description { get; set; }
public OpenApiRequestBodyAttribute()
{
}
}
///
/// Describes a parameter for the operation
///
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public class OpenApiParameterAttribute : Attribute
{
///
/// The name of the parameter
///
public string Name { get; }
///
/// The location of the parameter
///
public ParameterLocation In { get; set; } = ParameterLocation.Path;
///
/// Determines whether this parameter is mandatory
///
public bool Required { get; set; } = true;
///
/// A brief description of the parameter
///
public string Description { get; set; }
///
/// The type of the parameter
///
public Type Type { get; set; } = typeof(string);
public OpenApiParameterAttribute(string name)
{
Name = name;
}
}
///
/// The location of the parameter
///
public enum ParameterLocation
{
Query,
Header,
Path,
Cookie
}
}