< Summary - Kestrun — Combined Coverage

Information
Class: OpenApiInt64
Assembly: Kestrun.Annotations
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun.Annotations/OpenApi/JsonSchemaType/OpenApiScalars.cs
Tag: Kestrun/Kestrun@ca54e35c77799b76774b3805b6f075cdbc0c5fbe
Line coverage
75%
Covered lines: 3
Uncovered lines: 1
Coverable lines: 4
Total lines: 464
Line coverage: 75%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 01/02/2026 - 21:56:10 Line coverage: 75% (3/4) Total lines: 464 Tag: Kestrun/Kestrun@f60326065ebb24cf70b241e459b37baf142e6ed6

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
.ctor()100%210%
op_Implicit(...)100%11100%
op_Implicit(...)100%11100%

File(s)

/home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun.Annotations/OpenApi/JsonSchemaType/OpenApiScalars.cs

#LineLine coverage
 1// ——— Core ———
 2
 3using System.Net;
 4using System.Net.Sockets;
 5using System.Xml;
 6
 7public interface IOpenApiScalar
 8{
 9    object? RawValue { get; }
 10}
 11
 12/// <summary>
 13/// Generic strongly-typed OpenAPI wrapper that is PowerShell-friendly.
 14/// </summary>
 15public abstract class OpenApiScalar<T>(T value) : IOpenApiScalar
 16{
 17    public T Value { get; } = value;
 18
 19    public object? RawValue => Value;
 20
 21    public override string ToString() => Value?.ToString() ?? string.Empty;
 22
 23    // Note: operators are per closed generic type (OpenApiValue<string>, OpenApiValue<int>, etc.)
 24    // Derived types will typically redeclare operators for best ergonomics if needed.
 25}
 26
 27// ——— String & friends ———
 28
 29/// <summary>OpenAPI string primitive type.</summary>
 30/// <param name="value">The string value.</param>
 31[OpenApiSchemaComponent(Type = OaSchemaType.String)]
 32public class OpenApiString(string value) : OpenApiScalar<string>(value)
 33{
 34    public OpenApiString() : this(string.Empty) { }
 35
 36    public static implicit operator string(OpenApiString s)
 37    {
 38        return s.Value;
 39    }
 40
 41    public static implicit operator OpenApiString(string s)
 42    {
 43        return new(s);
 44    }
 45}
 46
 47/// <summary>
 48/// OpenAPI string/uuid format.
 49/// </summary>
 50/// <param name="value">The UUID string value.</param>
 51[OpenApiSchemaComponent(Type = OaSchemaType.String, Format = "uuid")]
 52public class OpenApiUuid(string value) : OpenApiString(value)
 53{
 54    public OpenApiUuid() : this(string.Empty) { }
 55
 56    public static implicit operator OpenApiUuid(string s)
 57    {
 58        return new(s);
 59    }
 60}
 61
 62/// <summary>
 63/// OpenAPI string/date format.
 64/// </summary>
 65/// <param name="value">The date string value.</param>
 66[OpenApiSchemaComponent(Type = OaSchemaType.String, Format = "date")]
 67public class OpenApiDate(string value) : OpenApiString(value)
 68{
 69    public OpenApiDate() : this(string.Empty) { }
 70
 71    public static implicit operator OpenApiDate(string s)
 72    {
 73        return new(s);
 74    }
 75}
 76
 77/// <summary>
 78/// OpenAPI string/date-time format.
 79/// </summary>
 80/// <param name="value">The date-time string value.</param>
 81[OpenApiSchemaComponent(Type = OaSchemaType.String, Format = "date-time")]
 82public class OpenApiDateTime(string value) : OpenApiString(value)
 83{
 84    public OpenApiDateTime() : this(string.Empty) { }
 85
 86    public static implicit operator OpenApiDateTime(string s)
 87    {
 88        return new(s);
 89    }
 90}
 91
 92/// <summary>
 93/// OpenAPI string/email format.
 94/// </summary>
 95/// <param name="value">The email string value.</param>
 96[OpenApiSchemaComponent(Type = OaSchemaType.String, Format = "email")]
 97public class OpenApiEmail(string value) : OpenApiString(value)
 98{
 99    public OpenApiEmail() : this(string.Empty) { }
 100
 101    public static implicit operator OpenApiEmail(string s)
 102    {
 103        return new(s);
 104    }
 105}
 106
 107/// <summary>
 108/// OpenAPI string/binary format.
 109/// </summary>
 110/// <param name="value">The binary byte array value.</param>
 111[OpenApiSchemaComponent(Type = OaSchemaType.String, Format = "binary")]
 112public class OpenApiBinary(byte[] value) : OpenApiScalar<byte[]>(value)
 113{
 114    public OpenApiBinary() : this([]) { }
 115
 116    public static implicit operator byte[](OpenApiBinary b)
 117    {
 118        return b.Value;
 119    }
 120
 121    public static implicit operator OpenApiBinary(byte[] b)
 122    {
 123        return new(b);
 124    }
 125
 126    public override string ToString() => $"byte[{Value.Length}]";
 127}
 128
 129/// <summary>
 130/// OpenAPI string/hostname format.
 131/// </summary>
 132/// <param name="value">The hostname string value.</param>
 133[OpenApiSchemaComponent(Type = OaSchemaType.String, Format = "hostname")]
 134public class OpenApiHostname(string value) : OpenApiString(value)
 135{
 136    public OpenApiHostname() : this(string.Empty) { }
 137
 138    public static implicit operator OpenApiHostname(string s)
 139    {
 140        return new(s);
 141    }
 142}
 143
 144/// <summary>
 145/// OpenAPI string/ipv4 format.
 146/// </summary>
 147/// <param name="value">The IPv4 string value.</param>
 148[OpenApiSchemaComponent(Type = OaSchemaType.String, Format = "ipv4")]
 149public class OpenApiIpv4(string value) : OpenApiString(value)
 150{
 151    public OpenApiIpv4() : this(string.Empty) { }
 152
 153    public OpenApiIpv4(IPAddress ip) : this(ForceIpv4(ip)) { }
 154
 155    public static implicit operator OpenApiIpv4(string s)
 156    {
 157        return new(s);
 158    }
 159
 160    private static string ForceIpv4(IPAddress ip) =>
 161        ip.AddressFamily != AddressFamily.InterNetwork ? throw new ArgumentException("IP address must be IPv4") : ip.ToS
 162}
 163
 164/// <summary>
 165/// OpenAPI string/ipv6 format.
 166/// </summary>
 167/// <param name="value">The IPv6 string value.</param>
 168[OpenApiSchemaComponent(Type = OaSchemaType.String, Format = "ipv6")]
 169public class OpenApiIpv6(string value) : OpenApiString(value)
 170{
 171    public OpenApiIpv6(IPAddress ip) : this(ForceIpv6(ip)) { }
 172
 173    public OpenApiIpv6() : this(string.Empty) { }
 174
 175    public static implicit operator OpenApiIpv6(string s)
 176    {
 177        return new(s);
 178    }
 179
 180    private static string ForceIpv6(IPAddress ip)
 181    {
 182        if (ip.AddressFamily != AddressFamily.InterNetworkV6)
 183        {
 184            throw new ArgumentException("IP address must be IPv6");
 185        }
 186
 187        // Reject IPv4-mapped IPv6 addresses (optional but recommended)
 188        return ip.IsIPv4MappedToIPv6
 189            ? throw new ArgumentException("IPv4-mapped addresses are not allowed. Provide a real IPv6 address.")
 190            : ip.ToString();
 191    }
 192}
 193
 194/// <summary>
 195/// OpenAPI string/uri format.
 196/// </summary>
 197/// <param name="value">The URI string value.</param>
 198[OpenApiSchemaComponent(Type = OaSchemaType.String, Format = "uri")]
 199public class OpenApiUri(string value) : OpenApiString(value)
 200{
 201    public OpenApiUri(Uri uri) : this(uri.ToString()) { }
 202    public OpenApiUri() : this(string.Empty) { }
 203
 204    public static implicit operator OpenApiUri(string s)
 205    {
 206        return new(s);
 207    }
 208}
 209
 210/// <summary>
 211/// OpenAPI string/url format.
 212/// </summary>
 213/// <param name="value">The URL string value.</param>
 214[OpenApiSchemaComponent(Type = OaSchemaType.String, Format = "url")]
 215public class OpenApiUrl(string value) : OpenApiString(value)
 216{
 217    public OpenApiUrl(Uri url) : this(url.ToString()) { }
 218    public OpenApiUrl() : this(string.Empty) { }
 219
 220    public static implicit operator OpenApiUrl(string s)
 221    {
 222        return new(s);
 223    }
 224}
 225
 226/// <summary>
 227/// OpenAPI string/byte (base64). Represented as bytes for convenience.
 228/// </summary>
 229/// <param name="value">The byte array value.</param>
 230[OpenApiSchemaComponent(Type = OaSchemaType.String, Format = "byte")]
 231public class OpenApiByte(byte[] value) : OpenApiScalar<byte[]>(value)
 232{
 233    public OpenApiByte() : this([]) { }
 234
 235    public static implicit operator byte[](OpenApiByte b)
 236    {
 237        return b.Value;
 238    }
 239
 240    public static implicit operator OpenApiByte(byte[] b)
 241    {
 242        return new(b);
 243    }
 244    public override string ToString() => $"base64(byte[{Value.Length}])";
 245}
 246
 247/// <summary>
 248/// OpenAPI string/password format.
 249/// </summary>
 250/// <param name="value">The password string value.</param>
 251[OpenApiSchemaComponent(Type = OaSchemaType.String, Format = "password")]
 252public class OpenApiPassword(string value) : OpenApiString(value)
 253{
 254    public OpenApiPassword() : this(string.Empty) { }
 255
 256    public static implicit operator OpenApiPassword(string s)
 257    {
 258        return new(s);
 259    }
 260}
 261
 262/// <summary>
 263/// OpenAPI string/regex format.
 264/// </summary>
 265/// <param name="value">The regex string value.</param>
 266[OpenApiSchemaComponent(Type = OaSchemaType.String, Format = "regex")]
 267public class OpenApiRegex(string value) : OpenApiString(value)
 268{
 269    public OpenApiRegex() : this(string.Empty) { }
 270
 271    public static implicit operator OpenApiRegex(string s)
 272    {
 273        return new(s);
 274    }
 275}
 276
 277/// <summary>
 278/// OpenAPI string/json format.
 279/// </summary>
 280/// <param name="value">The JSON string value.</param>
 281[OpenApiSchemaComponent(Type = OaSchemaType.String, Format = "json")]
 282public class OpenApiJson(string value) : OpenApiString(value)
 283{
 284    public OpenApiJson() : this(string.Empty) { }
 285
 286    public static implicit operator OpenApiJson(string s)
 287    {
 288        return new(s);
 289    }
 290}
 291
 292/// <summary>
 293/// OpenAPI string/xml format.
 294/// </summary>
 295/// <param name="value">The XML string value.</param>
 296[OpenApiSchemaComponent(Type = OaSchemaType.String, Format = "xml")]
 297public class OpenApiXml(string value) : OpenApiString(value)
 298{
 299    public OpenApiXml(XmlElement xml) : this(xml.OuterXml) { }
 300    public OpenApiXml() : this(string.Empty) { }
 301
 302    public static implicit operator OpenApiXml(string s)
 303    {
 304        return new(s);
 305    }
 306}
 307
 308/// <summary>
 309/// OpenAPI string/yaml format.
 310/// </summary>
 311/// <param name="value">The YAML string value.</param>
 312[OpenApiSchemaComponent(Type = OaSchemaType.String, Format = "yaml")]
 313public class OpenApiYaml(string value) : OpenApiString(value)
 314{
 315    public OpenApiYaml() : this(string.Empty) { }
 316
 317    public static implicit operator OpenApiYaml(string s)
 318    {
 319        return new(s);
 320    }
 321}
 322
 323#region  ——— Numeric & Boolean ———
 324
 325/// <summary>
 326/// OpenAPI integer primitive type.
 327/// </summary>
 328/// <param name="value">The integer value.</param>
 329[OpenApiSchemaComponent(Type = OaSchemaType.Integer)]
 330public class OpenApiInteger(long value) : OpenApiScalar<long>(value)
 331{
 332    public OpenApiInteger() : this(0) { }
 333
 334    public static implicit operator long(OpenApiInteger x)
 335    {
 336        return x.Value;
 337    }
 338
 339    public static implicit operator OpenApiInteger(long x)
 340    {
 341        return new(x);
 342    }
 343}
 344
 345/// <summary>
 346/// OpenAPI integer/int32 format.
 347/// </summary>
 348/// <param name="value">The int32 value.</param>
 349[OpenApiSchemaComponent(Type = OaSchemaType.Integer, Format = "int32")]
 350public class OpenApiInt32(int value) : OpenApiScalar<int>(value)
 351{
 352    public OpenApiInt32() : this(0) { }
 353
 354    public static implicit operator int(OpenApiInt32 x)
 355    {
 356        return x.Value;
 357    }
 358
 359    public static implicit operator OpenApiInt32(int x)
 360    {
 361        return new(x);
 362    }
 363}
 364
 365/// <summary>
 366/// OpenAPI integer/int64 format.
 367/// </summary>
 368/// <param name="value">The int64 value.</param>
 369[OpenApiSchemaComponent(Type = OaSchemaType.Integer, Format = "int64")]
 1370public class OpenApiInt64(long value) : OpenApiScalar<long>(value)
 371{
 0372    public OpenApiInt64() : this(0) { }
 373
 374    public static implicit operator long(OpenApiInt64 x)
 375    {
 1376        return x.Value;
 377    }
 378
 379    public static implicit operator OpenApiInt64(long x)
 380    {
 1381        return new(x);
 382    }
 383}
 384
 385/// <summary>
 386/// OpenAPI number primitive type.
 387/// </summary>
 388/// <param name="value">The number value.</param>
 389[OpenApiSchemaComponent(Type = OaSchemaType.Number)]
 390public class OpenApiNumber(double value) : OpenApiScalar<double>(value)
 391{
 392    public OpenApiNumber() : this(0d) { }
 393
 394    public static implicit operator double(OpenApiNumber x)
 395    {
 396        return x.Value;
 397    }
 398
 399    public static implicit operator OpenApiNumber(double x)
 400    {
 401        return new(x);
 402    }
 403}
 404
 405/// <summary>
 406/// OpenAPI number/float format.
 407/// </summary>
 408/// <param name="value">The float value.</param>
 409[OpenApiSchemaComponent(Type = OaSchemaType.Number, Format = "float")]
 410public class OpenApiFloat(float value) : OpenApiScalar<float>(value)
 411{
 412    public OpenApiFloat() : this(0f) { }
 413
 414    public static implicit operator float(OpenApiFloat x)
 415    {
 416        return x.Value;
 417    }
 418
 419    public static implicit operator OpenApiFloat(float x)
 420    {
 421        return new(x);
 422    }
 423}
 424
 425/// <summary>
 426/// OpenAPI number/double format.
 427/// </summary>
 428/// <param name="value">The double value.</param>
 429[OpenApiSchemaComponent(Type = OaSchemaType.Number, Format = "double")]
 430public class OpenApiDouble(double value) : OpenApiScalar<double>(value)
 431{
 432    public OpenApiDouble() : this(0d) { }
 433
 434    public static implicit operator double(OpenApiDouble x)
 435    {
 436        return x.Value;
 437    }
 438
 439    public static implicit operator OpenApiDouble(double x)
 440    {
 441        return new(x);
 442    }
 443}
 444
 445/// <summary>
 446/// OpenAPI boolean primitive type.
 447/// </summary>
 448/// <param name="value">The boolean value.</param>
 449[OpenApiSchemaComponent(Type = OaSchemaType.Boolean)]
 450public class OpenApiBoolean(bool value) : OpenApiScalar<bool>(value)
 451{
 452    public OpenApiBoolean() : this(false) { }
 453
 454    public static implicit operator bool(OpenApiBoolean x)
 455    {
 456        return x.Value;
 457    }
 458
 459    public static implicit operator OpenApiBoolean(bool x)
 460    {
 461        return new(x);
 462    }
 463}
 464#endregion