Skip to content

Commit

Permalink
Development (#677)
Browse files Browse the repository at this point in the history
* Fixed some issues

* formatted code

* updated SDK

* Updated SDK and version

* Fixed generation of lists of classes

* Fixed generation $Items classes

* Updated pubspec and changelog

* Fixed #524

* Fixed #598 Generation of query enum parameters

* Fixed conflicts

* Fixed some issues in swaggers

* Updated changelog and pubspec

* Fix #583, #637, #619 and update readme (#638)

* fix #583 and update readme

* fix #637

* fix #619

* Fixed generation of some fields

* Removed test

* Fixed classes named List

* Fixed generation of query parameters with ref default type

* Fixed generation of DateTime parameters

* Fixed generation of responses in some cases

* Some fixes

* Updated changelog and pubspec

* Implemented not nullable fields

* Fixed tests

* fixed generation of some swaggers

* Added ability to return String values

* Returned main.dart content

* Updated pubspec and changelog

* Fixed generation of required and not required fields

* Added check for object ref in body

* Fixed some things

* Fixed tests

* Fixed tests

* Fixed some things

* Updated changelog and pubspec

* Removed not needed lines in tests

* Fixed generation of nullable responses

* Added generation of DateTime

* Updated pubspec and changelog

* Fixed tests

* Fixed #669 Generation models from content schema allof

* Fixed #665 generation putIfAbsent for response from content schema

* Fixed generation of nullable and required properties

* Fixed tests

* Fixed some stuff related to nullable properties

* Updated changelog and pubspec

* Formatted code

* Formatted code

* Fixed tests

---------

Co-authored-by: Uladzimir Paliukhovich <uladzimir_paliukhovich@epam.com>
Co-authored-by: Romain <romain@rb-dev.fr>
  • Loading branch information
3 people authored Nov 10, 2023
1 parent 2a88a0c commit 2c25149
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 23 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 2.12.2

* Fixed generation of `nullable` and `required` fields ([#650](https://github.com/epam-cross-platform-lab/swagger-dart-code-generator/issues/650))
* Fixed generation of `putIfAbsent` for some models ([#665](https://github.com/epam-cross-platform-lab/swagger-dart-code-generator/issues/665))
* Fixed generation of some border-cased models ([#669](https://github.com/epam-cross-platform-lab/swagger-dart-code-generator/issues/669))

# 2.12.1
* Fixed return type nullability ([#670](https://github.com/epam-cross-platform-lab/swagger-dart-code-generator/issues/670))
* Fixed generation of DateTime return types
Expand Down
23 changes: 11 additions & 12 deletions lib/src/code_generators/swagger_models_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -585,12 +585,9 @@ static $returnType $fromJsonFunction($valueType? value) => $enumNameCamelCase$fr
String propertyKey,
SwaggerSchema prop,
) {
if (requiredProperties.contains(propertyKey)) {
return false;
}

return options.nullableModels.contains(className) ||
prop.isNullable == true;
return prop.isNullable == true ||
options.nullableModels.contains(className) ||
!requiredProperties.contains(propertyKey);
}

String nullable(
Expand Down Expand Up @@ -717,14 +714,15 @@ static $returnType $fromJsonFunction($valueType? value) => $enumNameCamelCase$fr
typeName: typeName,
defaultValue: prop.defaultValue,
isList: false,
className: className,
isNullable: isNullable(className, requiredProperties, propertyKey, prop),
);

final jsonKeyContent =
"@JsonKey(name: '${_validatePropertyKey(propertyKey)}'$includeIfNullString${unknownEnumValue.jsonKey})\n";

if ((prop.isNullable == true ||
options.nullableModels.contains(className)) &&
if (prop.isNullable == true ||
options.nullableModels.contains(className) ||
!requiredProperties.contains(propertyKey)) {
typeName = typeName.makeNullable();
}
Expand Down Expand Up @@ -772,7 +770,7 @@ static $returnType $fromJsonFunction($valueType? value) => $enumNameCamelCase$fr

final isPropertyNullable = options.nullableModels.contains(className) ||
refSchema?.isNullable == true ||
isNullable(className, requiredProperties, propertyKey, prop);
!requiredProperties.contains(propertyName);

final unknownEnumValue = generateEnumValue(
allEnumNames: allEnumNames,
Expand Down Expand Up @@ -995,8 +993,8 @@ static $returnType $fromJsonFunction($valueType? value) => $enumNameCamelCase$fr

var listPropertyName = 'List<$typeName>';

if ((prop.isNullable == true ||
options.nullableModels.contains(className)) &&
if (prop.isNullable == true ||
options.nullableModels.contains(className) ||
!requiredProperties.contains(propertyKey)) {
listPropertyName = listPropertyName.makeNullable();
}
Expand Down Expand Up @@ -1330,7 +1328,8 @@ static $returnType $fromJsonFunction($valueType? value) => $enumNameCamelCase$fr
propertyNames.add(fieldName);

final isNullableProperty = options.nullableModels.contains(className) ||
value.isNullable == true || !requiredProperties.contains(key);
value.isNullable == true ||
!requiredProperties.contains(key);

final isRequiredProperty = requiredProperties.contains(key);

Expand Down
2 changes: 1 addition & 1 deletion lib/swagger_dart_code_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class SwaggerDartCodeGenerator implements Builder {
allEnums,
options,
);

final imports = codeGenerator.generateImportsContent(
fileNameWithoutExtension,
models.contains('@JsonSerializable'),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: swagger_dart_code_generator

version: 2.12.1
version: 2.12.2

homepage: https://github.com/epam-cross-platform-lab/swagger-dart-code-generator
repository: https://github.com/epam-cross-platform-lab/swagger-dart-code-generator
Expand Down
1 change: 0 additions & 1 deletion test/generator_tests/enums_generator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:swagger_dart_code_generator/src/models/generator_options.dart';
import 'package:swagger_dart_code_generator/src/swagger_models/requests/swagger_request_parameter.dart';
import 'package:test/test.dart';


void main() {
final generator = SwaggerEnumsGeneratorV3(
GeneratorOptions(
Expand Down
12 changes: 5 additions & 7 deletions test/generator_tests/models_generator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,7 @@ void main() {
});

test('Should return validate constructor property', () {
final map = <String, SwaggerSchema>{
'Animal': SwaggerSchema()
};
final map = <String, SwaggerSchema>{'Animal': SwaggerSchema()};
const expectedResult = 'this.animal';
final result = generator.generateConstructorPropertiesContent(
className: '',
Expand Down Expand Up @@ -315,7 +313,7 @@ void main() {

const className = 'Animals';
const jsonKeyExpectedResult = "\t@JsonKey(name: 'Animals')\n";
const fieldExpectedResult = 'final Pet animals';
const fieldExpectedResult = 'final Pet? animals';
final result = generator.generatePropertiesContent(
SwaggerRoot.empty,
map,
Expand Down Expand Up @@ -420,7 +418,7 @@ void main() {
const jsonKeyExpectedResult =
"@JsonKey(name: 'Dog', defaultValue: <Object>[])";

const propertyExpectedResult = 'final List<Object> dog';
const propertyExpectedResult = 'final List<Object>? dog';
final result = generator.generateListPropertyContent(
propertyName,
propertyKey,
Expand Down Expand Up @@ -480,7 +478,7 @@ void main() {
{},
);

expect(result, contains('final List<TestOriginalRef> dog;'));
expect(result, contains('final List<TestOriginalRef>? dog;'));
});

test('Should return List<Object> by ref', () {
Expand All @@ -503,7 +501,7 @@ void main() {
{},
);

expect(result, contains('final List<TestObject> dog;'));
expect(result, contains('final List<TestObject>? dog;'));
});
});

Expand Down
2 changes: 1 addition & 1 deletion test/generator_tests/test_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -831,4 +831,4 @@ const carsService = '''
}
}
}
''';
''';

0 comments on commit 2c25149

Please sign in to comment.