Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ class {{classname}} {
{{#min}} // range from {{min}} to {{max}}{{/min}}//{{^min}}enum {{name}}Enum { {{#values}} {{.}}, {{/values}} };{{/min}}{
{{/allowableValues}}
{{/vars}}
{{classname}}();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@agilob I'm no expert in Dart but shall we keep the default constructor (no argument) for backward compatibility?

(upcoming 5.0.0 allows breaking changes without fallbacks but it's still worth considering backward compatibility)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, happy to explain this feature. Dart has flexible syntax on method params, default values, and mandatory params.

Method/constructor params can be mandatory (as not named) or named (optional) or named AND mandatory. This change introduces constructors that have named optional parameters. Such parameters have input params inside {} brackets. Since all fields in these classes are public anyway (dart discourages use of setters and getters "just because" like in java), so we have this syntax, of all valid constructors.

Constructors with all optional params are backwards compatible, it's really just programmers' preference
image

This MR introduces optional named params in constructors, while cascade operators is already supported, it's fully backwards compatible.
https://dart.dev/guides/language/language-tour#optional-parameters
https://dart.dev/guides/language/language-tour#cascade-notation-

(upcoming 5.0.0 allows breaking changes without fallbacks but it's still worth considering backward compatibility)

I am myself a guardian of backwards compatibility ;)

This MR 6729 breaks backwards compatibility when creating enums (which now are just string without any validation), so I found it necessary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am myself a guardian of backwards compatibility ;)

👍

Thanks for the explanation. The change looks good to me.

If no further feedback or question, I'll merge it over the weekend.


{{classname}}({
{{#vars}}
this.{{name}},
{{/vars}}
});

@override
String toString() {
Expand Down
11 changes: 6 additions & 5 deletions samples/client/petstore/dart2/petstore/test/pet_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ void main() {
..id = 124321
..name = 'Jose'
];
return Pet()
..id = id
..category = category
..tags = tags
..name = name
return Pet(
id : id,
category: category,
tags: tags,
name: name,
)
..status = status
..photoUrls = ['https://petstore.com/sample/photo1.jpg'];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ class ApiResponse {
String type = null;

String message = null;
ApiResponse();

ApiResponse({
this.code,
this.type,
this.message,
});

@override
String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ class Category {
int id = null;

String name = null;
Category();

Category({
this.id,
this.name,
});

@override
String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ class Order {
//enum statusEnum { placed, approved, delivered, };{

bool complete = false;
Order();

Order({
this.id,
this.petId,
this.quantity,
this.shipDate,
this.status,
this.complete,
});

@override
String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ class Pet {
/* pet status in the store */
String status = null;
//enum statusEnum { available, pending, sold, };{
Pet();

Pet({
this.id,
this.category,
this.name,
this.photoUrls,
this.tags,
this.status,
});

@override
String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ class Tag {
int id = null;

String name = null;
Tag();

Tag({
this.id,
this.name,
});

@override
String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@ class User {
String phone = null;
/* User Status */
int userStatus = null;
User();

User({
this.id,
this.username,
this.firstName,
this.lastName,
this.email,
this.password,
this.phone,
this.userStatus,
});

@override
String toString() {
Expand Down