Skip to content

Commit

Permalink
[Java][okhttp-gson] fix failure to deserialize floats (OpenAPITools#…
Browse files Browse the repository at this point in the history
…3846)

* fixed bug where nullApi.java would be generated.  Instead, generated DefaultApi.java to match the default path /{pathParam}

* fix to bug OpenAPITools#3157

* update samples
  • Loading branch information
bensimpson-ch authored and hokamoto committed Sep 12, 2019
1 parent 2fb08fb commit 221443a
Show file tree
Hide file tree
Showing 147 changed files with 1,714 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

@Override
public {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} read(final JsonReader jsonReader) throws IOException {
{{^isNumber}}{{{dataType}}}{{/isNumber}}{{#isNumber}}String{{/isNumber}} value = jsonReader.{{#isNumber}}nextString(){{/isNumber}}{{#isInteger}}nextInt(){{/isInteger}}{{^isNumber}}{{^isInteger}}next{{{dataType}}}(){{/isInteger}}{{/isNumber}};
{{^isNumber}}{{{dataType}}}{{/isNumber}}{{#isNumber}}String{{/isNumber}} value = {{#isFloat}}(float){{/isFloat}} jsonReader.{{#isNumber}}nextString(){{/isNumber}}{{#isInteger}}nextInt(){{/isInteger}}{{^isNumber}}{{^isInteger}}{{#isFloat}}nextDouble{{/isFloat}}{{^isFloat}}next{{{dataType}}}{{/isFloat}}(){{/isInteger}}{{/isNumber}};
return {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}.fromValue({{#isNumber}}new BigDecimal({{/isNumber}}value{{#isNumber}}){{/isNumber}});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1783,6 +1783,7 @@ definitions:
required:
- string_item
- number_item
- float_item
- integer_item
- bool_item
- array_item
Expand All @@ -1793,6 +1794,10 @@ definitions:
number_item:
type: number
example: 1.234
float_item:
type: number
example: 1.234
format: float
integer_item:
type: integer
example: -2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**StringItem** | **string** | |
**NumberItem** | **decimal** | |
**FloatItem** | **float** | |
**IntegerItem** | **int** | |
**BoolItem** | **bool** | |
**ArrayItem** | **List<int>** | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ protected TypeHolderExample() { }
/// </summary>
/// <param name="stringItem">stringItem (required).</param>
/// <param name="numberItem">numberItem (required).</param>
/// <param name="floatItem">floatItem (required).</param>
/// <param name="integerItem">integerItem (required).</param>
/// <param name="boolItem">boolItem (required).</param>
/// <param name="arrayItem">arrayItem (required).</param>
public TypeHolderExample(string stringItem = default(string), decimal numberItem = default(decimal), int integerItem = default(int), bool boolItem = default(bool), List<int> arrayItem = default(List<int>))
public TypeHolderExample(string stringItem = default(string), decimal numberItem = default(decimal), float floatItem = default(float), int integerItem = default(int), bool boolItem = default(bool), List<int> arrayItem = default(List<int>))
{
// to ensure "stringItem" is required (not null)
if (stringItem == null)
Expand All @@ -67,6 +68,16 @@ protected TypeHolderExample() { }
this.NumberItem = numberItem;
}

// to ensure "floatItem" is required (not null)
if (floatItem == null)
{
throw new InvalidDataException("floatItem is a required property for TypeHolderExample and cannot be null");
}
else
{
this.FloatItem = floatItem;
}

// to ensure "integerItem" is required (not null)
if (integerItem == null)
{
Expand Down Expand Up @@ -111,6 +122,12 @@ protected TypeHolderExample() { }
[DataMember(Name="number_item", EmitDefaultValue=false)]
public decimal NumberItem { get; set; }

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

/// <summary>
/// Gets or Sets IntegerItem
/// </summary>
Expand Down Expand Up @@ -139,6 +156,7 @@ public override string ToString()
sb.Append("class TypeHolderExample {\n");
sb.Append(" StringItem: ").Append(StringItem).Append("\n");
sb.Append(" NumberItem: ").Append(NumberItem).Append("\n");
sb.Append(" FloatItem: ").Append(FloatItem).Append("\n");
sb.Append(" IntegerItem: ").Append(IntegerItem).Append("\n");
sb.Append(" BoolItem: ").Append(BoolItem).Append("\n");
sb.Append(" ArrayItem: ").Append(ArrayItem).Append("\n");
Expand Down Expand Up @@ -187,6 +205,7 @@ public override int GetHashCode()
if (this.StringItem != null)
hashCode = hashCode * 59 + this.StringItem.GetHashCode();
hashCode = hashCode * 59 + this.NumberItem.GetHashCode();
hashCode = hashCode * 59 + this.FloatItem.GetHashCode();
hashCode = hashCode * 59 + this.IntegerItem.GetHashCode();
hashCode = hashCode * 59 + this.BoolItem.GetHashCode();
if (this.ArrayItem != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**StringItem** | **string** | |
**NumberItem** | **decimal** | |
**FloatItem** | **float** | |
**IntegerItem** | **int** | |
**BoolItem** | **bool** | |
**ArrayItem** | **List&lt;int&gt;** | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ protected TypeHolderExample() { }
/// </summary>
/// <param name="stringItem">stringItem (required).</param>
/// <param name="numberItem">numberItem (required).</param>
/// <param name="floatItem">floatItem (required).</param>
/// <param name="integerItem">integerItem (required).</param>
/// <param name="boolItem">boolItem (required).</param>
/// <param name="arrayItem">arrayItem (required).</param>
public TypeHolderExample(string stringItem = default(string), decimal numberItem = default(decimal), int integerItem = default(int), bool boolItem = default(bool), List<int> arrayItem = default(List<int>))
public TypeHolderExample(string stringItem = default(string), decimal numberItem = default(decimal), float floatItem = default(float), int integerItem = default(int), bool boolItem = default(bool), List<int> arrayItem = default(List<int>))
{
// to ensure "stringItem" is required (not null)
if (stringItem == null)
Expand All @@ -67,6 +68,16 @@ protected TypeHolderExample() { }
this.NumberItem = numberItem;
}

// to ensure "floatItem" is required (not null)
if (floatItem == null)
{
throw new InvalidDataException("floatItem is a required property for TypeHolderExample and cannot be null");
}
else
{
this.FloatItem = floatItem;
}

// to ensure "integerItem" is required (not null)
if (integerItem == null)
{
Expand Down Expand Up @@ -111,6 +122,12 @@ protected TypeHolderExample() { }
[DataMember(Name="number_item", EmitDefaultValue=false)]
public decimal NumberItem { get; set; }

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

/// <summary>
/// Gets or Sets IntegerItem
/// </summary>
Expand Down Expand Up @@ -139,6 +156,7 @@ public override string ToString()
sb.Append("class TypeHolderExample {\n");
sb.Append(" StringItem: ").Append(StringItem).Append("\n");
sb.Append(" NumberItem: ").Append(NumberItem).Append("\n");
sb.Append(" FloatItem: ").Append(FloatItem).Append("\n");
sb.Append(" IntegerItem: ").Append(IntegerItem).Append("\n");
sb.Append(" BoolItem: ").Append(BoolItem).Append("\n");
sb.Append(" ArrayItem: ").Append(ArrayItem).Append("\n");
Expand Down Expand Up @@ -187,6 +205,7 @@ public override int GetHashCode()
if (this.StringItem != null)
hashCode = hashCode * 59 + this.StringItem.GetHashCode();
hashCode = hashCode * 59 + this.NumberItem.GetHashCode();
hashCode = hashCode * 59 + this.FloatItem.GetHashCode();
hashCode = hashCode * 59 + this.IntegerItem.GetHashCode();
hashCode = hashCode * 59 + this.BoolItem.GetHashCode();
if (this.ArrayItem != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**StringItem** | **string** | |
**NumberItem** | **decimal** | |
**FloatItem** | **float** | |
**IntegerItem** | **int** | |
**BoolItem** | **bool** | |
**ArrayItem** | **List&lt;int&gt;** | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ protected TypeHolderExample() { }
/// </summary>
/// <param name="stringItem">stringItem (required).</param>
/// <param name="numberItem">numberItem (required).</param>
/// <param name="floatItem">floatItem (required).</param>
/// <param name="integerItem">integerItem (required).</param>
/// <param name="boolItem">boolItem (required).</param>
/// <param name="arrayItem">arrayItem (required).</param>
public TypeHolderExample(string stringItem = default(string), decimal numberItem = default(decimal), int integerItem = default(int), bool boolItem = default(bool), List<int> arrayItem = default(List<int>))
public TypeHolderExample(string stringItem = default(string), decimal numberItem = default(decimal), float floatItem = default(float), int integerItem = default(int), bool boolItem = default(bool), List<int> arrayItem = default(List<int>))
{
// to ensure "stringItem" is required (not null)
if (stringItem == null)
Expand All @@ -65,6 +66,16 @@ protected TypeHolderExample() { }
this.NumberItem = numberItem;
}

// to ensure "floatItem" is required (not null)
if (floatItem == null)
{
throw new InvalidDataException("floatItem is a required property for TypeHolderExample and cannot be null");
}
else
{
this.FloatItem = floatItem;
}

// to ensure "integerItem" is required (not null)
if (integerItem == null)
{
Expand Down Expand Up @@ -109,6 +120,12 @@ protected TypeHolderExample() { }
[DataMember(Name="number_item", EmitDefaultValue=false)]
public decimal NumberItem { get; set; }

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

/// <summary>
/// Gets or Sets IntegerItem
/// </summary>
Expand Down Expand Up @@ -137,6 +154,7 @@ public override string ToString()
sb.Append("class TypeHolderExample {\n");
sb.Append(" StringItem: ").Append(StringItem).Append("\n");
sb.Append(" NumberItem: ").Append(NumberItem).Append("\n");
sb.Append(" FloatItem: ").Append(FloatItem).Append("\n");
sb.Append(" IntegerItem: ").Append(IntegerItem).Append("\n");
sb.Append(" BoolItem: ").Append(BoolItem).Append("\n");
sb.Append(" ArrayItem: ").Append(ArrayItem).Append("\n");
Expand Down Expand Up @@ -184,6 +202,11 @@ public bool Equals(TypeHolderExample input)
(this.NumberItem != null &&
this.NumberItem.Equals(input.NumberItem))
) &&
(
this.FloatItem == input.FloatItem ||
(this.FloatItem != null &&
this.FloatItem.Equals(input.FloatItem))
) &&
(
this.IntegerItem == input.IntegerItem ||
(this.IntegerItem != null &&
Expand Down Expand Up @@ -215,6 +238,8 @@ public override int GetHashCode()
hashCode = hashCode * 59 + this.StringItem.GetHashCode();
if (this.NumberItem != null)
hashCode = hashCode * 59 + this.NumberItem.GetHashCode();
if (this.FloatItem != null)
hashCode = hashCode * 59 + this.FloatItem.GetHashCode();
if (this.IntegerItem != null)
hashCode = hashCode * 59 + this.IntegerItem.GetHashCode();
if (this.BoolItem != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ defmodule OpenapiPetstore.Model.TypeHolderExample do
defstruct [
:"string_item",
:"number_item",
:"float_item",
:"integer_item",
:"bool_item",
:"array_item"
Expand All @@ -19,6 +20,7 @@ defmodule OpenapiPetstore.Model.TypeHolderExample do
@type t :: %__MODULE__{
:"string_item" => String.t,
:"number_item" => float(),
:"float_item" => float(),
:"integer_item" => integer(),
:"bool_item" => boolean(),
:"array_item" => [integer()]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1869,6 +1869,10 @@ components:
number_item:
example: 1.234
type: number
float_item:
example: 1.234
format: float
type: number
integer_item:
example: -2
type: integer
Expand All @@ -1887,6 +1891,7 @@ components:
required:
- array_item
- bool_item
- float_item
- integer_item
- number_item
- string_item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**StringItem** | **string** | |
**NumberItem** | **float32** | |
**FloatItem** | **float32** | |
**IntegerItem** | **int32** | |
**BoolItem** | **bool** | |
**ArrayItem** | **[]int32** | |
Expand Down

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

5 changes: 5 additions & 0 deletions samples/client/petstore/go/go-petstore/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1869,6 +1869,10 @@ components:
number_item:
example: 1.234
type: number
float_item:
example: 1.234
format: float
type: number
integer_item:
example: -2
type: integer
Expand All @@ -1887,6 +1891,7 @@ components:
required:
- array_item
- bool_item
- float_item
- integer_item
- number_item
- string_item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**StringItem** | **string** | |
**NumberItem** | **float32** | |
**FloatItem** | **float32** | |
**IntegerItem** | **int32** | |
**BoolItem** | **bool** | |
**ArrayItem** | **[]int32** | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package petstore
type TypeHolderExample struct {
StringItem string `json:"string_item"`
NumberItem float32 `json:"number_item"`
FloatItem float32 `json:"float_item"`
IntegerItem int32 `json:"integer_item"`
BoolItem bool `json:"bool_item"`
ArrayItem []int32 `json:"array_item"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1687,6 +1687,7 @@ mkTypeHolderDefault typeHolderDefaultStringItem typeHolderDefaultNumberItem type
data TypeHolderExample = TypeHolderExample
{ typeHolderExampleStringItem :: !(Text) -- ^ /Required/ "string_item"
, typeHolderExampleNumberItem :: !(Double) -- ^ /Required/ "number_item"
, typeHolderExampleFloatItem :: !(Float) -- ^ /Required/ "float_item"
, typeHolderExampleIntegerItem :: !(Int) -- ^ /Required/ "integer_item"
, typeHolderExampleBoolItem :: !(Bool) -- ^ /Required/ "bool_item"
, typeHolderExampleArrayItem :: !([Int]) -- ^ /Required/ "array_item"
Expand All @@ -1698,6 +1699,7 @@ instance A.FromJSON TypeHolderExample where
TypeHolderExample
<$> (o .: "string_item")
<*> (o .: "number_item")
<*> (o .: "float_item")
<*> (o .: "integer_item")
<*> (o .: "bool_item")
<*> (o .: "array_item")
Expand All @@ -1708,6 +1710,7 @@ instance A.ToJSON TypeHolderExample where
_omitNulls
[ "string_item" .= typeHolderExampleStringItem
, "number_item" .= typeHolderExampleNumberItem
, "float_item" .= typeHolderExampleFloatItem
, "integer_item" .= typeHolderExampleIntegerItem
, "bool_item" .= typeHolderExampleBoolItem
, "array_item" .= typeHolderExampleArrayItem
Expand All @@ -1718,14 +1721,16 @@ instance A.ToJSON TypeHolderExample where
mkTypeHolderExample
:: Text -- ^ 'typeHolderExampleStringItem'
-> Double -- ^ 'typeHolderExampleNumberItem'
-> Float -- ^ 'typeHolderExampleFloatItem'
-> Int -- ^ 'typeHolderExampleIntegerItem'
-> Bool -- ^ 'typeHolderExampleBoolItem'
-> [Int] -- ^ 'typeHolderExampleArrayItem'
-> TypeHolderExample
mkTypeHolderExample typeHolderExampleStringItem typeHolderExampleNumberItem typeHolderExampleIntegerItem typeHolderExampleBoolItem typeHolderExampleArrayItem =
mkTypeHolderExample typeHolderExampleStringItem typeHolderExampleNumberItem typeHolderExampleFloatItem typeHolderExampleIntegerItem typeHolderExampleBoolItem typeHolderExampleArrayItem =
TypeHolderExample
{ typeHolderExampleStringItem
, typeHolderExampleNumberItem
, typeHolderExampleFloatItem
, typeHolderExampleIntegerItem
, typeHolderExampleBoolItem
, typeHolderExampleArrayItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,11 @@ typeHolderExampleNumberItemL :: Lens_' TypeHolderExample (Double)
typeHolderExampleNumberItemL f TypeHolderExample{..} = (\typeHolderExampleNumberItem -> TypeHolderExample { typeHolderExampleNumberItem, ..} ) <$> f typeHolderExampleNumberItem
{-# INLINE typeHolderExampleNumberItemL #-}

-- | 'typeHolderExampleFloatItem' Lens
typeHolderExampleFloatItemL :: Lens_' TypeHolderExample (Float)
typeHolderExampleFloatItemL f TypeHolderExample{..} = (\typeHolderExampleFloatItem -> TypeHolderExample { typeHolderExampleFloatItem, ..} ) <$> f typeHolderExampleFloatItem
{-# INLINE typeHolderExampleFloatItemL #-}

-- | 'typeHolderExampleIntegerItem' Lens
typeHolderExampleIntegerItemL :: Lens_' TypeHolderExample (Int)
typeHolderExampleIntegerItemL f TypeHolderExample{..} = (\typeHolderExampleIntegerItem -> TypeHolderExample { typeHolderExampleIntegerItem, ..} ) <$> f typeHolderExampleIntegerItem
Expand Down
Loading

0 comments on commit 221443a

Please sign in to comment.