Skip to content

Commit 9644265

Browse files
committed
[dart-dio] Fix inheritance with json_serializable using super parameters - Add 'extends' clause to child classes when parent exists - Use Dart 2.17+ super parameters (super.property) in constructors - Separate child properties (this.name) from parent properties (super.name) - Set parentVars in postProcessAllModels for json_serializable - Only declare child properties in class body (not parent properties) - Use allVars for equals/hashCode to include all properties Fixes #22547
1 parent 2b63fc5 commit 9644265

51 files changed

Lines changed: 50 additions & 5 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioClientCodegen.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ public class DartDioClientCodegen extends AbstractDartCodegen {
8787

8888
public DartDioClientCodegen() {
8989
super();
90-
91-
// This stops the DefaultCodegen from copying parent properties into the child's 'vars'.
92-
this.supportsInheritance = true;
9390

9491
modifyFeatureSet(features -> features
9592
.includeClientModificationFeatures(

modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/json_serializable/dart_constructor.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
{{^required}}{{#useOptional}}this.{{{name}}}{{#defaultValue}} = const Optional.present({{#isEnum}}{{^isContainer}}const {{{enumName}}}._({{/isContainer}}{{/isEnum}}{{{defaultValue}}}{{#isEnum}}{{^isContainer}}){{/isContainer}}{{/isEnum}}){{/defaultValue}}{{^defaultValue}} = const Optional.absent(){{/defaultValue}},{{/useOptional}}{{/required}}{{^required}}{{^useOptional}} this.{{{name}}}{{#defaultValue}} = {{#isEnum}}{{^isContainer}}const {{{enumName}}}._({{/isContainer}}{{/isEnum}}{{{defaultValue}}}{{#isEnum}}{{^isContainer}}){{/isContainer}}{{/isEnum}}{{/defaultValue}},{{/useOptional}}{{/required}}{{#required}}{{^defaultValue}}required {{/defaultValue}}{{/required}}{{#required}} this.{{{name}}}{{#defaultValue}} = {{#isEnum}}{{^isContainer}}const {{{enumName}}}._({{/isContainer}}{{/isEnum}}{{{defaultValue}}}{{#isEnum}}{{^isContainer}}){{/isContainer}}{{/isEnum}}{{/defaultValue}},{{/required}}
99
{{/vars}}
1010
{{#parentVars}}
11-
{{#required}}{{^defaultValue}}required {{/defaultValue}}{{/required}} super.{{{name}}}{{#defaultValue}} = {{#isEnum}}{{^isContainer}}const {{{enumName}}}._({{/isContainer}}{{/isEnum}}{{{defaultValue}}}{{#isEnum}}{{^isContainer}}){{/isContainer}}{{/isEnum}}{{/defaultValue}},
11+
{{^required}}{{#useOptional}}super.{{{name}}}{{#defaultValue}} = const Optional.present({{#isEnum}}{{^isContainer}}const {{{enumName}}}._({{/isContainer}}{{/isEnum}}{{{defaultValue}}}{{#isEnum}}{{^isContainer}}){{/isContainer}}{{/isEnum}}){{/defaultValue}}{{^defaultValue}} = const Optional.absent(){{/defaultValue}},{{/useOptional}}{{/required}}{{^required}}{{^useOptional}} super.{{{name}}}{{#defaultValue}} = {{#isEnum}}{{^isContainer}}const {{{enumName}}}._({{/isContainer}}{{/isEnum}}{{{defaultValue}}}{{#isEnum}}{{^isContainer}}){{/isContainer}}{{/isEnum}}{{/defaultValue}},{{/useOptional}}{{/required}}{{#required}}{{^defaultValue}}required {{/defaultValue}}{{/required}}{{#required}} super.{{{name}}}{{#defaultValue}} = {{#isEnum}}{{^isContainer}}const {{{enumName}}}._({{/isContainer}}{{/isEnum}}{{{defaultValue}}}{{#isEnum}}{{^isContainer}}){{/isContainer}}{{/isEnum}}{{/defaultValue}},{{/required}}
1212
{{/parentVars}}
1313
});

samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/additional_properties_class.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class AdditionalPropertiesClass {
2121
AdditionalPropertiesClass({
2222
this.mapProperty,
2323
this.mapOfMapProperty,
24-
2524
this.mapOfArrayInteger,
2625
});
2726

@@ -65,6 +64,7 @@ class AdditionalPropertiesClass {
6564

6665
@override
6766
bool operator ==(Object other) => identical(this, other) || other is AdditionalPropertiesClass &&
67+
runtimeType == other.runtimeType &&
6868
other.mapProperty == mapProperty &&
6969
other.mapOfMapProperty == mapOfMapProperty &&
7070
other.mapOfArrayInteger == mapOfArrayInteger;

samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/all_of_with_single_ref.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class AllOfWithSingleRef {
5353

5454
@override
5555
bool operator ==(Object other) => identical(this, other) || other is AllOfWithSingleRef &&
56+
runtimeType == other.runtimeType &&
5657
other.username == username &&
5758
other.singleRefType == singleRefType;
5859

samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/animal.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class Animal {
5151

5252
@override
5353
bool operator ==(Object other) => identical(this, other) || other is Animal &&
54+
runtimeType == other.runtimeType &&
5455
other.className == className &&
5556
other.color == color;
5657

samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/api_response.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class ApiResponse {
6464

6565
@override
6666
bool operator ==(Object other) => identical(this, other) || other is ApiResponse &&
67+
runtimeType == other.runtimeType &&
6768
other.code == code &&
6869
other.type == type &&
6970
other.message == message;

samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/array_of_array_of_number_only.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class ArrayOfArrayOfNumberOnly {
3838

3939
@override
4040
bool operator ==(Object other) => identical(this, other) || other is ArrayOfArrayOfNumberOnly &&
41+
runtimeType == other.runtimeType &&
4142
other.arrayArrayNumber == arrayArrayNumber;
4243

4344
@override

samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/array_of_number_only.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class ArrayOfNumberOnly {
3838

3939
@override
4040
bool operator ==(Object other) => identical(this, other) || other is ArrayOfNumberOnly &&
41+
runtimeType == other.runtimeType &&
4142
other.arrayNumber == arrayNumber;
4243

4344
@override

samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/array_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class ArrayTest {
6565

6666
@override
6767
bool operator ==(Object other) => identical(this, other) || other is ArrayTest &&
68+
runtimeType == other.runtimeType &&
6869
other.arrayOfString == arrayOfString &&
6970
other.arrayArrayOfInteger == arrayArrayOfInteger &&
7071
other.arrayArrayOfModel == arrayArrayOfModel;

samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/capitalization.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ class Capitalization {
104104

105105
@override
106106
bool operator ==(Object other) => identical(this, other) || other is Capitalization &&
107+
runtimeType == other.runtimeType &&
107108
other.smallCamel == smallCamel &&
108109
other.capitalCamel == capitalCamel &&
109110
other.smallSnake == smallSnake &&

0 commit comments

Comments
 (0)