forked from loafle/openapi-generator-original
[Dart] - Rework Dart client generator to be flutter-compatible (#7418)
* copy mustache templates from dart generator * Start with generator by copying the DartClientCodegen for now * at least we know this is not for a browser.. * First working version for a simple swagger configuration * remove browserClient parameter, since it doesn't make sense for flutter * Take care of complex types to support object hierarchies * add null safety * add small test for options * add flutter-petstore scripts * generate flutter petstore output * Add new flutter test project * move generated client to make it usable * use generated swagger petstore plugin * add support for lists of objects * add DateTime support * fix listFromJson implementation * fix NPEs in DateTime operations + place order in sample * Small readme changes * bugfixes * Use flutter-compatible implementation as default dart implementation * fix generated samples * Make lists serializable, now all dart test cases are working again * better list implementation * use StringBuffer * removed FlutterClientCodegen * fix browser client * fix dependencies * swagger-browser-client for browserClient testcases * fix scripts * removed flutter scripts * add map support and simplify code via using .toJson contract * remove unneeded devDependencies * Regenerated samples * fix call to mapFromJson, it is not a constructor * remove pointless string serialization * regenerated dart samples
This commit is contained in:
committed by
William Cheng
parent
a3c97753fe
commit
a5e26a44ff
@@ -1,24 +1,54 @@
|
||||
part of swagger.api;
|
||||
|
||||
@Entity()
|
||||
class ApiResponse {
|
||||
|
||||
@Property(name: 'code')
|
||||
int code = null;
|
||||
|
||||
|
||||
@Property(name: 'type')
|
||||
String type = null;
|
||||
|
||||
|
||||
@Property(name: 'message')
|
||||
String message = null;
|
||||
|
||||
ApiResponse();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
String toString() {
|
||||
return 'ApiResponse[code=$code, type=$type, message=$message, ]';
|
||||
}
|
||||
|
||||
ApiResponse.fromJson(Map<String, dynamic> json) {
|
||||
if (json == null) return;
|
||||
code =
|
||||
json['code'];
|
||||
type =
|
||||
json['type'];
|
||||
message =
|
||||
json['message'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'code': code,
|
||||
'type': type,
|
||||
'message': message
|
||||
};
|
||||
}
|
||||
|
||||
static List<ApiResponse> listFromJson(List<Map<String, dynamic>> json) {
|
||||
var list = new List<ApiResponse>();
|
||||
if (json != null && json.length > 0) {
|
||||
json.forEach((Map<String, dynamic> value) => list.add(new ApiResponse.fromJson(value)));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
static Map<String, ApiResponse> mapFromJson(Map<String, Map<String, dynamic>> json) {
|
||||
var map = new Map<String, ApiResponse>();
|
||||
if (json != null && json.length > 0) {
|
||||
json.forEach((String key, Map<String, dynamic> value) => map[key] = new ApiResponse.fromJson(value));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,48 @@
|
||||
part of swagger.api;
|
||||
|
||||
@Entity()
|
||||
class Category {
|
||||
|
||||
@Property(name: 'id')
|
||||
int id = null;
|
||||
|
||||
|
||||
@Property(name: 'name')
|
||||
String name = null;
|
||||
|
||||
Category();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
String toString() {
|
||||
return 'Category[id=$id, name=$name, ]';
|
||||
}
|
||||
|
||||
Category.fromJson(Map<String, dynamic> json) {
|
||||
if (json == null) return;
|
||||
id =
|
||||
json['id'];
|
||||
name =
|
||||
json['name'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'name': name
|
||||
};
|
||||
}
|
||||
|
||||
static List<Category> listFromJson(List<Map<String, dynamic>> json) {
|
||||
var list = new List<Category>();
|
||||
if (json != null && json.length > 0) {
|
||||
json.forEach((Map<String, dynamic> value) => list.add(new Category.fromJson(value)));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
static Map<String, Category> mapFromJson(Map<String, Map<String, dynamic>> json) {
|
||||
var map = new Map<String, Category>();
|
||||
if (json != null && json.length > 0) {
|
||||
json.forEach((String key, Map<String, dynamic> value) => map[key] = new Category.fromJson(value));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,36 +1,71 @@
|
||||
part of swagger.api;
|
||||
|
||||
@Entity()
|
||||
class Order {
|
||||
|
||||
@Property(name: 'id')
|
||||
int id = null;
|
||||
|
||||
|
||||
@Property(name: 'petId')
|
||||
int petId = null;
|
||||
|
||||
|
||||
@Property(name: 'quantity')
|
||||
int quantity = null;
|
||||
|
||||
|
||||
@Property(name: 'shipDate')
|
||||
DateTime shipDate = null;
|
||||
|
||||
/* Order Status */
|
||||
@Property(name: 'status')
|
||||
String status = null;
|
||||
//enum statusEnum { placed, approved, delivered, };
|
||||
|
||||
@Property(name: 'complete')
|
||||
bool complete = null;
|
||||
|
||||
Order();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
String toString() {
|
||||
return 'Order[id=$id, petId=$petId, quantity=$quantity, shipDate=$shipDate, status=$status, complete=$complete, ]';
|
||||
}
|
||||
|
||||
Order.fromJson(Map<String, dynamic> json) {
|
||||
if (json == null) return;
|
||||
id =
|
||||
json['id'];
|
||||
petId =
|
||||
json['petId'];
|
||||
quantity =
|
||||
json['quantity'];
|
||||
shipDate = json['shipDate'] == null ? null : DateTime.parse(json['shipDate']);
|
||||
status =
|
||||
json['status'];
|
||||
complete =
|
||||
json['complete'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'petId': petId,
|
||||
'quantity': quantity,
|
||||
'shipDate': shipDate == null ? '' : shipDate.toUtc().toIso8601String(),
|
||||
'status': status,
|
||||
'complete': complete
|
||||
};
|
||||
}
|
||||
|
||||
static List<Order> listFromJson(List<Map<String, dynamic>> json) {
|
||||
var list = new List<Order>();
|
||||
if (json != null && json.length > 0) {
|
||||
json.forEach((Map<String, dynamic> value) => list.add(new Order.fromJson(value)));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
static Map<String, Order> mapFromJson(Map<String, Map<String, dynamic>> json) {
|
||||
var map = new Map<String, Order>();
|
||||
if (json != null && json.length > 0) {
|
||||
json.forEach((String key, Map<String, dynamic> value) => map[key] = new Order.fromJson(value));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,36 +1,76 @@
|
||||
part of swagger.api;
|
||||
|
||||
@Entity()
|
||||
class Pet {
|
||||
|
||||
@Property(name: 'id')
|
||||
int id = null;
|
||||
|
||||
|
||||
@Property(name: 'category')
|
||||
Category category = null;
|
||||
|
||||
|
||||
@Property(name: 'name')
|
||||
String name = null;
|
||||
|
||||
|
||||
@Property(name: 'photoUrls')
|
||||
List<String> photoUrls = [];
|
||||
|
||||
|
||||
@Property(name: 'tags')
|
||||
List<Tag> tags = [];
|
||||
|
||||
/* pet status in the store */
|
||||
@Property(name: 'status')
|
||||
String status = null;
|
||||
//enum statusEnum { available, pending, sold, };
|
||||
Pet();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
String toString() {
|
||||
return 'Pet[id=$id, category=$category, name=$name, photoUrls=$photoUrls, tags=$tags, status=$status, ]';
|
||||
}
|
||||
|
||||
Pet.fromJson(Map<String, dynamic> json) {
|
||||
if (json == null) return;
|
||||
id =
|
||||
json['id'];
|
||||
category =
|
||||
|
||||
|
||||
new Category.fromJson(json['category'])
|
||||
;
|
||||
name =
|
||||
json['name'];
|
||||
photoUrls =
|
||||
json['photoUrls'];
|
||||
tags =
|
||||
Tag.listFromJson(json['tags'])
|
||||
;
|
||||
status =
|
||||
json['status'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'category': category,
|
||||
'name': name,
|
||||
'photoUrls': photoUrls,
|
||||
'tags': tags,
|
||||
'status': status
|
||||
};
|
||||
}
|
||||
|
||||
static List<Pet> listFromJson(List<Map<String, dynamic>> json) {
|
||||
var list = new List<Pet>();
|
||||
if (json != null && json.length > 0) {
|
||||
json.forEach((Map<String, dynamic> value) => list.add(new Pet.fromJson(value)));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
static Map<String, Pet> mapFromJson(Map<String, Map<String, dynamic>> json) {
|
||||
var map = new Map<String, Pet>();
|
||||
if (json != null && json.length > 0) {
|
||||
json.forEach((String key, Map<String, dynamic> value) => map[key] = new Pet.fromJson(value));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,48 @@
|
||||
part of swagger.api;
|
||||
|
||||
@Entity()
|
||||
class Tag {
|
||||
|
||||
@Property(name: 'id')
|
||||
int id = null;
|
||||
|
||||
|
||||
@Property(name: 'name')
|
||||
String name = null;
|
||||
|
||||
Tag();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
String toString() {
|
||||
return 'Tag[id=$id, name=$name, ]';
|
||||
}
|
||||
|
||||
Tag.fromJson(Map<String, dynamic> json) {
|
||||
if (json == null) return;
|
||||
id =
|
||||
json['id'];
|
||||
name =
|
||||
json['name'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'name': name
|
||||
};
|
||||
}
|
||||
|
||||
static List<Tag> listFromJson(List<Map<String, dynamic>> json) {
|
||||
var list = new List<Tag>();
|
||||
if (json != null && json.length > 0) {
|
||||
json.forEach((Map<String, dynamic> value) => list.add(new Tag.fromJson(value)));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
static Map<String, Tag> mapFromJson(Map<String, Map<String, dynamic>> json) {
|
||||
var map = new Map<String, Tag>();
|
||||
if (json != null && json.length > 0) {
|
||||
json.forEach((String key, Map<String, dynamic> value) => map[key] = new Tag.fromJson(value));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,44 +1,84 @@
|
||||
part of swagger.api;
|
||||
|
||||
@Entity()
|
||||
class User {
|
||||
|
||||
@Property(name: 'id')
|
||||
int id = null;
|
||||
|
||||
|
||||
@Property(name: 'username')
|
||||
String username = null;
|
||||
|
||||
|
||||
@Property(name: 'firstName')
|
||||
String firstName = null;
|
||||
|
||||
|
||||
@Property(name: 'lastName')
|
||||
String lastName = null;
|
||||
|
||||
|
||||
@Property(name: 'email')
|
||||
String email = null;
|
||||
|
||||
|
||||
@Property(name: 'password')
|
||||
String password = null;
|
||||
|
||||
|
||||
@Property(name: 'phone')
|
||||
String phone = null;
|
||||
|
||||
/* User Status */
|
||||
@Property(name: 'userStatus')
|
||||
int userStatus = null;
|
||||
|
||||
User();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
String toString() {
|
||||
return 'User[id=$id, username=$username, firstName=$firstName, lastName=$lastName, email=$email, password=$password, phone=$phone, userStatus=$userStatus, ]';
|
||||
}
|
||||
|
||||
User.fromJson(Map<String, dynamic> json) {
|
||||
if (json == null) return;
|
||||
id =
|
||||
json['id'];
|
||||
username =
|
||||
json['username'];
|
||||
firstName =
|
||||
json['firstName'];
|
||||
lastName =
|
||||
json['lastName'];
|
||||
email =
|
||||
json['email'];
|
||||
password =
|
||||
json['password'];
|
||||
phone =
|
||||
json['phone'];
|
||||
userStatus =
|
||||
json['userStatus'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'username': username,
|
||||
'firstName': firstName,
|
||||
'lastName': lastName,
|
||||
'email': email,
|
||||
'password': password,
|
||||
'phone': phone,
|
||||
'userStatus': userStatus
|
||||
};
|
||||
}
|
||||
|
||||
static List<User> listFromJson(List<Map<String, dynamic>> json) {
|
||||
var list = new List<User>();
|
||||
if (json != null && json.length > 0) {
|
||||
json.forEach((Map<String, dynamic> value) => list.add(new User.fromJson(value)));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
static Map<String, User> mapFromJson(Map<String, Map<String, dynamic>> json) {
|
||||
var map = new Map<String, User>();
|
||||
if (json != null && json.length > 0) {
|
||||
json.forEach((String key, Map<String, dynamic> value) => map[key] = new User.fromJson(value));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user