Skip to content

Commit

Permalink
v2.2.2 (#24)
Browse files Browse the repository at this point in the history
- *Fixed:* Corrected the YAML to JSON conversion for `long` vs `string` values.
  • Loading branch information
chullybun authored Jul 30, 2024
1 parent 0103fe9 commit 72c5d0a
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

Represents the **NuGet** versions.

## v2.2.2
- *Fixed:* Corrected the YAML to JSON conversion for `long` vs `string` values.

## v2.2.1
- *Fixed:* All dependencies updated to the latest version.

Expand Down
2 changes: 1 addition & 1 deletion src/OnRamp/OnRamp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<OutputType>Exe</OutputType>
<TargetFramework>netstandard2.1</TargetFramework>
<RootNamespace>OnRamp</RootNamespace>
<Version>2.2.1</Version>
<Version>2.2.2</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Avanade</Authors>
<Company>Avanade</Company>
Expand Down
4 changes: 2 additions & 2 deletions src/OnRamp/Utility/StreamExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ bool INodeTypeResolver.Resolve(NodeEvent? nodeEvent, ref Type currentType)
{
if (nodeEvent is Scalar scalar && scalar.Style == YamlDotNet.Core.ScalarStyle.Plain)
{
if (decimal.TryParse(scalar.Value, out _))
if (decimal.TryParse(scalar.Value, out var dv))
{
if (scalar.Value.Length > 1 && scalar.Value.StartsWith('0')) // Valid JSON does not support a number that starts with a zero.
currentType = typeof(string);
else
currentType = typeof(decimal);
currentType = dv == Math.Round(dv) ? typeof(long) : typeof(decimal);

return true;
}
Expand Down
5 changes: 5 additions & 0 deletions tests/OnRamp.Test/Config/EntityConfigEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ public Task BeforePrepareAsync(IRootConfig config)
{
var ec = config as EntityConfig;
ec.Name = ec.Name.ToUpperInvariant();

var p = ec.Properties[2];
if (p.Count != 4 || p.Amount != 3.95M)
throw new System.InvalidOperationException("Count or Amount was incorrectly parsed.");

return Task.CompletedTask;
}
}
Expand Down
8 changes: 8 additions & 0 deletions tests/OnRamp.Test/Config/PropertyConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ public class PropertyConfig : ConfigBase<EntityConfig, EntityConfig>
[CodeGenProperty("Key", Title = "Indicates whether the property is nullable.")]
public bool? IsNullable { get; set; }

[JsonPropertyName("count")]
[CodeGenProperty("Key", Title = "Test out an integer.")]
public int? Count { get; set; }

[JsonPropertyName("amount")]
[CodeGenProperty("Key", Title = "Test out a decimal.")]
public decimal? Amount { get; set; }

protected override Task PrepareAsync()
{
Type = DefaultWhereNull(Type, () => "string");
Expand Down
2 changes: 1 addition & 1 deletion tests/OnRamp.Test/Data/ValidEntity.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
properties:
- { name: Name }
- { name: Age, type: int }
- { name: Salary, type: decimal, isNullable: true }
- { name: Salary, type: decimal, isNullable: true, count: 4, amount: 3.95 }
2 changes: 2 additions & 0 deletions tests/OnRamp.Test/Expected/Property.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ Property | Description
**`name`** | The property name. [Mandatory]
**`type`** | The property type. Valid options are: `string`, `int`, `decimal`.<br/>&dagger; This is a more detailed description for the property type.
`isNullable` | Indicates whether the property is nullable.
`count` | Test out an integer.
`amount` | Test out a decimal.

8 changes: 8 additions & 0 deletions tests/OnRamp.Test/Expected/Schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@
"isNullable": {
"type": "boolean",
"title": "Indicates whether the property is nullable."
},
"count": {
"type": "integer",
"title": "Test out an integer."
},
"amount": {
"type": "number",
"title": "Test out a decimal."
}
},
"required": [
Expand Down

0 comments on commit 72c5d0a

Please sign in to comment.