Skip to content

Commit 1798fea

Browse files
authored
Dart - generate constructor with named params (#6751)
* Dart - generate constructor with names params * Test if constructor exists
1 parent 1f27700 commit 1798fea

8 files changed

Lines changed: 57 additions & 12 deletions

File tree

modules/openapi-generator/src/main/resources/dart2/class.mustache

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ class {{classname}} {
66
{{#min}} // range from {{min}} to {{max}}{{/min}}//{{^min}}enum {{name}}Enum { {{#values}} {{.}}, {{/values}} };{{/min}}{
77
{{/allowableValues}}
88
{{/vars}}
9-
{{classname}}();
9+
10+
{{classname}}({
11+
{{#vars}}
12+
this.{{name}},
13+
{{/vars}}
14+
});
1015

1116
@override
1217
String toString() {

samples/client/petstore/dart2/petstore/test/pet_test.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ void main() {
2525
..id = 124321
2626
..name = 'Jose'
2727
];
28-
return Pet()
29-
..id = id
30-
..category = category
31-
..tags = tags
32-
..name = name
28+
return Pet(
29+
id : id,
30+
category: category,
31+
tags: tags,
32+
name: name,
33+
)
3334
..status = status
3435
..photoUrls = ['https://petstore.com/sample/photo1.jpg'];
3536
}

samples/client/petstore/dart2/petstore_client_lib/lib/model/api_response.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ class ApiResponse {
77
String type = null;
88

99
String message = null;
10-
ApiResponse();
10+
11+
ApiResponse({
12+
this.code,
13+
this.type,
14+
this.message,
15+
});
1116

1217
@override
1318
String toString() {

samples/client/petstore/dart2/petstore_client_lib/lib/model/category.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ class Category {
55
int id = null;
66

77
String name = null;
8-
Category();
8+
9+
Category({
10+
this.id,
11+
this.name,
12+
});
913

1014
@override
1115
String toString() {

samples/client/petstore/dart2/petstore_client_lib/lib/model/order.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,15 @@ class Order {
1414
//enum statusEnum { placed, approved, delivered, };{
1515

1616
bool complete = false;
17-
Order();
17+
18+
Order({
19+
this.id,
20+
this.petId,
21+
this.quantity,
22+
this.shipDate,
23+
this.status,
24+
this.complete,
25+
});
1826

1927
@override
2028
String toString() {

samples/client/petstore/dart2/petstore_client_lib/lib/model/pet.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,15 @@ class Pet {
1414
/* pet status in the store */
1515
String status = null;
1616
//enum statusEnum { available, pending, sold, };{
17-
Pet();
17+
18+
Pet({
19+
this.id,
20+
this.category,
21+
this.name,
22+
this.photoUrls,
23+
this.tags,
24+
this.status,
25+
});
1826

1927
@override
2028
String toString() {

samples/client/petstore/dart2/petstore_client_lib/lib/model/tag.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ class Tag {
55
int id = null;
66

77
String name = null;
8-
Tag();
8+
9+
Tag({
10+
this.id,
11+
this.name,
12+
});
913

1014
@override
1115
String toString() {

samples/client/petstore/dart2/petstore_client_lib/lib/model/user.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,17 @@ class User {
1717
String phone = null;
1818
/* User Status */
1919
int userStatus = null;
20-
User();
20+
21+
User({
22+
this.id,
23+
this.username,
24+
this.firstName,
25+
this.lastName,
26+
this.email,
27+
this.password,
28+
this.phone,
29+
this.userStatus,
30+
});
2131

2232
@override
2333
String toString() {

0 commit comments

Comments
 (0)