Skip to content

Commit

Permalink
Removed generation of indexes file
Browse files Browse the repository at this point in the history
  • Loading branch information
uladzimir_paliukhovich committed Feb 2, 2022
1 parent e4716a3 commit 4ad82db
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 45 deletions.
1 change: 0 additions & 1 deletion example/lib/swagger_generated_code/client_index.dart

This file was deleted.

18 changes: 0 additions & 18 deletions lib/src/code_generators/swagger_additions_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,6 @@ import 'package:swagger_dart_code_generator/src/models/generator_options.dart';
class SwaggerAdditionsGenerator {
static const mappingVariableName = 'generatedMapping';

///Generates index.dart for all generated services
String generateIndexes(Map<String, List<String>> buildExtensions) {
final importsList = buildExtensions.keys.map((String key) {
final fileName = key
.split('/')
.last
.replaceAll('-', '_')
.replaceAll('.json', '.swagger');
final className = getClassNameFromFileName(key.split('/').last);

return 'export \'$fileName.dart\' show $className;';
}).toList();

importsList.sort();

return importsList.join('\n');
}

///Generated Map of all models generated by generator
String generateConverterMappings(
Map<String, List<String>> buildExtensions, bool hasModels) {
Expand Down
3 changes: 0 additions & 3 deletions lib/src/swagger_code_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ class SwaggerCodeGenerator {
return openApi != null ? 3 : 2;
}

String generateIndexes(Map<String, List<String>> buildExtensions) =>
_getSwaggerAdditionsGenerator().generateIndexes(buildExtensions);

String generateConverterMappings(
Map<String, List<String>> buildExtensions, bool hasModels) =>
_getSwaggerAdditionsGenerator()
Expand Down
16 changes: 4 additions & 12 deletions lib/swagger_dart_code_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ const String _outputFileExtension = '.swagger.dart';
const String _outputEnumsFileExtension = '.enums.swagger.dart';
const String _outputModelsFileExtension = '.models.swagger.dart';
const String _outputResponsesFileExtension = '.responses.swagger.dart';
const String _indexFileName = 'client_index.dart';
const String _mappingFileName = 'client_mapping.dart';
const kAdditionalResult = 'lib/main.dart';
const kAdditionalResult = 'lib/swagger_dart_code_generator_temp.dart';

String normal(String path) {
return AssetId('', path).path;
Expand All @@ -32,6 +31,8 @@ Map<String, List<String>> _generateExtensions(GeneratorOptions options) {
(FileSystemEntity file) =>
_inputFileExtensions.any((ending) => file.path.endsWith(ending)));

File(kAdditionalResult).createSync();

var out = normalize(options.outputFolder);

filesList.forEach((FileSystemEntity element) {
Expand All @@ -58,7 +59,6 @@ Map<String, List<String>> _generateExtensions(GeneratorOptions options) {
});

///Register additional outputs in first input
result[kAdditionalResult]!.add(join(out, _indexFileName));
result[kAdditionalResult]!.add(join(out, _mappingFileName));
print('\n\n\n$result');
return result;
Expand All @@ -84,6 +84,7 @@ class SwaggerDartCodeGenerator implements Builder {
Future<void> build(BuildStep buildStep) async {
if (buildStep.inputId.path == kAdditionalResult) {
await _generateAndWriteAdditionalFiles(buildStep);
File(kAdditionalResult).deleteSync();
return;
}

Expand Down Expand Up @@ -260,15 +261,6 @@ $dateToJson
AssetId inputId, BuildStep buildStep, bool hasModels) async {
final codeGenerator = SwaggerCodeGenerator();

final indexAssetId =
AssetId(inputId.package, join(options.outputFolder, _indexFileName));

final imports = codeGenerator.generateIndexes(buildExtensions);

if (!options.buildOnlyModels) {
await buildStep.writeAsString(indexAssetId, _formatter.format(imports));
}

if (options.withConverter && !options.buildOnlyModels) {
final mappingAssetId = AssetId(
inputId.package, join(options.outputFolder, _mappingFileName));
Expand Down
11 changes: 0 additions & 11 deletions test/generator_tests/additions_generator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,6 @@ void main() {
expect(result,
contains("import 'swagger.fileName.enums.swagger.dart' as enums;"));
});

test('Should generate indexes file', () {
final result = generator.generateIndexes(<String, List<String>>{
'someFile.dart': <String>['someFile.swagger.dart'],
'secondFile.dart': <String>['secondFile.swagger.dart']
});

expect(result, contains("export 'someFile.dart.dart' show SomeFile;"));
expect(
result, contains("export 'secondFile.dart.dart' show SecondFile;"));
});
});
group('Test for generateDateToJson', () {
final generator = SwaggerAdditionsGenerator();
Expand Down

0 comments on commit 4ad82db

Please sign in to comment.