Skip to content

Commit

Permalink
[DART] fix: set fields to null if json value is null. (#1798)
Browse files Browse the repository at this point in the history
* fix: set fields to null if json value is null.

* rebuild dart2 petstore

* rebuild dart petstore

* rebuild petstore

* [DART]fix: set fields to null if json value is null.
  • Loading branch information
d3v-cl authored and wing328 committed Jan 8, 2019
1 parent 293066b commit 9ccf872
Show file tree
Hide file tree
Showing 134 changed files with 4,342 additions and 2,945 deletions.
18 changes: 11 additions & 7 deletions modules/openapi-generator/src/main/resources/dart/class.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,41 @@ class {{classname}} {
{{classname}}.fromJson(Map<String, dynamic> json) {
if (json == null) return;
{{#vars}}
if (json['{{baseName}}'] == null) {
{{name}} = null;
} else {
{{#isDateTime}}
{{name}} = json['{{baseName}}'] == null ? null : DateTime.parse(json['{{baseName}}']);
{{name}} = DateTime.parse(json['{{baseName}}']);
{{/isDateTime}}
{{#isDate}}
{{name}} = json['{{baseName}}'] == null ? null : DateTime.parse(json['{{baseName}}']);
{{name}} = DateTime.parse(json['{{baseName}}']);
{{/isDate}}
{{^isDateTime}}
{{^isDate}}
{{#complexType}}
{{#isListContainer}}
{{name}} = {{complexType}}.listFromJson(json['{{baseName}}']);
{{name}} = {{complexType}}.listFromJson(json['{{baseName}}']);
{{/isListContainer}}
{{^isListContainer}}
{{#isMapContainer}}
{{name}} = {{complexType}}.mapFromJson(json['{{baseName}}']);
{{name}} = {{complexType}}.mapFromJson(json['{{baseName}}']);
{{/isMapContainer}}
{{^isMapContainer}}
{{name}} = new {{complexType}}.fromJson(json['{{baseName}}']);
{{name}} = new {{complexType}}.fromJson(json['{{baseName}}']);
{{/isMapContainer}}
{{/isListContainer}}
{{/complexType}}
{{^complexType}}
{{#isListContainer}}
{{name}} = (json['{{baseName}}'] as List).map((item) => item as {{items.datatype}}).toList();
{{name}} = (json['{{baseName}}'] as List).map((item) => item as {{items.datatype}}).toList();
{{/isListContainer}}
{{^isListContainer}}
{{name}} = json['{{baseName}}'];
{{name}} = json['{{baseName}}'];
{{/isListContainer}}
{{/complexType}}
{{/isDate}}
{{/isDateTime}}
}
{{/vars}}
}

Expand Down
18 changes: 11 additions & 7 deletions modules/openapi-generator/src/main/resources/dart2/class.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,41 @@ class {{classname}} {
{{classname}}.fromJson(Map<String, dynamic> json) {
if (json == null) return;
{{#vars}}
if (json['{{baseName}}'] == null) {
{{name}} = null;
} else {
{{#isDateTime}}
{{name}} = json['{{baseName}}'] == null ? null : DateTime.parse(json['{{baseName}}']);
{{name}} = DateTime.parse(json['{{baseName}}']);
{{/isDateTime}}
{{#isDate}}
{{name}} = json['{{baseName}}'] == null ? null : DateTime.parse(json['{{baseName}}']);
{{name}} = DateTime.parse(json['{{baseName}}']);
{{/isDate}}
{{^isDateTime}}
{{^isDate}}
{{#complexType}}
{{#isListContainer}}
{{name}} = {{complexType}}.listFromJson(json['{{baseName}}']);
{{name}} = {{complexType}}.listFromJson(json['{{baseName}}']);
{{/isListContainer}}
{{^isListContainer}}
{{#isMapContainer}}
{{name}} = {{complexType}}.mapFromJson(json['{{baseName}}']);
{{name}} = {{complexType}}.mapFromJson(json['{{baseName}}']);
{{/isMapContainer}}
{{^isMapContainer}}
{{name}} = new {{complexType}}.fromJson(json['{{baseName}}']);
{{name}} = new {{complexType}}.fromJson(json['{{baseName}}']);
{{/isMapContainer}}
{{/isListContainer}}
{{/complexType}}
{{^complexType}}
{{#isListContainer}}
{{name}} = ((json['{{baseName}}'] ?? []) as List).map((item) => item as {{items.datatype}}).toList();
{{name}} = (json['{{baseName}}'] as List).map((item) => item as {{items.datatype}}).toList();
{{/isListContainer}}
{{^isListContainer}}
{{name}} = json['{{baseName}}'];
{{name}} = json['{{baseName}}'];
{{/isListContainer}}
{{/complexType}}
{{/isDate}}
{{/isDateTime}}
}
{{/vars}}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.1-SNAPSHOT
4.0.0-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ import 'package:openapi/api.dart';
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
var api_instance = new PetApi();
var pet = new Pet(); // Pet | Pet object that needs to be added to the store
var body = new Pet(); // Pet | Pet object that needs to be added to the store
try {
api_instance.addPet(pet);
api_instance.addPet(body);
} catch (e) {
print("Exception when calling PetApi->addPet: $e\n");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Method | HTTP request | Description


# **addPet**
> addPet(pet)
> addPet(body)
Add a new pet to the store

Expand All @@ -31,10 +31,10 @@ import 'package:openapi/api.dart';
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
var api_instance = new PetApi();
var pet = new Pet(); // Pet | Pet object that needs to be added to the store
var body = new Pet(); // Pet | Pet object that needs to be added to the store
try {
api_instance.addPet(pet);
api_instance.addPet(body);
} catch (e) {
print("Exception when calling PetApi->addPet: $e\n");
}
Expand All @@ -44,7 +44,7 @@ try {

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**pet** | [**Pet**](Pet.md)| Pet object that needs to be added to the store |
**body** | [**Pet**](Pet.md)| Pet object that needs to be added to the store |

### Return type

Expand Down Expand Up @@ -243,7 +243,7 @@ Name | Type | Description | Notes
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)

# **updatePet**
> updatePet(pet)
> updatePet(body)
Update an existing pet

Expand All @@ -254,10 +254,10 @@ import 'package:openapi/api.dart';
//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
var api_instance = new PetApi();
var pet = new Pet(); // Pet | Pet object that needs to be added to the store
var body = new Pet(); // Pet | Pet object that needs to be added to the store
try {
api_instance.updatePet(pet);
api_instance.updatePet(body);
} catch (e) {
print("Exception when calling PetApi->updatePet: $e\n");
}
Expand All @@ -267,7 +267,7 @@ try {

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**pet** | [**Pet**](Pet.md)| Pet object that needs to be added to the store |
**body** | [**Pet**](Pet.md)| Pet object that needs to be added to the store |

### Return type

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ No authorization required
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)

# **placeOrder**
> Order placeOrder(order)
> Order placeOrder(body)
Place an order for a pet

Expand All @@ -153,10 +153,10 @@ Place an order for a pet
import 'package:openapi/api.dart';
var api_instance = new StoreApi();
var order = new Order(); // Order | order placed for purchasing the pet
var body = new Order(); // Order | order placed for purchasing the pet
try {
var result = api_instance.placeOrder(order);
var result = api_instance.placeOrder(body);
print(result);
} catch (e) {
print("Exception when calling StoreApi->placeOrder: $e\n");
Expand All @@ -167,7 +167,7 @@ try {

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**order** | [**Order**](Order.md)| order placed for purchasing the pet |
**body** | [**Order**](Order.md)| order placed for purchasing the pet |

### Return type

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Method | HTTP request | Description


# **createUser**
> createUser(user)
> createUser(body)
Create user

Expand All @@ -31,10 +31,10 @@ This can only be done by the logged in user.
import 'package:openapi/api.dart';
var api_instance = new UserApi();
var user = new User(); // User | Created user object
var body = new User(); // User | Created user object
try {
api_instance.createUser(user);
api_instance.createUser(body);
} catch (e) {
print("Exception when calling UserApi->createUser: $e\n");
}
Expand All @@ -44,7 +44,7 @@ try {

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**user** | [**User**](User.md)| Created user object |
**body** | [**User**](User.md)| Created user object |

### Return type

Expand All @@ -62,7 +62,7 @@ No authorization required
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)

# **createUsersWithArrayInput**
> createUsersWithArrayInput(user)
> createUsersWithArrayInput(body)
Creates list of users with given input array

Expand All @@ -71,10 +71,10 @@ Creates list of users with given input array
import 'package:openapi/api.dart';
var api_instance = new UserApi();
var user = [new List&lt;User&gt;()]; // List<User> | List of user object
var body = [new List&lt;User&gt;()]; // List<User> | List of user object
try {
api_instance.createUsersWithArrayInput(user);
api_instance.createUsersWithArrayInput(body);
} catch (e) {
print("Exception when calling UserApi->createUsersWithArrayInput: $e\n");
}
Expand All @@ -84,7 +84,7 @@ try {

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**user** | [**List&lt;User&gt;**](List.md)| List of user object |
**body** | [**List&lt;User&gt;**](List.md)| List of user object |

### Return type

Expand All @@ -102,7 +102,7 @@ No authorization required
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)

# **createUsersWithListInput**
> createUsersWithListInput(user)
> createUsersWithListInput(body)
Creates list of users with given input array

Expand All @@ -111,10 +111,10 @@ Creates list of users with given input array
import 'package:openapi/api.dart';
var api_instance = new UserApi();
var user = [new List&lt;User&gt;()]; // List<User> | List of user object
var body = [new List&lt;User&gt;()]; // List<User> | List of user object
try {
api_instance.createUsersWithListInput(user);
api_instance.createUsersWithListInput(body);
} catch (e) {
print("Exception when calling UserApi->createUsersWithListInput: $e\n");
}
Expand All @@ -124,7 +124,7 @@ try {

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**user** | [**List&lt;User&gt;**](List.md)| List of user object |
**body** | [**List&lt;User&gt;**](List.md)| List of user object |

### Return type

Expand Down Expand Up @@ -304,7 +304,7 @@ No authorization required
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)

# **updateUser**
> updateUser(username, user)
> updateUser(username, body)
Updated user

Expand All @@ -316,10 +316,10 @@ import 'package:openapi/api.dart';
var api_instance = new UserApi();
var username = username_example; // String | name that need to be deleted
var user = new User(); // User | Updated user object
var body = new User(); // User | Updated user object
try {
api_instance.updateUser(username, user);
api_instance.updateUser(username, body);
} catch (e) {
print("Exception when calling UserApi->updateUser: $e\n");
}
Expand All @@ -330,7 +330,7 @@ try {
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**username** | **String**| name that need to be deleted | [default to null]
**user** | [**User**](User.md)| Updated user object |
**body** | [**User**](User.md)| Updated user object |

### Return type

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ part 'model/pet.dart';
part 'model/tag.dart';
part 'model/user.dart';


ApiClient defaultApiClient = new ApiClient();
Loading

0 comments on commit 9ccf872

Please sign in to comment.