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

Version/2.3.4 #304

Merged
merged 46 commits into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
4f84c08
Fixed some issues
Nov 1, 2021
26c00bd
Added fix for Field annotations. Updatec changelog and pubspec
Nov 1, 2021
57186d5
Fixed lot of issues with AllOf support
Nov 2, 2021
9c20696
Updated changelog and pubspec
Nov 2, 2021
0a5e0a1
Added requestbodies generation from requests
Nov 4, 2021
4a5b13b
Merge remote-tracking branch 'origin/master' into version/2.2.5
Nov 4, 2021
e22cf42
Add windows support (#273)
Mause Nov 10, 2021
73d60e2
Fixed errors with requestBodies generation
Nov 12, 2021
cfc205f
Added possibility to use operationId for request name
Nov 12, 2021
364a7b4
Format code
Nov 12, 2021
42ee7ed
Updated pubspec and changelog
Nov 12, 2021
2da1393
Fix tests
Nov 12, 2021
95c4478
Fix analyser issues
Nov 12, 2021
bdd025b
Updated example readme
Nov 12, 2021
e5de95a
Removed converter generator
Nov 19, 2021
fc1a8e7
Fix cases when refs are overriden
Nov 24, 2021
e14ed6a
Fixed enum generation
Dec 14, 2021
16d788e
Released 2.2.8
Dec 14, 2021
73d0ae5
Added support int64
Dec 15, 2021
850624f
Updated changelog and pubspec
Dec 15, 2021
9139808
Fix for models int64
Dec 16, 2021
c575224
Updated changelog and pubspec
Dec 16, 2021
c1d69b3
Merge remote-tracking branch 'origin/version/2.2.8' into version/2.3.0
Dec 17, 2021
2a6f9cd
Removed not needed file
Dec 17, 2021
3f850d3
Fixed responses array of int
Dec 22, 2021
c6e9cb3
Reverted analysis options
Dec 22, 2021
b987918
Updated changelog
Dec 22, 2021
2c20a3b
Updated version
Dec 22, 2021
a1a93c3
Fixed tests
Dec 22, 2021
22075cd
Merge remote-tracking branch 'origin/master' into version/2.3.0
Dec 22, 2021
a1b6bd3
Fixed analyser issues
Dec 22, 2021
b6eb45b
Fixed issue #291
Dec 23, 2021
f495829
updated changelog and pubcpec
Dec 23, 2021
f006011
Merge remote-tracking branch 'origin/master' into version/2.3.1
Dec 23, 2021
39f4a7e
Added parsing of security for requests
Dec 24, 2021
56882c9
Fixed num parsing as Num
Dec 24, 2021
c2e4412
Implemented security keys definition
Dec 24, 2021
76073db
Removed not needed prints
Dec 24, 2021
d1d056e
Updated changelog and pubspec
Dec 24, 2021
79b7393
Merge remote-tracking branch 'origin/master' into version/2.3.2
Dec 24, 2021
8445037
Removed use_inheritance field
Jan 10, 2022
a4fc03b
Merge remote-tracking branch 'origin/master' into version/2.3.3
Jan 10, 2022
9a19d7a
Removed outdated tests
Jan 10, 2022
c519d47
Implemented integer enums support
Jan 11, 2022
a4bc616
Merge remote-tracking branch 'origin/master' into version/2.3.4
Jan 11, 2022
c114860
Updated changelog and pubspec
Jan 11, 2022
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 2.3.4

* Fixed Issue ([#268](https://github.com/epam-cross-platform-lab/swagger-dart-code-generator/issues/268))
* Added support of integer enum values

# 2.3.3

* Fixed Issue ([#297](https://github.com/epam-cross-platform-lab/swagger-dart-code-generator/issues/297))
Expand Down
2 changes: 2 additions & 0 deletions lib/src/code_generators/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const kInt64 = 'int64';
const kNum = 'num';
const kUndefinedParameter = 'undefinedParameter';

const kIntegerTypes = [kInteger, kInt64, kNum];

const kResponses = '/responses/';

//Request types
Expand Down
41 changes: 34 additions & 7 deletions lib/src/code_generators/swagger_enums_generator.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:convert';
import 'package:recase/recase.dart';
import 'package:swagger_dart_code_generator/src/code_generators/constants.dart';
import 'package:swagger_dart_code_generator/src/code_generators/swagger_models_generator.dart';
import 'package:swagger_dart_code_generator/src/exception_words.dart';
import 'package:swagger_dart_code_generator/src/extensions/string_extension.dart';
Expand Down Expand Up @@ -182,8 +183,16 @@ $enumsFromRequestBodies
swaggerRequestParameter.items?.enumValues ??
[];

final isInteger =
kIntegerTypes.contains(swaggerRequestParameter.schema?.type) ||
kIntegerTypes.contains(swaggerRequestParameter.items?.type);

if (enumValues.isNotEmpty) {
final enumContent = generateEnumContent(name, enumValues);
final enumContent = generateEnumContent(
name,
enumValues,
isInteger,
);

result.writeln(enumContent);
enumNames.add(swaggerRequestParameter.name);
Expand All @@ -195,8 +204,15 @@ $enumsFromRequestBodies
return result.toString();
}

String generateEnumContent(String enumName, List<String> enumValues) {
final enumValuesContent = getEnumValuesContent(enumValues);
String generateEnumContent(
String enumName,
List<String> enumValues,
bool isInteger,
) {
final enumValuesContent = getEnumValuesContent(
enumValues: enumValues,
isInteger: isInteger,
);

final enumMap = '''
\n\tconst \$${enumName}Map = {
Expand All @@ -217,7 +233,10 @@ $enumMap
return result;
}

String getEnumValuesContent(List<String> enumValues) {
String getEnumValuesContent({
required List<String> enumValues,
required bool isInteger,
}) {
final result = <String>[];
final resultStrings = <String>[];

Expand All @@ -229,8 +248,14 @@ $enumMap
}

result.add(validatedValue);
resultStrings.add(
"\t@JsonValue('${value.replaceAll("\$", "\\\$")}')\n\t$validatedValue");

if (isInteger) {
resultStrings.add(
"\t@JsonValue(${value.replaceAll("\$", "\\\$")})\n\t$validatedValue");
} else {
resultStrings.add(
"\t@JsonValue('${value.replaceAll("\$", "\\\$")}')\n\t$validatedValue");
}
});

return resultStrings.join(',\n');
Expand Down Expand Up @@ -363,10 +388,12 @@ $enumMap
};
''';

final isInteger = kIntegerTypes.contains(map['type']);

return """
enum ${enumName.capitalize} {
\t@JsonValue('$defaultEnumValueName')\n $defaultEnumValueName,
${getEnumValuesContent(enumValues)}
${getEnumValuesContent(enumValues: enumValues, isInteger: isInteger)}
}

$enumMap
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.3.3
version: 2.3.4

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
3 changes: 2 additions & 1 deletion test/generator_tests/enums_generator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ void main() {
test('Should generate enum values', () {
final values = <String>['file_sup'];
const output = "\t@JsonValue('file_sup')\n\tfileSup";
final result = generator.getEnumValuesContent(values);
final result =
generator.getEnumValuesContent(enumValues: values, isInteger: false);

expect(result, contains(output));
});
Expand Down