Skip to content

Commit

Permalink
Development (#676)
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

---------

Co-authored-by: Uladzimir Paliukhovich <[email protected]>
Co-authored-by: Romain <[email protected]>
  • Loading branch information
3 people authored Nov 10, 2023
1 parent 080bca0 commit 2a88a0c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 23 deletions.
28 changes: 18 additions & 10 deletions lib/src/code_generators/swagger_models_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,8 @@ abstract class SwaggerModelsGenerator extends SwaggerGeneratorBase {
final includeIfNullString = generateIncludeIfNullString();

if (typeName != kDynamic &&
(prop.isNullable || options.nullableModels.contains(typeName))) {
(prop.isNullable == true ||
options.nullableModels.contains(typeName))) {
typeName = typeName.makeNullable();
}

Expand Down Expand Up @@ -588,7 +589,8 @@ static $returnType $fromJsonFunction($valueType? value) => $enumNameCamelCase$fr
return false;
}

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

String nullable(
Expand Down Expand Up @@ -655,7 +657,8 @@ static $returnType $fromJsonFunction($valueType? value) => $enumNameCamelCase$fr
final jsonKeyContent =
"@JsonKey(name: '${_validatePropertyKey(propertyKey)}'$includeIfNullString${unknownEnumValue.jsonKey}$dateToJsonValue)\n";

if ((prop.isNullable || options.nullableModels.contains(className)) &&
if ((prop.isNullable == true ||
options.nullableModels.contains(className)) &&
!requiredProperties.contains(propertyKey)) {
typeName = typeName.makeNullable();
}
Expand Down Expand Up @@ -720,7 +723,8 @@ static $returnType $fromJsonFunction($valueType? value) => $enumNameCamelCase$fr
final jsonKeyContent =
"@JsonKey(name: '${_validatePropertyKey(propertyKey)}'$includeIfNullString${unknownEnumValue.jsonKey})\n";

if ((prop.isNullable || options.nullableModels.contains(className)) &&
if ((prop.isNullable == true ||
options.nullableModels.contains(className)) &&
!requiredProperties.contains(propertyKey)) {
typeName = typeName.makeNullable();
}
Expand Down Expand Up @@ -790,7 +794,8 @@ static $returnType $fromJsonFunction($valueType? value) => $enumNameCamelCase$fr
final jsonKeyContent =
"@JsonKey(name: '${_validatePropertyKey(propertyKey)}'$includeIfNullString${unknownEnumValue.jsonKey})\n";

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

var enumPropertyName = className.capitalize + key.capitalize;

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

var listPropertyName = 'List<$typeName>';

if ((prop.isNullable || options.nullableModels.contains(className)) &&
if ((prop.isNullable == true ||
options.nullableModels.contains(className)) &&
!requiredProperties.contains(propertyKey)) {
listPropertyName = listPropertyName.makeNullable();
}
Expand Down Expand Up @@ -1061,7 +1068,8 @@ static $returnType $fromJsonFunction($valueType? value) => $enumNameCamelCase$fr
jsonKeyContent += ')\n';
}

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

propertyNames.add(fieldName);

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

final isRequiredProperty = requiredProperties.contains(key);

Expand Down
2 changes: 1 addition & 1 deletion lib/src/code_generators/swagger_requests_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@ class SwaggerRequestsGenerator extends SwaggerGeneratorBase {
var typeName =
getValidatedClassName(schemaRef.getRef()).withPostfix(modelPostfix);

if (neededSchema.isNullable) {
if (neededSchema.isNullable == true) {
typeName = typeName.makeNullable();
}

Expand Down
6 changes: 3 additions & 3 deletions lib/src/swagger_models/responses/swagger_schema.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SwaggerSchema {
this.required = const [],
this.description = '',
this.enumNames,
this.isNullable = true,
this.isNullable,
this.hasAdditionalProperties = false,
this.msEnum,
this.title = '',
Expand Down Expand Up @@ -80,8 +80,8 @@ class SwaggerSchema {
@JsonKey(name: 'properties', defaultValue: {})
Map<String, SwaggerSchema> properties;

@JsonKey(name: 'nullable', defaultValue: true)
bool isNullable;
@JsonKey(name: 'nullable', defaultValue: null)
bool? isNullable;

@JsonKey(name: 'schema')
SwaggerSchema? schema;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/swagger_models/responses/swagger_schema.g2.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions test/generator_tests/models_generator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ void main() {
const className = 'Animals';
const propertyKey = 'Dog';
const jsonKeyExpectedResult = "\t@JsonKey(name: 'Dog')\n";
const fieldExpectedResult = '\tfinal Pet? dog';
const fieldExpectedResult = '\tfinal Pet dog';
final result = generator.generatePropertyContentBySchema(
map,
propertyName,
Expand All @@ -315,7 +315,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 All @@ -342,7 +342,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 All @@ -367,7 +367,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 All @@ -392,7 +392,7 @@ void main() {

const className = 'Animals';
const jsonKeyExpectedResult = "\t@JsonKey(name: '\\\$with')\n";
const fieldExpectedResult = 'final Pet? \$with';
const fieldExpectedResult = 'final Pet \$with';
final result = generator.generatePropertiesContent(
SwaggerRoot.empty,
map,
Expand Down Expand Up @@ -420,7 +420,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 +480,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 +503,7 @@ void main() {
{},
);

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

Expand Down

0 comments on commit 2a88a0c

Please sign in to comment.