Skip to content

Commit

Permalink
SDK - Add support for decimal (#1392)
Browse files Browse the repository at this point in the history
  • Loading branch information
dolauli authored Oct 18, 2024
1 parent 8ab5a43 commit e2130bd
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
6 changes: 4 additions & 2 deletions powershell/sdk/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@ export class Helper {

public GetCsharpType(schema: Schema): string {
let type = <string>schema.type;
if (schema.type === SchemaType.Integer) {
if (schema.type === SchemaType.Integer || schema.type === SchemaType.Number) {
type = type + (<NumberSchema>schema).precision;
}
const offset = this.useDateTimeOffset ? 'Offset' : '';
const typeMap = new Map<string, string>([
['integer', 'int'],
['integer32', 'int'],
['integer64', 'long'],
['number', 'double'],
['number32', 'double'],
['number64', 'double'],
['number128', 'decimal'],
['boolean', 'bool'],
['string', 'string'],
['unixtime', 'System.DateTime'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,16 @@ public Operation()
/// <param name="typeByteArray">This is byte array</param>
/// <param name="typeBoolean">This is boolean</param>
/// <param name="typeNumber">This is number</param>
/// <param name="typeNumber32">This is number</param>
/// <param name="typeNumber64">This is number</param>
/// <param name="typeNumber128">This is number</param>
/// <param name="typeConstant">This is constant. Possible values
/// include: 'const'</param>
/// <param name="typeChoice">This is choice. Possible values include:
/// 'choice1', 'choice2'</param>
/// <param name="typeSealedChoice">This is sealed choice. Possible
/// values include: 'sealedchoice1', 'sealedchoice2'</param>
public Operation(string typeString, int typeInteger, System.Collections.Generic.IList<string> typeArray, object typeAny = default(object), System.Collections.Generic.IDictionary<string, string> typeDictionary = default(System.Collections.Generic.IDictionary<string, string>), OperationTypeObject typeObject = default(OperationTypeObject), System.DateTime? typeTime = default(System.DateTime?), string typeCredential = default(string), byte[] typeBinary = default(byte[]), System.TimeSpan? typeDuration = default(System.TimeSpan?), string typeUri = default(string), System.Guid? typeUuid = default(System.Guid?), System.DateTime? typeDateTime = default(System.DateTime?), System.DateTime? typeDate = default(System.DateTime?), byte[] typeByteArray = default(byte[]), bool? typeBoolean = default(bool?), double? typeNumber = default(double?), string typeConstant = default(string), string typeChoice = default(string), string typeSealedChoice = default(string))
public Operation(string typeString, int typeInteger, System.Collections.Generic.IList<string> typeArray, object typeAny = default(object), System.Collections.Generic.IDictionary<string, string> typeDictionary = default(System.Collections.Generic.IDictionary<string, string>), OperationTypeObject typeObject = default(OperationTypeObject), System.DateTime? typeTime = default(System.DateTime?), string typeCredential = default(string), byte[] typeBinary = default(byte[]), System.TimeSpan? typeDuration = default(System.TimeSpan?), string typeUri = default(string), System.Guid? typeUuid = default(System.Guid?), System.DateTime? typeDateTime = default(System.DateTime?), System.DateTime? typeDate = default(System.DateTime?), byte[] typeByteArray = default(byte[]), bool? typeBoolean = default(bool?), double? typeNumber = default(double?), double? typeNumber32 = default(double?), double? typeNumber64 = default(double?), decimal? typeNumber128 = default(decimal?), string typeConstant = default(string), string typeChoice = default(string), string typeSealedChoice = default(string))
{
this.TypeAny = typeAny;
this.TypeDictionary = typeDictionary;
Expand All @@ -69,6 +72,9 @@ public Operation()
this.TypeBoolean = typeBoolean;
this.TypeInteger = typeInteger;
this.TypeNumber = typeNumber;
this.TypeNumber32 = typeNumber32;
this.TypeNumber64 = typeNumber64;
this.TypeNumber128 = typeNumber128;
this.TypeConstant = typeConstant;
this.TypeChoice = typeChoice;
this.TypeSealedChoice = typeSealedChoice;
Expand Down Expand Up @@ -179,6 +185,24 @@ public Operation()
[Newtonsoft.Json.JsonProperty(PropertyName = "typeNumber")]
public double? TypeNumber { get; set; }

/// <summary>
/// Gets or sets this is number
/// </summary>
[Newtonsoft.Json.JsonProperty(PropertyName = "typeNumber32")]
public double? TypeNumber32 { get; set; }

/// <summary>
/// Gets or sets this is number
/// </summary>
[Newtonsoft.Json.JsonProperty(PropertyName = "typeNumber64")]
public double? TypeNumber64 { get; set; }

/// <summary>
/// Gets or sets this is number
/// </summary>
[Newtonsoft.Json.JsonProperty(PropertyName = "typeNumber128")]
public decimal? TypeNumber128 { get; set; }

/// <summary>
/// Gets or sets this is constant. Possible values include: 'const'
/// </summary>
Expand Down
15 changes: 15 additions & 0 deletions tests-upgrade/tests-sdk1-support/model-validate/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,21 @@
"type": "number",
"description": "This is number"
},
"typeNumber32": {
"type": "number",
"format": "float",
"description": "This is number"
},
"typeNumber64": {
"type": "number",
"format": "double",
"description": "This is number"
},
"typeNumber128": {
"type": "number",
"format": "decimal",
"description": "This is number"
},
"typeConstant": {
"type": "string",
"description": "This is constant",
Expand Down

0 comments on commit e2130bd

Please sign in to comment.