Skip to content
Open
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 @@ -606,6 +606,52 @@ protected CodegenDiscriminator createDiscriminator(String schemaName, Schema sch
@Override
public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs) {
objs = super.postProcessAllModels(objs);

// For json_serializable, properly set up parent variables for inheritance
if (SERIALIZATION_LIBRARY_JSON_SERIALIZABLE.equals(library)) {
// Build a map of all models for quick lookup
Map<String, CodegenModel> allModelsMap = new HashMap<>();
for (ModelsMap modelsEntries : objs.values()) {
for (ModelMap modelsMap : modelsEntries.getModels()) {
allModelsMap.put(modelsMap.getModel().getClassname(), modelsMap.getModel());
}
}

// Process models with inheritance
for (ModelsMap modelsEntries : objs.values()) {
for (ModelMap mo : modelsEntries.getModels()) {
CodegenModel cm = mo.getModel();

if (cm.getParent() != null && !cm.getParent().isEmpty()) {
LOGGER.debug("Processing inheritance for model: {} (extends: {})", cm.getClassname(), cm.getParent());

CodegenModel parentModel = allModelsMap.get(cm.getParent());

if (parentModel != null && parentModel.getVars() != null && !parentModel.getVars().isEmpty()) {
// Set parent variables
cm.setParentVars(parentModel.getVars());

// Remove parent properties from child's vars to avoid duplication
Set<String> parentVarNames = cm.getParentVars().stream()
.map(CodegenProperty::getName)
.collect(Collectors.toSet());

cm.setVars(cm.getVars().stream()
.filter(p -> !parentVarNames.contains(p.getName()))
.collect(Collectors.toList())
);

LOGGER.debug("Inheritance setup complete for {}: {} parent properties moved to parentVars",
cm.getClassname(), parentModel.getVars().size());
} else {
LOGGER.warn("Parent model '{}' not found or has no properties for child model '{}'",
cm.getParent(), cm.getClassname());
}
}
}
}
}

if (SERIALIZATION_LIBRARY_BUILT_VALUE.equals(library)) {
adaptToDartInheritance(objs);
syncRootTypesWithInnerVars(objs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ part '{{classFilename}}.g.dart';
disallowUnrecognizedKeys: false,
explicitToJson: true,
)
class {{{classname}}} {
class {{{classname}}}{{#parent}} extends {{{parent}}}{{/parent}} {
{{>serialization/json_serializable/dart_constructor}}


Expand Down Expand Up @@ -89,14 +89,14 @@ class {{{classname}}} {
runtimeType == other.runtimeType &&
equals(
[
{{#vars}}
{{#allVars}}
{{{name}}},
{{/vars}}
{{/allVars}}
],
[
{{#vars}}
{{#allVars}}
other.{{{name}}},
{{/vars}}
{{/allVars}}
]
);
}
Expand All @@ -105,25 +105,26 @@ class {{{classname}}} {
{{^useEquatable}}
@override
bool operator ==(Object other) => identical(this, other) || other is {{{classname}}} &&
{{#vars}}
runtimeType == other.runtimeType &&
{{#allVars}}
other.{{{name}}} == {{{name}}}{{^-last}} &&{{/-last}}{{#-last}};{{/-last}}
{{/vars}}
{{/allVars}}
{{/useEquatable}}

{{#useEquatable}}
@override
int get hashCode => runtimeType.hashCode ^ mapPropsToHashCode([
{{#vars}}
{{#allVars}}
{{{name}}},
{{/vars}}
{{/allVars}}
],);
{{/useEquatable}}
{{^useEquatable}}
@override
int get hashCode =>
{{#vars}}
{{#allVars}}
{{#isNullable}}({{{name}}} == null ? 0 : {{{name}}}.hashCode){{/isNullable}}{{^isNullable}}{{{name}}}.hashCode{{/isNullable}}{{^-last}} +{{/-last}}{{#-last}};{{/-last}}
{{/vars}}
{{/allVars}}
{{/useEquatable}}

factory {{{classname}}}.fromJson(Map<String, dynamic> json) => _${{{classname}}}FromJson(json);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/// Returns a new [{{{classname}}}] instance.
/// Returns a new [{{{classname}}}] instance.
{{{classname}}}({
{{#vars}}

{{#vars}}
{{!
A field is required in Dart when it is
required && !defaultValue in OAS
}}
{{^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}}
{{/vars}}
{{#parentVars}}
{{^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}}
{{/parentVars}}
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import 'package:openapi/api.dart';
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**className** | **String** | |
**color** | **String** | | [optional] [default to 'red']
**declawed** | **bool** | | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import 'package:openapi/api.dart';
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**type** | **String** | | [optional]
**nullableProperty** | **String** | | [optional]
**otherProperty** | **String** | | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import 'package:openapi/api.dart';
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**className** | **String** | |
**color** | **String** | | [optional] [default to 'red']
**breed** | **String** | | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ part 'additional_properties_class.g.dart';
explicitToJson: true,
)
class AdditionalPropertiesClass {
/// Returns a new [AdditionalPropertiesClass] instance.
/// Returns a new [AdditionalPropertiesClass] instance.
AdditionalPropertiesClass({

this.mapProperty,

this.mapOfMapProperty,

this.mapOfArrayInteger,
});

Expand Down Expand Up @@ -67,6 +64,7 @@ class AdditionalPropertiesClass {

@override
bool operator ==(Object other) => identical(this, other) || other is AdditionalPropertiesClass &&
runtimeType == other.runtimeType &&
other.mapProperty == mapProperty &&
other.mapOfMapProperty == mapOfMapProperty &&
other.mapOfArrayInteger == mapOfArrayInteger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ part 'all_of_with_single_ref.g.dart';
explicitToJson: true,
)
class AllOfWithSingleRef {
/// Returns a new [AllOfWithSingleRef] instance.
/// Returns a new [AllOfWithSingleRef] instance.
AllOfWithSingleRef({

this.username,

this.singleRefType,
});

Expand Down Expand Up @@ -55,6 +53,7 @@ class AllOfWithSingleRef {

@override
bool operator ==(Object other) => identical(this, other) || other is AllOfWithSingleRef &&
runtimeType == other.runtimeType &&
other.username == username &&
other.singleRefType == singleRefType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ part 'animal.g.dart';
explicitToJson: true,
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
)
class Animal {
/// Returns a new [Animal] instance.
/// Returns a new [Animal] instance.
Animal({

required this.className,

this.color = 'red',
});

Expand Down Expand Up @@ -53,6 +51,7 @@ class Animal {

@override
bool operator ==(Object other) => identical(this, other) || other is Animal &&
runtimeType == other.runtimeType &&
other.className == className &&
other.color == color;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ part 'api_response.g.dart';
explicitToJson: true,
)
class ApiResponse {
/// Returns a new [ApiResponse] instance.
/// Returns a new [ApiResponse] instance.
ApiResponse({

this.code,

this.type,

this.message,
});

Expand Down Expand Up @@ -67,6 +64,7 @@ class ApiResponse {

@override
bool operator ==(Object other) => identical(this, other) || other is ApiResponse &&
runtimeType == other.runtimeType &&
other.code == code &&
other.type == type &&
other.message == message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ part 'array_of_array_of_number_only.g.dart';
explicitToJson: true,
)
class ArrayOfArrayOfNumberOnly {
/// Returns a new [ArrayOfArrayOfNumberOnly] instance.
/// Returns a new [ArrayOfArrayOfNumberOnly] instance.
ArrayOfArrayOfNumberOnly({

this.arrayArrayNumber,
});

Expand All @@ -39,6 +38,7 @@ class ArrayOfArrayOfNumberOnly {

@override
bool operator ==(Object other) => identical(this, other) || other is ArrayOfArrayOfNumberOnly &&
runtimeType == other.runtimeType &&
other.arrayArrayNumber == arrayArrayNumber;

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ part 'array_of_number_only.g.dart';
explicitToJson: true,
)
class ArrayOfNumberOnly {
/// Returns a new [ArrayOfNumberOnly] instance.
/// Returns a new [ArrayOfNumberOnly] instance.
ArrayOfNumberOnly({

this.arrayNumber,
});

Expand All @@ -39,6 +38,7 @@ class ArrayOfNumberOnly {

@override
bool operator ==(Object other) => identical(this, other) || other is ArrayOfNumberOnly &&
runtimeType == other.runtimeType &&
other.arrayNumber == arrayNumber;

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,10 @@ part 'array_test.g.dart';
explicitToJson: true,
)
class ArrayTest {
/// Returns a new [ArrayTest] instance.
/// Returns a new [ArrayTest] instance.
ArrayTest({

this.arrayOfString,

this.arrayArrayOfInteger,

this.arrayArrayOfModel,
});

Expand Down Expand Up @@ -68,6 +65,7 @@ class ArrayTest {

@override
bool operator ==(Object other) => identical(this, other) || other is ArrayTest &&
runtimeType == other.runtimeType &&
other.arrayOfString == arrayOfString &&
other.arrayArrayOfInteger == arrayArrayOfInteger &&
other.arrayArrayOfModel == arrayArrayOfModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,13 @@ part 'capitalization.g.dart';
explicitToJson: true,
)
class Capitalization {
/// Returns a new [Capitalization] instance.
/// Returns a new [Capitalization] instance.
Capitalization({

this.smallCamel,

this.capitalCamel,

this.smallSnake,

this.capitalSnake,

this.sCAETHFlowPoints,

this.ATT_NAME,
});

Expand Down Expand Up @@ -110,6 +104,7 @@ class Capitalization {

@override
bool operator ==(Object other) => identical(this, other) || other is Capitalization &&
runtimeType == other.runtimeType &&
other.smallCamel == smallCamel &&
other.capitalCamel == capitalCamel &&
other.smallSnake == smallSnake &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,14 @@ part 'cat.g.dart';
disallowUnrecognizedKeys: false,
explicitToJson: true,
)
class Cat {
/// Returns a new [Cat] instance.
class Cat extends Animal {
/// Returns a new [Cat] instance.
Cat({

required this.className,

this.color = 'red',

this.declawed,
required super.className,
super.color = 'red',
});

@JsonKey(

name: r'className',
required: true,
includeIfNull: false,
)


final String className;



@JsonKey(
defaultValue: 'red',
name: r'color',
required: false,
includeIfNull: false,
)


final String? color;



@JsonKey(

name: r'declawed',
Expand All @@ -70,6 +43,7 @@ class Cat {

@override
bool operator ==(Object other) => identical(this, other) || other is Cat &&
runtimeType == other.runtimeType &&
other.className == className &&
other.color == color &&
other.declawed == declawed;
Expand Down
Loading