Skip to content

Commit 2f0d63a

Browse files
committed
fixed string formatted as decimal
1 parent b1f572e commit 2f0d63a

File tree

59 files changed

+1007
-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.

59 files changed

+1007
-32
lines changed

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

Lines changed: 10 additions & 0 deletions
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}}
@@ -450,7 +455,12 @@
450455
{{^isEnum}}
451456
{{^isUuid}}
452457
{{#lambda.copyText}}
458+
{{#isDecimal}}
459+
writer.WriteString("{{baseName}}", {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}.ToString());
460+
{{/isDecimal}}
461+
{{^isDecimal}}
453462
writer.WriteString("{{baseName}}", {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}});
463+
{{/isDecimal}}
454464
{{/lambda.copyText}}
455465
{{#lambda.indent3}}
456466
{{>WriteProperty}}

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

Lines changed: 7 additions & 0 deletions
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

Lines changed: 7 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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/Model/FormatTest.cs

Lines changed: 49 additions & 2 deletions
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;
@@ -679,6 +706,9 @@ public override FormatTest Read(ref Utf8JsonReader utf8JsonReader, Type typeToCo
679706
case "password":
680707
password = new Option<string>(utf8JsonReader.GetString());
681708
break;
709+
case "string_formatted_as_decimal_required":
710+
stringFormattedAsDecimalRequired = new Option<decimal?>(utf8JsonReader.GetDecimal());
711+
break;
682712
case "binary":
683713
if (utf8JsonReader.TokenType != JsonTokenType.Null)
684714
binary = new Option<System.IO.Stream>(JsonSerializer.Deserialize<System.IO.Stream>(ref utf8JsonReader, jsonSerializerOptions));
@@ -743,6 +773,9 @@ public override FormatTest Read(ref Utf8JsonReader utf8JsonReader, Type typeToCo
743773
case "string":
744774
varString = new Option<string>(utf8JsonReader.GetString());
745775
break;
776+
case "string_formatted_as_decimal":
777+
stringFormattedAsDecimal = new Option<decimal?>(utf8JsonReader.GetDecimal());
778+
break;
746779
case "unsigned_integer":
747780
if (utf8JsonReader.TokenType != JsonTokenType.Null)
748781
unsignedInteger = new Option<uint?>(utf8JsonReader.GetUInt32());
@@ -773,6 +806,9 @@ public override FormatTest Read(ref Utf8JsonReader utf8JsonReader, Type typeToCo
773806
if (!password.IsSet)
774807
throw new ArgumentException("Property is required for class FormatTest.", nameof(password));
775808

809+
if (!stringFormattedAsDecimalRequired.IsSet)
810+
throw new ArgumentException("Property is required for class FormatTest.", nameof(stringFormattedAsDecimalRequired));
811+
776812
if (varByte.IsSet && varByte.Value == null)
777813
throw new ArgumentNullException(nameof(varByte), "Property is not nullable for class FormatTest.");
778814

@@ -785,6 +821,9 @@ public override FormatTest Read(ref Utf8JsonReader utf8JsonReader, Type typeToCo
785821
if (password.IsSet && password.Value == null)
786822
throw new ArgumentNullException(nameof(password), "Property is not nullable for class FormatTest.");
787823

824+
if (stringFormattedAsDecimalRequired.IsSet && stringFormattedAsDecimalRequired.Value == null)
825+
throw new ArgumentNullException(nameof(stringFormattedAsDecimalRequired), "Property is not nullable for class FormatTest.");
826+
788827
if (binary.IsSet && binary.Value == null)
789828
throw new ArgumentNullException(nameof(binary), "Property is not nullable for class FormatTest.");
790829

@@ -836,6 +875,9 @@ public override FormatTest Read(ref Utf8JsonReader utf8JsonReader, Type typeToCo
836875
if (varString.IsSet && varString.Value == null)
837876
throw new ArgumentNullException(nameof(varString), "Property is not nullable for class FormatTest.");
838877

878+
if (stringFormattedAsDecimal.IsSet && stringFormattedAsDecimal.Value == null)
879+
throw new ArgumentNullException(nameof(stringFormattedAsDecimal), "Property is not nullable for class FormatTest.");
880+
839881
if (unsignedInteger.IsSet && unsignedInteger.Value == null)
840882
throw new ArgumentNullException(nameof(unsignedInteger), "Property is not nullable for class FormatTest.");
841883

@@ -845,7 +887,7 @@ public override FormatTest Read(ref Utf8JsonReader utf8JsonReader, Type typeToCo
845887
if (uuid.IsSet && uuid.Value == null)
846888
throw new ArgumentNullException(nameof(uuid), "Property is not nullable for class FormatTest.");
847889

848-
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);
890+
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);
849891
}
850892

851893
/// <summary>
@@ -901,6 +943,8 @@ public void WriteProperties(Utf8JsonWriter writer, FormatTest formatTest, JsonSe
901943

902944
writer.WriteString("password", formatTest.Password);
903945

946+
writer.WriteString("string_formatted_as_decimal_required", formatTest.StringFormattedAsDecimalRequired.ToString());
947+
904948
if (formatTest.BinaryOption.IsSet)
905949
{
906950
writer.WritePropertyName("binary");
@@ -956,6 +1000,9 @@ public void WriteProperties(Utf8JsonWriter writer, FormatTest formatTest, JsonSe
9561000
if (formatTest.StringOption.IsSet)
9571001
writer.WriteString("string", formatTest.String);
9581002

1003+
if (formatTest.StringFormattedAsDecimalOption.IsSet)
1004+
writer.WriteString("string_formatted_as_decimal", formatTest.StringFormattedAsDecimal.ToString());
1005+
9591006
if (formatTest.UnsignedIntegerOption.IsSet)
9601007
writer.WriteNumber("unsigned_integer", formatTest.UnsignedIntegerOption.Value.Value);
9611008

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

Lines changed: 7 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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]

0 commit comments

Comments
 (0)