Skip to content

Commit 34c6c58

Browse files
authored
[csharp][generichost] Fixed string formatted as decimal (#20894)
* fixed string formatted as decimal * build tests
1 parent 8756ff7 commit 34c6c58

File tree

72 files changed

+1241
-32
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1241
-32
lines changed

modules/openapi-generator/src/main/resources/csharp/libraries/generichost/JsonConverter.mustache

+10
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,12 @@
179179
{{^isMap}}
180180
{{^isEnum}}
181181
{{^isUuid}}
182+
{{#isDecimal}}
183+
{{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}} = {{>OptionProperty}}utf8JsonReader.GetDecimal());
184+
{{/isDecimal}}
185+
{{^isDecimal}}
182186
{{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}} = {{>OptionProperty}}utf8JsonReader.GetString(){{^isNullable}}{{nrt!}}{{/isNullable}});
187+
{{/isDecimal}}
183188
{{/isUuid}}
184189
{{/isEnum}}
185190
{{/isMap}}
@@ -439,7 +444,12 @@
439444
{{^isEnum}}
440445
{{^isUuid}}
441446
{{#lambda.copyText}}
447+
{{#isDecimal}}
448+
writer.WriteString("{{baseName}}", {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}.ToString());
449+
{{/isDecimal}}
450+
{{^isDecimal}}
442451
writer.WriteString("{{baseName}}", {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}});
452+
{{/isDecimal}}
443453
{{/lambda.copyText}}
444454
{{#lambda.indent3}}
445455
{{>WriteProperty}}

modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -1673,6 +1673,7 @@ components:
16731673
- byte
16741674
- date
16751675
- password
1676+
- string_formatted_as_decimal_required
16761677
properties:
16771678
integer:
16781679
type: integer
@@ -1771,6 +1772,12 @@ components:
17711772
description: None
17721773
type: string
17731774
pattern: '^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$'
1775+
string_formatted_as_decimal:
1776+
format: decimal
1777+
type: string
1778+
string_formatted_as_decimal_required:
1779+
format: decimal
1780+
type: string
17741781
EnumClass:
17751782
type: string
17761783
default: '-efg'

samples/client/petstore/csharp/generichost/net4.7/FormModels/api/openapi.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -1665,11 +1665,18 @@ components:
16651665
pattern: "^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\\\
16661666
/([0-9]|[1-2][0-9]|3[0-2]))$"
16671667
type: string
1668+
string_formatted_as_decimal:
1669+
format: decimal
1670+
type: string
1671+
string_formatted_as_decimal_required:
1672+
format: decimal
1673+
type: string
16681674
required:
16691675
- byte
16701676
- date
16711677
- number
16721678
- password
1679+
- string_formatted_as_decimal_required
16731680
type: object
16741681
EnumClass:
16751682
default: -efg

samples/client/petstore/csharp/generichost/net4.7/FormModels/docs/models/FormatTest.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Name | Type | Description | Notes
88
**Date** | **DateTime** | |
99
**Number** | **decimal** | |
1010
**Password** | **string** | |
11+
**StringFormattedAsDecimalRequired** | **decimal** | |
1112
**Binary** | **System.IO.Stream** | | [optional]
1213
**DateTime** | **DateTime** | | [optional]
1314
**Decimal** | **decimal** | | [optional]
@@ -25,6 +26,7 @@ Name | Type | Description | Notes
2526
**PatternWithDigits** | **string** | A string that is a 10 digit number. Can have leading zeros. | [optional]
2627
**PatternWithDigitsAndDelimiter** | **string** | A string starting with 'image_' (case insensitive) and one to three digits following i.e. Image_01. | [optional]
2728
**String** | **string** | | [optional]
29+
**StringFormattedAsDecimal** | **decimal** | | [optional]
2830
**UnsignedInteger** | **uint** | | [optional]
2931
**UnsignedLong** | **ulong** | | [optional]
3032
**Uuid** | **Guid** | | [optional]

samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools.Test/Model/FormatTestTests.cs

+18
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ public void PasswordTest()
8989
// TODO unit test for the property 'Password'
9090
}
9191

92+
/// <summary>
93+
/// Test the property 'StringFormattedAsDecimalRequired'
94+
/// </summary>
95+
[Fact]
96+
public void StringFormattedAsDecimalRequiredTest()
97+
{
98+
// TODO unit test for the property 'StringFormattedAsDecimalRequired'
99+
}
100+
92101
/// <summary>
93102
/// Test the property 'Binary'
94103
/// </summary>
@@ -242,6 +251,15 @@ public void StringTest()
242251
// TODO unit test for the property 'String'
243252
}
244253

254+
/// <summary>
255+
/// Test the property 'StringFormattedAsDecimal'
256+
/// </summary>
257+
[Fact]
258+
public void StringFormattedAsDecimalTest()
259+
{
260+
// TODO unit test for the property 'StringFormattedAsDecimal'
261+
}
262+
245263
/// <summary>
246264
/// Test the property 'UnsignedInteger'
247265
/// </summary>

samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/FormatTest.cs

+49-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public partial class FormatTest : IValidatableObject
3636
/// <param name="date">date</param>
3737
/// <param name="number">number</param>
3838
/// <param name="password">password</param>
39+
/// <param name="stringFormattedAsDecimalRequired">stringFormattedAsDecimalRequired</param>
3940
/// <param name="binary">binary</param>
4041
/// <param name="dateTime">dateTime</param>
4142
/// <param name="decimal">decimal</param>
@@ -53,16 +54,18 @@ public partial class FormatTest : IValidatableObject
5354
/// <param name="patternWithDigits">A string that is a 10 digit number. Can have leading zeros.</param>
5455
/// <param name="patternWithDigitsAndDelimiter">A string starting with &#39;image_&#39; (case insensitive) and one to three digits following i.e. Image_01.</param>
5556
/// <param name="string">string</param>
57+
/// <param name="stringFormattedAsDecimal">stringFormattedAsDecimal</param>
5658
/// <param name="unsignedInteger">unsignedInteger</param>
5759
/// <param name="unsignedLong">unsignedLong</param>
5860
/// <param name="uuid">uuid</param>
5961
[JsonConstructor]
60-
public FormatTest(byte[] @byte, DateTime date, decimal number, string password, Option<System.IO.Stream> binary = default, Option<DateTime?> dateTime = default, Option<decimal?> @decimal = default, Option<double?> @double = default, Option<float?> @float = default, Option<int?> int32 = default, Option<int?> int32Range = default, Option<long?> int64 = default, Option<long?> int64Negative = default, Option<long?> int64NegativeExclusive = default, Option<long?> int64Positive = default, Option<long?> int64PositiveExclusive = default, Option<int?> integer = default, Option<string> patternWithBackslash = default, Option<string> patternWithDigits = default, Option<string> patternWithDigitsAndDelimiter = default, Option<string> @string = default, Option<uint?> unsignedInteger = default, Option<ulong?> unsignedLong = default, Option<Guid?> uuid = default)
62+
public FormatTest(byte[] @byte, DateTime date, decimal number, string password, decimal stringFormattedAsDecimalRequired, Option<System.IO.Stream> binary = default, Option<DateTime?> dateTime = default, Option<decimal?> @decimal = default, Option<double?> @double = default, Option<float?> @float = default, Option<int?> int32 = default, Option<int?> int32Range = default, Option<long?> int64 = default, Option<long?> int64Negative = default, Option<long?> int64NegativeExclusive = default, Option<long?> int64Positive = default, Option<long?> int64PositiveExclusive = default, Option<int?> integer = default, Option<string> patternWithBackslash = default, Option<string> patternWithDigits = default, Option<string> patternWithDigitsAndDelimiter = default, Option<string> @string = default, Option<decimal?> stringFormattedAsDecimal = default, Option<uint?> unsignedInteger = default, Option<ulong?> unsignedLong = default, Option<Guid?> uuid = default)
6163
{
6264
Byte = @byte;
6365
Date = date;
6466
Number = number;
6567
Password = password;
68+
StringFormattedAsDecimalRequired = stringFormattedAsDecimalRequired;
6669
BinaryOption = binary;
6770
DateTimeOption = dateTime;
6871
DecimalOption = @decimal;
@@ -80,6 +83,7 @@ public FormatTest(byte[] @byte, DateTime date, decimal number, string password,
8083
PatternWithDigitsOption = patternWithDigits;
8184
PatternWithDigitsAndDelimiterOption = patternWithDigitsAndDelimiter;
8285
StringOption = @string;
86+
StringFormattedAsDecimalOption = stringFormattedAsDecimal;
8387
UnsignedIntegerOption = unsignedInteger;
8488
UnsignedLongOption = unsignedLong;
8589
UuidOption = uuid;
@@ -113,6 +117,12 @@ public FormatTest(byte[] @byte, DateTime date, decimal number, string password,
113117
[JsonPropertyName("password")]
114118
public string Password { get; set; }
115119

120+
/// <summary>
121+
/// Gets or Sets StringFormattedAsDecimalRequired
122+
/// </summary>
123+
[JsonPropertyName("string_formatted_as_decimal_required")]
124+
public decimal StringFormattedAsDecimalRequired { get; set; }
125+
116126
/// <summary>
117127
/// Used to track the state of Binary
118128
/// </summary>
@@ -338,6 +348,19 @@ public FormatTest(byte[] @byte, DateTime date, decimal number, string password,
338348
[JsonPropertyName("string")]
339349
public string String { get { return this.StringOption; } set { this.StringOption = new Option<string>(value); } }
340350

351+
/// <summary>
352+
/// Used to track the state of StringFormattedAsDecimal
353+
/// </summary>
354+
[JsonIgnore]
355+
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
356+
public Option<decimal?> StringFormattedAsDecimalOption { get; private set; }
357+
358+
/// <summary>
359+
/// Gets or Sets StringFormattedAsDecimal
360+
/// </summary>
361+
[JsonPropertyName("string_formatted_as_decimal")]
362+
public decimal? StringFormattedAsDecimal { get { return this.StringFormattedAsDecimalOption; } set { this.StringFormattedAsDecimalOption = new Option<decimal?>(value); } }
363+
341364
/// <summary>
342365
/// Used to track the state of UnsignedInteger
343366
/// </summary>
@@ -396,6 +419,7 @@ public override string ToString()
396419
sb.Append(" Date: ").Append(Date).Append("\n");
397420
sb.Append(" Number: ").Append(Number).Append("\n");
398421
sb.Append(" Password: ").Append(Password).Append("\n");
422+
sb.Append(" StringFormattedAsDecimalRequired: ").Append(StringFormattedAsDecimalRequired).Append("\n");
399423
sb.Append(" Binary: ").Append(Binary).Append("\n");
400424
sb.Append(" DateTime: ").Append(DateTime).Append("\n");
401425
sb.Append(" Decimal: ").Append(Decimal).Append("\n");
@@ -413,6 +437,7 @@ public override string ToString()
413437
sb.Append(" PatternWithDigits: ").Append(PatternWithDigits).Append("\n");
414438
sb.Append(" PatternWithDigitsAndDelimiter: ").Append(PatternWithDigitsAndDelimiter).Append("\n");
415439
sb.Append(" String: ").Append(String).Append("\n");
440+
sb.Append(" StringFormattedAsDecimal: ").Append(StringFormattedAsDecimal).Append("\n");
416441
sb.Append(" UnsignedInteger: ").Append(UnsignedInteger).Append("\n");
417442
sb.Append(" UnsignedLong: ").Append(UnsignedLong).Append("\n");
418443
sb.Append(" Uuid: ").Append(Uuid).Append("\n");
@@ -628,6 +653,7 @@ public override FormatTest Read(ref Utf8JsonReader utf8JsonReader, Type typeToCo
628653
Option<DateTime?> date = default;
629654
Option<decimal?> number = default;
630655
Option<string> password = default;
656+
Option<decimal?> stringFormattedAsDecimalRequired = default;
631657
Option<System.IO.Stream> binary = default;
632658
Option<DateTime?> dateTime = default;
633659
Option<decimal?> varDecimal = default;
@@ -645,6 +671,7 @@ public override FormatTest Read(ref Utf8JsonReader utf8JsonReader, Type typeToCo
645671
Option<string> patternWithDigits = default;
646672
Option<string> patternWithDigitsAndDelimiter = default;
647673
Option<string> varString = default;
674+
Option<decimal?> stringFormattedAsDecimal = default;
648675
Option<uint?> unsignedInteger = default;
649676
Option<ulong?> unsignedLong = default;
650677
Option<Guid?> uuid = default;
@@ -676,6 +703,9 @@ public override FormatTest Read(ref Utf8JsonReader utf8JsonReader, Type typeToCo
676703
case "password":
677704
password = new Option<string>(utf8JsonReader.GetString());
678705
break;
706+
case "string_formatted_as_decimal_required":
707+
stringFormattedAsDecimalRequired = new Option<decimal?>(utf8JsonReader.GetDecimal());
708+
break;
679709
case "binary":
680710
binary = new Option<System.IO.Stream>(JsonSerializer.Deserialize<System.IO.Stream>(ref utf8JsonReader, jsonSerializerOptions));
681711
break;
@@ -727,6 +757,9 @@ public override FormatTest Read(ref Utf8JsonReader utf8JsonReader, Type typeToCo
727757
case "string":
728758
varString = new Option<string>(utf8JsonReader.GetString());
729759
break;
760+
case "string_formatted_as_decimal":
761+
stringFormattedAsDecimal = new Option<decimal?>(utf8JsonReader.GetDecimal());
762+
break;
730763
case "unsigned_integer":
731764
unsignedInteger = new Option<uint?>(utf8JsonReader.TokenType == JsonTokenType.Null ? (uint?)null : utf8JsonReader.GetUInt32());
732765
break;
@@ -754,6 +787,9 @@ public override FormatTest Read(ref Utf8JsonReader utf8JsonReader, Type typeToCo
754787
if (!password.IsSet)
755788
throw new ArgumentException("Property is required for class FormatTest.", nameof(password));
756789

790+
if (!stringFormattedAsDecimalRequired.IsSet)
791+
throw new ArgumentException("Property is required for class FormatTest.", nameof(stringFormattedAsDecimalRequired));
792+
757793
if (varByte.IsSet && varByte.Value == null)
758794
throw new ArgumentNullException(nameof(varByte), "Property is not nullable for class FormatTest.");
759795

@@ -766,6 +802,9 @@ public override FormatTest Read(ref Utf8JsonReader utf8JsonReader, Type typeToCo
766802
if (password.IsSet && password.Value == null)
767803
throw new ArgumentNullException(nameof(password), "Property is not nullable for class FormatTest.");
768804

805+
if (stringFormattedAsDecimalRequired.IsSet && stringFormattedAsDecimalRequired.Value == null)
806+
throw new ArgumentNullException(nameof(stringFormattedAsDecimalRequired), "Property is not nullable for class FormatTest.");
807+
769808
if (binary.IsSet && binary.Value == null)
770809
throw new ArgumentNullException(nameof(binary), "Property is not nullable for class FormatTest.");
771810

@@ -817,6 +856,9 @@ public override FormatTest Read(ref Utf8JsonReader utf8JsonReader, Type typeToCo
817856
if (varString.IsSet && varString.Value == null)
818857
throw new ArgumentNullException(nameof(varString), "Property is not nullable for class FormatTest.");
819858

859+
if (stringFormattedAsDecimal.IsSet && stringFormattedAsDecimal.Value == null)
860+
throw new ArgumentNullException(nameof(stringFormattedAsDecimal), "Property is not nullable for class FormatTest.");
861+
820862
if (unsignedInteger.IsSet && unsignedInteger.Value == null)
821863
throw new ArgumentNullException(nameof(unsignedInteger), "Property is not nullable for class FormatTest.");
822864

@@ -826,7 +868,7 @@ public override FormatTest Read(ref Utf8JsonReader utf8JsonReader, Type typeToCo
826868
if (uuid.IsSet && uuid.Value == null)
827869
throw new ArgumentNullException(nameof(uuid), "Property is not nullable for class FormatTest.");
828870

829-
return new FormatTest(varByte.Value, date.Value.Value, number.Value.Value, password.Value, binary, dateTime, varDecimal, varDouble, varFloat, int32, int32Range, int64, int64Negative, int64NegativeExclusive, int64Positive, int64PositiveExclusive, integer, patternWithBackslash, patternWithDigits, patternWithDigitsAndDelimiter, varString, unsignedInteger, unsignedLong, uuid);
871+
return new FormatTest(varByte.Value, date.Value.Value, number.Value.Value, password.Value, stringFormattedAsDecimalRequired.Value.Value, binary, dateTime, varDecimal, varDouble, varFloat, int32, int32Range, int64, int64Negative, int64NegativeExclusive, int64Positive, int64PositiveExclusive, integer, patternWithBackslash, patternWithDigits, patternWithDigitsAndDelimiter, varString, stringFormattedAsDecimal, unsignedInteger, unsignedLong, uuid);
830872
}
831873

832874
/// <summary>
@@ -882,6 +924,8 @@ public void WriteProperties(Utf8JsonWriter writer, FormatTest formatTest, JsonSe
882924

883925
writer.WriteString("password", formatTest.Password);
884926

927+
writer.WriteString("string_formatted_as_decimal_required", formatTest.StringFormattedAsDecimalRequired.ToString());
928+
885929
if (formatTest.BinaryOption.IsSet)
886930
{
887931
writer.WritePropertyName("binary");
@@ -937,6 +981,9 @@ public void WriteProperties(Utf8JsonWriter writer, FormatTest formatTest, JsonSe
937981
if (formatTest.StringOption.IsSet)
938982
writer.WriteString("string", formatTest.String);
939983

984+
if (formatTest.StringFormattedAsDecimalOption.IsSet)
985+
writer.WriteString("string_formatted_as_decimal", formatTest.StringFormattedAsDecimal.ToString());
986+
940987
if (formatTest.UnsignedIntegerOption.IsSet)
941988
writer.WriteNumber("unsigned_integer", formatTest.UnsignedIntegerOption.Value.Value);
942989

samples/client/petstore/csharp/generichost/net4.7/Petstore/api/openapi.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -1706,11 +1706,18 @@ components:
17061706
pattern: "^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\\\
17071707
/([0-9]|[1-2][0-9]|3[0-2]))$"
17081708
type: string
1709+
string_formatted_as_decimal:
1710+
format: decimal
1711+
type: string
1712+
string_formatted_as_decimal_required:
1713+
format: decimal
1714+
type: string
17091715
required:
17101716
- byte
17111717
- date
17121718
- number
17131719
- password
1720+
- string_formatted_as_decimal_required
17141721
type: object
17151722
EnumClass:
17161723
default: -efg

samples/client/petstore/csharp/generichost/net4.7/Petstore/docs/models/FormatTest.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Name | Type | Description | Notes
88
**Date** | **DateTime** | |
99
**Number** | **decimal** | |
1010
**Password** | **string** | |
11+
**StringFormattedAsDecimalRequired** | **decimal** | |
1112
**Binary** | **System.IO.Stream** | | [optional]
1213
**DateTime** | **DateTime** | | [optional]
1314
**Decimal** | **decimal** | | [optional]
@@ -25,6 +26,7 @@ Name | Type | Description | Notes
2526
**PatternWithDigits** | **string** | A string that is a 10 digit number. Can have leading zeros. | [optional]
2627
**PatternWithDigitsAndDelimiter** | **string** | A string starting with &#39;image_&#39; (case insensitive) and one to three digits following i.e. Image_01. | [optional]
2728
**String** | **string** | | [optional]
29+
**StringFormattedAsDecimal** | **decimal** | | [optional]
2830
**UnsignedInteger** | **uint** | | [optional]
2931
**UnsignedLong** | **ulong** | | [optional]
3032
**Uuid** | **Guid** | | [optional]

samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools.Test/Model/FormatTestTests.cs

+18
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ public void PasswordTest()
8989
// TODO unit test for the property 'Password'
9090
}
9191

92+
/// <summary>
93+
/// Test the property 'StringFormattedAsDecimalRequired'
94+
/// </summary>
95+
[Fact]
96+
public void StringFormattedAsDecimalRequiredTest()
97+
{
98+
// TODO unit test for the property 'StringFormattedAsDecimalRequired'
99+
}
100+
92101
/// <summary>
93102
/// Test the property 'Binary'
94103
/// </summary>
@@ -242,6 +251,15 @@ public void StringTest()
242251
// TODO unit test for the property 'String'
243252
}
244253

254+
/// <summary>
255+
/// Test the property 'StringFormattedAsDecimal'
256+
/// </summary>
257+
[Fact]
258+
public void StringFormattedAsDecimalTest()
259+
{
260+
// TODO unit test for the property 'StringFormattedAsDecimal'
261+
}
262+
245263
/// <summary>
246264
/// Test the property 'UnsignedInteger'
247265
/// </summary>

0 commit comments

Comments
 (0)