forked from loafle/openapi-generator-original
[dart2] Fix up test code generation, double deserialization, 'new' keyword deprecation (#3576)
* dart2: Use the correct classname in test generation At present test generation has a stray hard-coded reference to the pet store Pet() class, which should reflect the actual classname under test. * dart2: Call toDouble() in generated code for double types At present the generated code does not correctly handle transitioning to double when dealing with non-integer types in JSON deserialization. This ends up with dart raising an unhandled type mismatch exception: Unhandled exception: type 'int' is not a subtype of type 'double' where ... Using the .toDouble() conversion when a double type is expected fixes this up by making the typing explicit. * dart2: Drop use of deprecated 'new' keyword in generated code The use of the 'new' keyword in dart2 is deprecated and should be avoided, as per the official guidance of the dart2 authors: https://dart.dev/guides/language/effective-dart/usage#dont-use-new * dart2: Regenerate samples for mustache template changes
This commit is contained in:
committed by
William Cheng
parent
1152af4d02
commit
4b0fc3013f
@@ -45,13 +45,13 @@ class ApiResponse {
|
||||
}
|
||||
|
||||
static List<ApiResponse> listFromJson(List<dynamic> json) {
|
||||
return json == null ? new List<ApiResponse>() : json.map((value) => new ApiResponse.fromJson(value)).toList();
|
||||
return json == null ? List<ApiResponse>() : json.map((value) => ApiResponse.fromJson(value)).toList();
|
||||
}
|
||||
|
||||
static Map<String, ApiResponse> mapFromJson(Map<String, dynamic> json) {
|
||||
var map = new Map<String, ApiResponse>();
|
||||
var map = Map<String, ApiResponse>();
|
||||
if (json != null && json.isNotEmpty) {
|
||||
json.forEach((String key, dynamic value) => map[key] = new ApiResponse.fromJson(value));
|
||||
json.forEach((String key, dynamic value) => map[key] = ApiResponse.fromJson(value));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -36,13 +36,13 @@ class Category {
|
||||
}
|
||||
|
||||
static List<Category> listFromJson(List<dynamic> json) {
|
||||
return json == null ? new List<Category>() : json.map((value) => new Category.fromJson(value)).toList();
|
||||
return json == null ? List<Category>() : json.map((value) => Category.fromJson(value)).toList();
|
||||
}
|
||||
|
||||
static Map<String, Category> mapFromJson(Map<String, dynamic> json) {
|
||||
var map = new Map<String, Category>();
|
||||
var map = Map<String, Category>();
|
||||
if (json != null && json.isNotEmpty) {
|
||||
json.forEach((String key, dynamic value) => map[key] = new Category.fromJson(value));
|
||||
json.forEach((String key, dynamic value) => map[key] = Category.fromJson(value));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -73,13 +73,13 @@ class Order {
|
||||
}
|
||||
|
||||
static List<Order> listFromJson(List<dynamic> json) {
|
||||
return json == null ? new List<Order>() : json.map((value) => new Order.fromJson(value)).toList();
|
||||
return json == null ? List<Order>() : json.map((value) => Order.fromJson(value)).toList();
|
||||
}
|
||||
|
||||
static Map<String, Order> mapFromJson(Map<String, dynamic> json) {
|
||||
var map = new Map<String, Order>();
|
||||
var map = Map<String, Order>();
|
||||
if (json != null && json.isNotEmpty) {
|
||||
json.forEach((String key, dynamic value) => map[key] = new Order.fromJson(value));
|
||||
json.forEach((String key, dynamic value) => map[key] = Order.fromJson(value));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ class Pet {
|
||||
if (json['category'] == null) {
|
||||
category = null;
|
||||
} else {
|
||||
category = new Category.fromJson(json['category']);
|
||||
category = Category.fromJson(json['category']);
|
||||
}
|
||||
if (json['name'] == null) {
|
||||
name = null;
|
||||
@@ -73,13 +73,13 @@ class Pet {
|
||||
}
|
||||
|
||||
static List<Pet> listFromJson(List<dynamic> json) {
|
||||
return json == null ? new List<Pet>() : json.map((value) => new Pet.fromJson(value)).toList();
|
||||
return json == null ? List<Pet>() : json.map((value) => Pet.fromJson(value)).toList();
|
||||
}
|
||||
|
||||
static Map<String, Pet> mapFromJson(Map<String, dynamic> json) {
|
||||
var map = new Map<String, Pet>();
|
||||
var map = Map<String, Pet>();
|
||||
if (json != null && json.isNotEmpty) {
|
||||
json.forEach((String key, dynamic value) => map[key] = new Pet.fromJson(value));
|
||||
json.forEach((String key, dynamic value) => map[key] = Pet.fromJson(value));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -36,13 +36,13 @@ class Tag {
|
||||
}
|
||||
|
||||
static List<Tag> listFromJson(List<dynamic> json) {
|
||||
return json == null ? new List<Tag>() : json.map((value) => new Tag.fromJson(value)).toList();
|
||||
return json == null ? List<Tag>() : json.map((value) => Tag.fromJson(value)).toList();
|
||||
}
|
||||
|
||||
static Map<String, Tag> mapFromJson(Map<String, dynamic> json) {
|
||||
var map = new Map<String, Tag>();
|
||||
var map = Map<String, Tag>();
|
||||
if (json != null && json.isNotEmpty) {
|
||||
json.forEach((String key, dynamic value) => map[key] = new Tag.fromJson(value));
|
||||
json.forEach((String key, dynamic value) => map[key] = Tag.fromJson(value));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -90,13 +90,13 @@ class User {
|
||||
}
|
||||
|
||||
static List<User> listFromJson(List<dynamic> json) {
|
||||
return json == null ? new List<User>() : json.map((value) => new User.fromJson(value)).toList();
|
||||
return json == null ? List<User>() : json.map((value) => User.fromJson(value)).toList();
|
||||
}
|
||||
|
||||
static Map<String, User> mapFromJson(Map<String, dynamic> json) {
|
||||
var map = new Map<String, User>();
|
||||
var map = Map<String, User>();
|
||||
if (json != null && json.isNotEmpty) {
|
||||
json.forEach((String key, dynamic value) => map[key] = new User.fromJson(value));
|
||||
json.forEach((String key, dynamic value) => map[key] = User.fromJson(value));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user