Repository: epam-cross-platform-lab/swagger-dart-code-generator

Issue:
[FEATURE] Rid of excludes
Replase exclude to // ignore_for_file: type=lint 
[BUG] example project fails to generate code
**Describe the bug**
With a fresh checkout of this project (d27237607d3b865c29379ae2cb1cdba08e459f7b), the example fails to generate code.

**To Reproduce**
cd to the example subdirectory and run:
`flutter pub get`
`flutter pub run build_runner build --delete-conflicting-outputs`

**Expected behavior**
Classes to be generated for the swagger petstore example.

**Library version used:**
d27237607d3b865c29379ae2cb1cdba08e459f7b

**Additional context**
The code that's being generated has paths in the `export` 
Output:
```
[SEVERE] swagger_dart_code_generator:swagger_dart_code_generator on input_folder/swagger_dart_code_generator_temp.dart (cached):

Could not format because the source could not be parsed:

line 2, column 61 of .: Expected to find ';'.
  ╷
2 │ export 'input_folder\pet_service_swagger.swagger.dart' show InputFolder\petServiceSwagger;
```

Add ability to pass interceptors into the create() method of generated ChopperService 
The static create() method builds ChopperClient instance and pass it into private API impl class. ChopperClient class supports 'interceptors' parameter that allows to pass list of interceptors. It is very usefull ability of ChopperClient. But currently there is no (in the generated client) ability to pass 'interceptors' into the create() method. Interceptors give full control on request/response events with 'onRequest()' and 'onResponse()' listeners. 

Currently we are using interceptors to implement log requests/responses (Chopper HttpLoggingInterceptor), generate Curl-code (Chopper CurlInterceptor), do jwt-based authentication (custom interceptor implementation) and some other tasks. All these interceptors are working fine, but to support it we need to make replace generated 'create()' method with self version. Below the code demonstrated the diffs:

**Current generated code**:
```
@ChopperApi()
abstract class MyAppApi extends ChopperService {
  static MyAppApi create(
      {ChopperClient? client,
      String? baseUrl}) {
    if (client != null) {
      return _$MyAppApi(client);
    }

    final newClient = ChopperClient(
        services: [_$MyAppApi()],
        converter: $JsonSerializableConverter(),
        baseUrl: baseUrl ?? 'http://');
    return _$MyAppApi(newClient);
  }
```

**Corrected code that supports passing the 'interceptors'**:
```
@ChopperApi()
abstract class MyAppApi extends ChopperService {
  static MyAppApi create(
      {ChopperClient? client,
      String? baseUrl,
      Iterable<dynamic>? interceptors}) {
    if (client != null) {
      return _$MyAppApi(client);
    }

    final newClient = ChopperClient(
        services: [_$MyAppApi()],
        converter: $JsonSerializableConverter(),
        interceptors: interceptors ?? [],
        baseUrl: baseUrl ?? 'http://');
    return _$MyAppApi(newClient);
  }
```




Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8688a1f3..3e0dd1ec 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,9 @@
+# 2.4.2
+
+* Added linter rule `ignore_for_file` for generated files ([#350](https://github.com/epam-cross-platform-lab/swagger-dart-code-generator/issues/350))
+* Fixed `dateToJson` generation when `separateModels=true` ([#347](https://github.com/epam-cross-platform-lab/swagger-dart-code-generator/issues/347))
+* Added ability to add interceptors to create method ([#349](https://github.com/epam-cross-platform-lab/swagger-dart-code-generator/issues/349))
+* Fixed code generation on Windows platform ([#346](https://github.com/epam-cross-platform-lab/swagger-dart-code-generator/issues/346))
 # 2.4.1
 
 * Fixed cases when class has name `Query` ([#343](https://github.com/epam-cross-platform-lab/swagger-dart-code-generator/issues/343))
diff --git a/analysis_options.yaml b/analysis_options.yaml
index 92b23a51..9e0c1ce6 100644
--- a/analysis_options.yaml
+++ b/analysis_options.yaml
@@ -5,9 +5,6 @@ include: package:lints/recommended.yaml
 analyzer:
   strong-mode:
     implicit-casts: false
-  exclude:
-    - example/**/*.dart
-    - lib/**/*.g2.dart
 linter:
   rules:
     - type_annotate_public_apis
diff --git a/example/lib/swagger_generated_code/pet_service_json.swagger.dart b/example/lib/swagger_generated_code/pet_service_json.swagger.dart
index 8e3dd54e..aab574de 100644
--- a/example/lib/swagger_generated_code/pet_service_json.swagger.dart
+++ b/example/lib/swagger_generated_code/pet_service_json.swagger.dart
@@ -1,3 +1,5 @@
+// ignore_for_file: type=lint
+
 import 'package:json_annotation/json_annotation.dart';
 import 'package:collection/collection.dart';
 
diff --git a/example/lib/swagger_generated_code/pet_service_swagger.swagger.dart b/example/lib/swagger_generated_code/pet_service_swagger.swagger.dart
index 61cd074a..357d1ca9 100644
--- a/example/lib/swagger_generated_code/pet_service_swagger.swagger.dart
+++ b/example/lib/swagger_generated_code/pet_service_swagger.swagger.dart
@@ -1,3 +1,5 @@
+// ignore_for_file: type=lint
+
 import 'package:json_annotation/json_annotation.dart';
 import 'package:collection/collection.dart';
 
diff --git a/example/lib/swagger_generated_code/pet_service_yaml.swagger.dart b/example/lib/swagger_generated_code/pet_service_yaml.swagger.dart
index 33c4cbcf..9b6adcbc 100644
--- a/example/lib/swagger_generated_code/pet_service_yaml.swagger.dart
+++ b/example/lib/swagger_generated_code/pet_service_yaml.swagger.dart
@@ -1,3 +1,5 @@
+// ignore_for_file: type=lint
+
 import 'package:json_annotation/json_annotation.dart';
 import 'package:collection/collection.dart';
 
diff --git a/lib/src/code_generators/swagger_additions_generator.dart b/lib/src/code_generators/swagger_additions_generator.dart
index 9db65c54..faffa23b 100644
--- a/lib/src/code_generators/swagger_additions_generator.dart
+++ b/lib/src/code_generators/swagger_additions_generator.dart
@@ -8,13 +8,12 @@ class SwaggerAdditionsGenerator {
   ///Generates index.dart for all generated services
   String generateIndexes(List<String> fileNames) {
     final importsList = fileNames.map((key) {
-      final fileName = key
-          .split('/')
-          .last
+      final actualFileName = getFileNameBase(key);
+      final fileName = actualFileName
           .replaceAll('-', '_')
           .replaceAll('.json', '.swagger')
           .replaceAll('.yaml', '.swagger');
-      final className = getClassNameFromFileName(key.split('/').last);
+      final className = getClassNameFromFileName(actualFileName);
 
       return 'export \'$fileName.dart\' show $className;';
     }).toList();
@@ -59,6 +58,8 @@ import 'package:chopper/chopper.dart' as chopper;''';
 
     if (hasModels && !separateModels) {
       result.writeln("""
+// ignore_for_file: type=lint
+
 import 'package:json_annotation/json_annotation.dart';
 import 'package:collection/collection.dart';
 """);
@@ -198,6 +199,7 @@ final \$jsonDecoder = \$CustomJsonDecoder(generatedMapping);
     final newClient = ChopperClient(
       services: [_\$$className()],
       $converterString
+      interceptors: interceptors ?? [],
       $baseUrlString);
     return _\$$className(newClient);
 ''';
diff --git a/lib/src/code_generators/swagger_requests_generator.dart b/lib/src/code_generators/swagger_requests_generator.dart
index dc275f27..ee7cb88e 100644
--- a/lib/src/code_generators/swagger_requests_generator.dart
+++ b/lib/src/code_generators/swagger_requests_generator.dart
@@ -84,6 +84,12 @@ class SwaggerRequestsGenerator {
             ..type = Reference('String?')
             ..name = 'baseUrl',
         ))
+        ..optionalParameters.add(Parameter(
+          (p) => p
+            ..named = true
+            ..type = Reference('Iterable<dynamic>?')
+            ..name = 'interceptors',
+        ))
         ..body = Code(body),
     );
   }
diff --git a/lib/src/extensions/file_name_extensions.dart b/lib/src/extensions/file_name_extensions.dart
index 6751e81a..2dcd03d7 100644
--- a/lib/src/extensions/file_name_extensions.dart
+++ b/lib/src/extensions/file_name_extensions.dart
@@ -1,16 +1,15 @@
 import 'package:swagger_dart_code_generator/src/extensions/string_extension.dart';
-import 'package:path/path.dart' as p;
 
 String getClassNameFromFileName(String file) {
-  final name = getFileNameWithoutExtension(file).replaceAll('-', '_');
+  final name = removeFileExtension(file).replaceAll('-', '_');
   final result = name.split('_').map((String e) => e.capitalize);
   return result.join();
 }
 
-String getFileNameWithoutExtension(String file) {
+String removeFileExtension(String file) {
   return file.split('.').first;
 }
 
 String getFileNameBase(String filePath) {
-  return p.basenameWithoutExtension(filePath).replaceAll('-', '_');
+  return filePath.split(RegExp(r'\\|\/')).last.replaceAll('-', '_');
 }
diff --git a/lib/swagger_dart_code_generator.dart b/lib/swagger_dart_code_generator.dart
index 37917553..852a902e 100644
--- a/lib/swagger_dart_code_generator.dart
+++ b/lib/swagger_dart_code_generator.dart
@@ -50,7 +50,7 @@ Map<String, List<String>> _generateExtensions(GeneratorOptions options) {
   result[additionalResultPath] = {};
 
   for (var url in allFilesPaths) {
-    final name = getFileNameBase(url.split('/').last);
+    final name = removeFileExtension(getFileNameBase(url));
 
     result[additionalResultPath]!.add(join(out, '$name$_outputFileExtension'));
     result[additionalResultPath]!
@@ -69,7 +69,6 @@ Map<String, List<String>> _generateExtensions(GeneratorOptions options) {
   ///Register additional outputs in first input
   result[additionalResultPath]!.add(join(out, _indexFileName));
   result[additionalResultPath]!.add(join(out, _mappingFileName));
-  print(jsonEncode(allFilesPaths));
 
   return result.map((key, value) => MapEntry(key, value.toList()));
 }
@@ -93,7 +92,7 @@ class SwaggerDartCodeGenerator implements Builder {
   @override
   Future<void> build(BuildStep buildStep) async {
     for (final url in options.inputUrls) {
-      final fileNameWithExtension = url.split('/').last.replaceAll('-', '_');
+      final fileNameWithExtension = getFileNameBase(url);
 
       final contents = await _download(url);
 
@@ -134,9 +133,10 @@ class SwaggerDartCodeGenerator implements Builder {
         contentMap = jsonDecode(contents) as Map<String, dynamic>;
       }
 
-      final fileNameWithExtension = url.split('/').last.replaceAll('-', '_');
+      final fileNameWithExtension = getFileNameBase(url);
 
-      final fileNameWithoutExtension = getFileNameBase(fileNameWithExtension);
+      final fileNameWithoutExtension =
+          removeFileExtension(fileNameWithExtension);
 
       await _generateAndWriteFile(
         contents: contentMap,
@@ -165,16 +165,16 @@ class SwaggerDartCodeGenerator implements Builder {
     final codeGenerator = SwaggerCodeGenerator();
 
     final models = codeGenerator.generateModels(
-        contents, getFileNameWithoutExtension(fileNameWithExtension), options);
+        contents, removeFileExtension(fileNameWithExtension), options);
 
     final responses = codeGenerator.generateResponses(
-        contents, getFileNameWithoutExtension(fileNameWithExtension), options);
+        contents, removeFileExtension(fileNameWithExtension), options);
 
     final requestBodies = codeGenerator.generateRequestBodies(
-        contents, getFileNameWithoutExtension(fileNameWithExtension), options);
+        contents, removeFileExtension(fileNameWithExtension), options);
 
     final enums = codeGenerator.generateEnums(
-        contents, getFileNameWithoutExtension(fileNameWithExtension));
+        contents, removeFileExtension(fileNameWithExtension));
 
     final imports = codeGenerator.generateImportsContent(
       fileNameWithoutExtension,
@@ -187,11 +187,11 @@ class SwaggerDartCodeGenerator implements Builder {
     final requests = codeGenerator.generateRequests(
         contents,
         getClassNameFromFileName(fileNameWithExtension),
-        getFileNameWithoutExtension(fileNameWithExtension),
+        removeFileExtension(fileNameWithExtension),
         options);
 
     final customDecoder = codeGenerator.generateCustomJsonConverter(
-        getFileNameWithoutExtension(fileNameWithExtension), options);
+        removeFileExtension(fileNameWithExtension), options);
 
     final dateToJson = codeGenerator.generateDateToJson();
 
@@ -320,6 +320,8 @@ $dateToJson
         : '';
 
     return '''
+// ignore_for_file: type=lint
+
 import 'package:json_annotation/json_annotation.dart';
 import 'package:collection/collection.dart';
 import 'dart:convert';
diff --git a/pubspec.yaml b/pubspec.yaml
index 91488832..1c6d3202 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,6 +1,6 @@
 name: swagger_dart_code_generator
 
-version: 2.4.1
+version: 2.4.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


Test patch:
diff --git a/test/file_name_extensions_test.dart b/test/file_name_extensions_test.dart
index 3144670d..a0e972b4 100644
--- a/test/file_name_extensions_test.dart
+++ b/test/file_name_extensions_test.dart
@@ -5,7 +5,7 @@ void main() {
   group('Additions generator tests', () {
     test('Should generate mapping for files', () {
       const fileName = 'example_file.swagger.dart';
-      var result = getFileNameWithoutExtension(fileName);
+      var result = removeFileExtension(fileName);
       var expandedResult = 'example_file';
       expect(result, equals(expandedResult));
     });