Skip to content

Commit

Permalink
Add support for ulong, closes #1437
Browse files Browse the repository at this point in the history
  • Loading branch information
Rico Suter committed Sep 26, 2023
1 parent c6c0340 commit 138004f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/NJsonSchema.CodeGeneration.CSharp/CSharpTypeResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,16 @@ private string ResolveInteger(JsonSchema schema, bool isNullable, string typeNam
return isNullable ? "long?" : "long";
}

if (schema.Format == JsonFormatStrings.Long || schema.Format == "long")
{
return isNullable ? "long?" : "long";
}

if (schema.Format == JsonFormatStrings.ULong || schema.Format == "ulong")
{
return isNullable ? "ulong?" : "ulong";
}

if (schema.Minimum.HasValue || schema.Maximum.HasValue)
{
if (string.IsNullOrEmpty(schema.Format) && schema.Type == JsonObjectType.Integer)
Expand Down
8 changes: 6 additions & 2 deletions src/NJsonSchema/Generation/ReflectionServiceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,16 @@ protected virtual JsonTypeDescription GetDescription(ContextualType contextualTy
return JsonTypeDescription.Create(contextualType, JsonObjectType.Integer, false, JsonFormatStrings.Integer);
}

if (originalType == typeof(long) ||
originalType == typeof(ulong))
if (originalType == typeof(long))
{
return JsonTypeDescription.Create(contextualType, JsonObjectType.Integer, false, JsonFormatStrings.Long);
}

if (originalType == typeof(ulong))
{
return JsonTypeDescription.Create(contextualType, JsonObjectType.Integer, false, JsonFormatStrings.ULong);
}

if (originalType == typeof(double))
{
return JsonTypeDescription.Create(contextualType, JsonObjectType.Number, false, JsonFormatStrings.Double);
Expand Down
3 changes: 3 additions & 0 deletions src/NJsonSchema/JsonFormatStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public static class JsonFormatStrings
/// <summary>Format for a long integer. </summary>
public const string Long = "int64";

/// <summary>Format for a unsigned long integer. </summary>
public const string ULong = "uint64";

/// <summary>Format for a double number. </summary>
public const string Double = "double";

Expand Down

0 comments on commit 138004f

Please sign in to comment.