Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development #677

Merged
merged 58 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
2c826d8
Fixed some issues
Jun 7, 2023
f064936
formatted code
Jun 7, 2023
352d09f
updated SDK
Jun 7, 2023
861dfac
Updated SDK and version
Jun 7, 2023
d320f12
Fixed generation of lists of classes
Jun 7, 2023
fbda249
Fixed generation $Items classes
Jun 7, 2023
1ade0c7
Updated pubspec and changelog
Jun 7, 2023
fe41f12
Fixed #524
Jun 9, 2023
173d9aa
Fixed #598 Generation of query enum parameters
Jun 23, 2023
a09e442
Merge branch 'master' into version/2.11.6
Jun 23, 2023
16b5e3f
Fixed conflicts
Jun 23, 2023
d1c7d2f
Fixed some issues in swaggers
Jul 5, 2023
6ae1b7d
Updated changelog and pubspec
Jul 5, 2023
ff4d14e
Fix #583, #637, #619 and update readme (#638)
romainboucher Sep 8, 2023
3466b48
Merge branch 'master' into version/2.11.6
Sep 8, 2023
290deb0
Fixed generation of some fields
Sep 22, 2023
d3a77eb
Removed test
Sep 22, 2023
8283674
Fixed classes named List
Sep 22, 2023
a71a9e9
Fixed generation of query parameters with ref default type
Sep 22, 2023
dead103
Merge branch 'master' into version/2.11.6
Sep 22, 2023
d99e4f9
Fixed generation of DateTime parameters
Sep 22, 2023
e2fe57f
Fixed generation of responses in some cases
Sep 22, 2023
8e8c5ff
Merge branch 'master' into version/2.11.6
Sep 22, 2023
1b24515
Some fixes
Sep 22, 2023
4bdd297
Updated changelog and pubspec
Sep 22, 2023
b974025
Merge branch 'master' into version/2.11.6
Sep 22, 2023
3e6c745
Implemented not nullable fields
Sep 29, 2023
bc0c305
Fixed tests
Sep 29, 2023
0ed9163
fixed generation of some swaggers
Oct 13, 2023
baec549
Added ability to return String values
Oct 13, 2023
fdc496a
Merge branch 'master' into development
Oct 13, 2023
899833e
Returned main.dart content
Oct 13, 2023
1eabeb0
Updated pubspec and changelog
Oct 13, 2023
360b837
Fixed generation of required and not required fields
Oct 20, 2023
6c2f1a7
Added check for object ref in body
Oct 20, 2023
e973370
Fixed some things
Oct 20, 2023
4fa3a11
Fixed tests
Oct 20, 2023
7896617
Fixed tests
Oct 20, 2023
22af9f0
Fixed some things
Oct 20, 2023
ddf6b4c
Updated changelog and pubspec
Oct 20, 2023
66dba04
Removed not needed lines in tests
Oct 20, 2023
8fcfbb0
Fixed generation of nullable responses
Nov 1, 2023
7448d28
Added generation of DateTime
Nov 1, 2023
c8c3522
Updated pubspec and changelog
Nov 1, 2023
d7a06b2
Merge branch 'master' into development
Nov 1, 2023
4c7f4df
Fixed tests
Nov 1, 2023
6b9e104
Fixed #669 Generation models from content schema allof
Nov 10, 2023
c191faf
Fixed #665 generation putIfAbsent for response from content schema
Nov 10, 2023
f37ea45
Merge branch 'master' into development
Nov 10, 2023
313cea9
Fixed generation of nullable and required properties
Nov 10, 2023
cc170ce
Merge branch 'master' into development
Nov 10, 2023
74bd541
Fixed tests
Nov 10, 2023
07421ca
Fixed some stuff related to nullable properties
Nov 10, 2023
d19f042
Updated changelog and pubspec
Nov 10, 2023
82db0eb
Formatted code
Nov 10, 2023
ecb17c4
Merge branch 'master' into development
Nov 10, 2023
7719589
Formatted code
Nov 10, 2023
d277030
Fixed tests
Nov 10, 2023
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
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 = '''
}
}
}
''';
''';