Skip to content

Commit

Permalink
Better tests for string (number) (OpenAPITools#3953)
Browse files Browse the repository at this point in the history
* beter test for string (number)

* fix mapping

* fix mapping in csharp generators
  • Loading branch information
wing328 authored and Jesse Michael committed Oct 3, 2019
1 parent 85a6d56 commit 0a549e5
Show file tree
Hide file tree
Showing 119 changed files with 1,693 additions and 136 deletions.
Expand Up @@ -1068,8 +1068,7 @@ public DefaultCodegen() {
typeMapping.put("file", "File");
typeMapping.put("UUID", "UUID");
typeMapping.put("URI", "URI");
typeMapping.put("BigDecimal", "BigDecimal"); //TODO need the mapping?

typeMapping.put("BigDecimal", "BigDecimal");

instantiationTypes = new HashMap<String, String>();

Expand Down
Expand Up @@ -181,6 +181,7 @@ public AbstractCSharpCodegen() {
typeMapping.put("long", "long?");
typeMapping.put("double", "double?");
typeMapping.put("number", "decimal?");
typeMapping.put("BigDecimal", "decimal?");
typeMapping.put("DateTime", "DateTime?");
typeMapping.put("date", "DateTime?");
typeMapping.put("file", "System.IO.Stream");
Expand Down
Expand Up @@ -96,6 +96,7 @@ public AbstractGoCodegen() {
typeMapping.put("number", "float32");
typeMapping.put("float", "float32");
typeMapping.put("double", "float64");
typeMapping.put("BigDecimal", "float64");
typeMapping.put("boolean", "bool");
typeMapping.put("string", "string");
typeMapping.put("UUID", "string");
Expand Down
Expand Up @@ -95,6 +95,7 @@ public CSharpClientCodegen() {
typeMapping.put("long", "long");
typeMapping.put("double", "double");
typeMapping.put("number", "decimal");
typeMapping.put("BigDecimal", "decimal");
typeMapping.put("DateTime", "DateTime");
typeMapping.put("date", "DateTime");
typeMapping.put("UUID", "Guid");
Expand Down
Expand Up @@ -94,6 +94,7 @@ public CSharpNetCoreClientCodegen() {
typeMapping.put("long", "long");
typeMapping.put("double", "double");
typeMapping.put("number", "decimal");
typeMapping.put("BigDecimal", "decimal");
typeMapping.put("DateTime", "DateTime");
typeMapping.put("date", "DateTime");
typeMapping.put("file", "System.IO.Stream");
Expand Down
Expand Up @@ -222,6 +222,7 @@ public HaskellHttpClientCodegen() {
typeMapping.put("float", "Float");
typeMapping.put("double", "Double");
typeMapping.put("number", "Double");
typeMapping.put("BigDecimal", "Double");
typeMapping.put("integer", "Int");
typeMapping.put("file", "FilePath");
// lib
Expand Down
Expand Up @@ -171,6 +171,7 @@ public HaskellServantCodegen() {
typeMapping.put("file", "FilePath");
typeMapping.put("binary", "FilePath");
typeMapping.put("number", "Double");
typeMapping.put("BigDecimal", "Double");
typeMapping.put("any", "Value");
typeMapping.put("UUID", "UUID");
typeMapping.put("URI", "Text");
Expand Down
Expand Up @@ -144,6 +144,7 @@ public JavascriptClientCodegen() {
typeMapping.put("int", "Number");
typeMapping.put("float", "Number");
typeMapping.put("number", "Number");
typeMapping.put("BigDecimal", "Number");
typeMapping.put("DateTime", "Date");
typeMapping.put("date", "Date");
typeMapping.put("long", "Number");
Expand Down
Expand Up @@ -1403,6 +1403,9 @@ definitions:
format: password
maxLength: 64
minLength: 10
BigDecimal:
type: string
format: number
EnumClass:
type: string
default: '-efg'
Expand Down
Expand Up @@ -16,6 +16,7 @@ Name | Type | Description | Notes
**DateTime** | **DateTime** | | [optional]
**Uuid** | **Guid** | | [optional]
**Password** | **string** | |
**BigDecimal** | **decimal** | | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Up @@ -53,7 +53,8 @@ public partial class FormatTest : IEquatable<FormatTest>, IValidatableObject
/// <param name="dateTime">dateTime.</param>
/// <param name="uuid">uuid.</param>
/// <param name="password">password (required).</param>
public FormatTest(int integer = default(int), int int32 = default(int), long int64 = default(long), decimal number = default(decimal), float _float = default(float), double _double = default(double), string _string = default(string), byte[] _byte = default(byte[]), System.IO.Stream binary = default(System.IO.Stream), DateTime date = default(DateTime), DateTime dateTime = default(DateTime), Guid uuid = default(Guid), string password = default(string))
/// <param name="bigDecimal">bigDecimal.</param>
public FormatTest(int integer = default(int), int int32 = default(int), long int64 = default(long), decimal number = default(decimal), float _float = default(float), double _double = default(double), string _string = default(string), byte[] _byte = default(byte[]), System.IO.Stream binary = default(System.IO.Stream), DateTime date = default(DateTime), DateTime dateTime = default(DateTime), Guid uuid = default(Guid), string password = default(string), decimal bigDecimal = default(decimal))
{
// to ensure "number" is required (not null)
if (number == null)
Expand Down Expand Up @@ -104,6 +105,7 @@ public FormatTest(int integer = default(int), int int32 = default(int), long int
this.Binary = binary;
this.DateTime = dateTime;
this.Uuid = uuid;
this.BigDecimal = bigDecimal;
}

/// <summary>
Expand Down Expand Up @@ -185,6 +187,12 @@ public FormatTest(int integer = default(int), int int32 = default(int), long int
[DataMember(Name="password", EmitDefaultValue=false)]
public string Password { get; set; }

/// <summary>
/// Gets or Sets BigDecimal
/// </summary>
[DataMember(Name="BigDecimal", EmitDefaultValue=false)]
public decimal BigDecimal { get; set; }

/// <summary>
/// Returns the string presentation of the object
/// </summary>
Expand All @@ -206,6 +214,7 @@ public override string ToString()
sb.Append(" DateTime: ").Append(DateTime).Append("\n");
sb.Append(" Uuid: ").Append(Uuid).Append("\n");
sb.Append(" Password: ").Append(Password).Append("\n");
sb.Append(" BigDecimal: ").Append(BigDecimal).Append("\n");
sb.Append("}\n");
return sb.ToString();
}
Expand Down Expand Up @@ -268,6 +277,7 @@ public override int GetHashCode()
hashCode = hashCode * 59 + this.Uuid.GetHashCode();
if (this.Password != null)
hashCode = hashCode * 59 + this.Password.GetHashCode();
hashCode = hashCode * 59 + this.BigDecimal.GetHashCode();
return hashCode;
}
}
Expand Down
Expand Up @@ -16,6 +16,7 @@ Name | Type | Description | Notes
**DateTime** | **DateTime** | | [optional]
**Uuid** | **Guid** | | [optional]
**Password** | **string** | |
**BigDecimal** | **decimal** | | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Up @@ -53,7 +53,8 @@ public partial class FormatTest : IEquatable<FormatTest>, IValidatableObject
/// <param name="dateTime">dateTime.</param>
/// <param name="uuid">uuid.</param>
/// <param name="password">password (required).</param>
public FormatTest(int integer = default(int), int int32 = default(int), long int64 = default(long), decimal number = default(decimal), float _float = default(float), double _double = default(double), string _string = default(string), byte[] _byte = default(byte[]), System.IO.Stream binary = default(System.IO.Stream), DateTime date = default(DateTime), DateTime dateTime = default(DateTime), Guid uuid = default(Guid), string password = default(string))
/// <param name="bigDecimal">bigDecimal.</param>
public FormatTest(int integer = default(int), int int32 = default(int), long int64 = default(long), decimal number = default(decimal), float _float = default(float), double _double = default(double), string _string = default(string), byte[] _byte = default(byte[]), System.IO.Stream binary = default(System.IO.Stream), DateTime date = default(DateTime), DateTime dateTime = default(DateTime), Guid uuid = default(Guid), string password = default(string), decimal bigDecimal = default(decimal))
{
// to ensure "number" is required (not null)
if (number == null)
Expand Down Expand Up @@ -104,6 +105,7 @@ public FormatTest(int integer = default(int), int int32 = default(int), long int
this.Binary = binary;
this.DateTime = dateTime;
this.Uuid = uuid;
this.BigDecimal = bigDecimal;
}

/// <summary>
Expand Down Expand Up @@ -185,6 +187,12 @@ public FormatTest(int integer = default(int), int int32 = default(int), long int
[DataMember(Name="password", EmitDefaultValue=false)]
public string Password { get; set; }

/// <summary>
/// Gets or Sets BigDecimal
/// </summary>
[DataMember(Name="BigDecimal", EmitDefaultValue=false)]
public decimal BigDecimal { get; set; }

/// <summary>
/// Returns the string presentation of the object
/// </summary>
Expand All @@ -206,6 +214,7 @@ public override string ToString()
sb.Append(" DateTime: ").Append(DateTime).Append("\n");
sb.Append(" Uuid: ").Append(Uuid).Append("\n");
sb.Append(" Password: ").Append(Password).Append("\n");
sb.Append(" BigDecimal: ").Append(BigDecimal).Append("\n");
sb.Append("}\n");
return sb.ToString();
}
Expand Down Expand Up @@ -268,6 +277,7 @@ public override int GetHashCode()
hashCode = hashCode * 59 + this.Uuid.GetHashCode();
if (this.Password != null)
hashCode = hashCode * 59 + this.Password.GetHashCode();
hashCode = hashCode * 59 + this.BigDecimal.GetHashCode();
return hashCode;
}
}
Expand Down
Expand Up @@ -18,6 +18,7 @@ Name | Type | Description | Notes
**DateTime** | **DateTime** | | [optional]
**Uuid** | **Guid** | | [optional]
**Password** | **string** | |
**BigDecimal** | **decimal** | | [optional]

[[Back to Model list]](../README.md#documentation-for-models)
[[Back to API list]](../README.md#documentation-for-api-endpoints)
Expand Down
Expand Up @@ -51,7 +51,8 @@ public partial class FormatTest : IEquatable<FormatTest>, IValidatableObject
/// <param name="dateTime">dateTime.</param>
/// <param name="uuid">uuid.</param>
/// <param name="password">password (required).</param>
public FormatTest(int integer = default(int), int int32 = default(int), long int64 = default(long), decimal number = default(decimal), float _float = default(float), double _double = default(double), string _string = default(string), byte[] _byte = default(byte[]), System.IO.Stream binary = default(System.IO.Stream), DateTime date = default(DateTime), DateTime dateTime = default(DateTime), Guid uuid = default(Guid), string password = default(string))
/// <param name="bigDecimal">bigDecimal.</param>
public FormatTest(int integer = default(int), int int32 = default(int), long int64 = default(long), decimal number = default(decimal), float _float = default(float), double _double = default(double), string _string = default(string), byte[] _byte = default(byte[]), System.IO.Stream binary = default(System.IO.Stream), DateTime date = default(DateTime), DateTime dateTime = default(DateTime), Guid uuid = default(Guid), string password = default(string), decimal bigDecimal = default(decimal))
{
// to ensure "number" is required (not null)
if (number == null)
Expand Down Expand Up @@ -102,6 +103,7 @@ public FormatTest(int integer = default(int), int int32 = default(int), long int
this.Binary = binary;
this.DateTime = dateTime;
this.Uuid = uuid;
this.BigDecimal = bigDecimal;
}

/// <summary>
Expand Down Expand Up @@ -183,6 +185,12 @@ public FormatTest(int integer = default(int), int int32 = default(int), long int
[DataMember(Name="password", EmitDefaultValue=false)]
public string Password { get; set; }

/// <summary>
/// Gets or Sets BigDecimal
/// </summary>
[DataMember(Name="BigDecimal", EmitDefaultValue=false)]
public decimal BigDecimal { get; set; }

/// <summary>
/// Returns the string presentation of the object
/// </summary>
Expand All @@ -204,6 +212,7 @@ public override string ToString()
sb.Append(" DateTime: ").Append(DateTime).Append("\n");
sb.Append(" Uuid: ").Append(Uuid).Append("\n");
sb.Append(" Password: ").Append(Password).Append("\n");
sb.Append(" BigDecimal: ").Append(BigDecimal).Append("\n");
sb.Append("}\n");
return sb.ToString();
}
Expand Down Expand Up @@ -302,6 +311,11 @@ public bool Equals(FormatTest input)
this.Password == input.Password ||
(this.Password != null &&
this.Password.Equals(input.Password))
) &&
(
this.BigDecimal == input.BigDecimal ||
(this.BigDecimal != null &&
this.BigDecimal.Equals(input.BigDecimal))
);
}

Expand Down Expand Up @@ -340,6 +354,8 @@ public override int GetHashCode()
hashCode = hashCode * 59 + this.Uuid.GetHashCode();
if (this.Password != null)
hashCode = hashCode * 59 + this.Password.GetHashCode();
if (this.BigDecimal != null)
hashCode = hashCode * 59 + this.BigDecimal.GetHashCode();
return hashCode;
}
}
Expand Down
Expand Up @@ -21,7 +21,8 @@ defmodule OpenapiPetstore.Model.FormatTest do
:"date",
:"dateTime",
:"uuid",
:"password"
:"password",
:"BigDecimal"
]

@type t :: %__MODULE__{
Expand All @@ -37,7 +38,8 @@ defmodule OpenapiPetstore.Model.FormatTest do
:"date" => Date.t,
:"dateTime" => DateTime.t | nil,
:"uuid" => String.t | nil,
:"password" => String.t
:"password" => String.t,
:"BigDecimal" => String.t | nil
}
end

Expand All @@ -46,6 +48,7 @@ defimpl Poison.Decoder, for: OpenapiPetstore.Model.FormatTest do
def decode(value, options) do
value
|> deserialize(:"date", :date, nil, options)
|> deserialize(:"BigDecimal", :struct, OpenapiPetstore.Model.String.t, options)
end
end

Expand Up @@ -1491,6 +1491,9 @@ components:
maxLength: 64
minLength: 10
type: string
BigDecimal:
format: number
type: string
required:
- byte
- date
Expand Down
Expand Up @@ -17,6 +17,7 @@ Name | Type | Description | Notes
**DateTime** | [**time.Time**](time.Time.md) | | [optional]
**Uuid** | **string** | | [optional]
**Password** | **string** | |
**BigDecimal** | **float64** | | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions samples/client/petstore/go/go-petstore/api/openapi.yaml
Expand Up @@ -1491,6 +1491,9 @@ components:
maxLength: 64
minLength: 10
type: string
BigDecimal:
format: number
type: string
required:
- byte
- date
Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore/go/go-petstore/docs/FormatTest.md
Expand Up @@ -17,6 +17,7 @@ Name | Type | Description | Notes
**DateTime** | [**time.Time**](time.Time.md) | | [optional]
**Uuid** | **string** | | [optional]
**Password** | **string** | |
**BigDecimal** | **float64** | | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Down
Expand Up @@ -27,4 +27,5 @@ type FormatTest struct {
DateTime time.Time `json:"dateTime,omitempty"`
Uuid string `json:"uuid,omitempty"`
Password string `json:"password"`
BigDecimal float64 `json:"BigDecimal,omitempty"`
}
Expand Up @@ -1075,6 +1075,7 @@ data FormatTest = FormatTest
, formatTestDateTime :: !(Maybe DateTime) -- ^ "dateTime"
, formatTestUuid :: !(Maybe Text) -- ^ "uuid"
, formatTestPassword :: !(Text) -- ^ /Required/ "password"
, formatTestBigDecimal :: !(Maybe Double) -- ^ "BigDecimal"
} deriving (P.Show, P.Eq, P.Typeable)

-- | FromJSON FormatTest
Expand All @@ -1094,6 +1095,7 @@ instance A.FromJSON FormatTest where
<*> (o .:? "dateTime")
<*> (o .:? "uuid")
<*> (o .: "password")
<*> (o .:? "BigDecimal")

-- | ToJSON FormatTest
instance A.ToJSON FormatTest where
Expand All @@ -1112,6 +1114,7 @@ instance A.ToJSON FormatTest where
, "dateTime" .= formatTestDateTime
, "uuid" .= formatTestUuid
, "password" .= formatTestPassword
, "BigDecimal" .= formatTestBigDecimal
]


Expand All @@ -1137,6 +1140,7 @@ mkFormatTest formatTestNumber formatTestByte formatTestDate formatTestPassword =
, formatTestDateTime = Nothing
, formatTestUuid = Nothing
, formatTestPassword
, formatTestBigDecimal = Nothing
}

-- ** HasOnlyReadOnly
Expand Down
Expand Up @@ -487,6 +487,11 @@ formatTestPasswordL :: Lens_' FormatTest (Text)
formatTestPasswordL f FormatTest{..} = (\formatTestPassword -> FormatTest { formatTestPassword, ..} ) <$> f formatTestPassword
{-# INLINE formatTestPasswordL #-}

-- | 'formatTestBigDecimal' Lens
formatTestBigDecimalL :: Lens_' FormatTest (Maybe Double)
formatTestBigDecimalL f FormatTest{..} = (\formatTestBigDecimal -> FormatTest { formatTestBigDecimal, ..} ) <$> f formatTestBigDecimal
{-# INLINE formatTestBigDecimalL #-}



-- * HasOnlyReadOnly
Expand Down
3 changes: 3 additions & 0 deletions samples/client/petstore/haskell-http-client/openapi.yaml
Expand Up @@ -1491,6 +1491,9 @@ components:
maxLength: 64
minLength: 10
type: string
BigDecimal:
format: number
type: string
required:
- byte
- date
Expand Down
Expand Up @@ -354,6 +354,7 @@ genFormatTest n =
<*> arbitraryReducedMaybe n -- formatTestDateTime :: Maybe DateTime
<*> arbitraryReducedMaybe n -- formatTestUuid :: Maybe Text
<*> arbitrary -- formatTestPassword :: Text
<*> arbitraryReducedMaybe n -- formatTestBigDecimal :: Maybe Double

instance Arbitrary HasOnlyReadOnly where
arbitrary = sized genHasOnlyReadOnly
Expand Down

0 comments on commit 0a549e5

Please sign in to comment.