diff --git a/swagger_parser/CHANGELOG.md b/swagger_parser/CHANGELOG.md index eb0f06fb..e63d88a2 100644 --- a/swagger_parser/CHANGELOG.md +++ b/swagger_parser/CHANGELOG.md @@ -1,3 +1,6 @@ +## 1.18.3 +- Add version getter to root client + ## 1.18.3 - Remove support of BigInt in Dart for `int64` types diff --git a/swagger_parser/lib/src/generator/templates/dart_root_client_template.dart b/swagger_parser/lib/src/generator/templates/dart_root_client_template.dart index 70ac71eb..21eeedf2 100644 --- a/swagger_parser/lib/src/generator/templates/dart_root_client_template.dart +++ b/swagger_parser/lib/src/generator/templates/dart_root_client_template.dart @@ -45,6 +45,8 @@ ${descriptionComment(comment)}class $className { final Dio _dio; final String? _baseUrl; + static String get version => '${openApiInfo.apiVersion ?? ''}'; + ${_privateFields(clientsNames, postfix)} ${_getters(clientsNames, postfix)} diff --git a/swagger_parser/pubspec.yaml b/swagger_parser/pubspec.yaml index 9ed722dc..861ec450 100644 --- a/swagger_parser/pubspec.yaml +++ b/swagger_parser/pubspec.yaml @@ -1,6 +1,6 @@ name: swagger_parser description: Package that generates REST clients and data classes from OpenApi definition file -version: 1.18.3 +version: 1.18.4 repository: https://github.com/Carapacik/swagger_parser/tree/main/swagger_parser topics: - swagger diff --git a/swagger_parser/test/e2e/tests/basic/additional_properties_class.2.0/expected_files/rest_client.dart b/swagger_parser/test/e2e/tests/basic/additional_properties_class.2.0/expected_files/rest_client.dart index 89de3624..0acb531f 100644 --- a/swagger_parser/test/e2e/tests/basic/additional_properties_class.2.0/expected_files/rest_client.dart +++ b/swagger_parser/test/e2e/tests/basic/additional_properties_class.2.0/expected_files/rest_client.dart @@ -19,6 +19,8 @@ class RestClient { final Dio _dio; final String? _baseUrl; + static String get version => '1.0'; + TestClient? _test; TestClient get test => _test ??= TestClient(_dio, baseUrl: _baseUrl); diff --git a/swagger_parser/test/e2e/tests/basic/basic_requests.2.0/expected_files/rest_client.dart b/swagger_parser/test/e2e/tests/basic/basic_requests.2.0/expected_files/rest_client.dart index 0b9732a9..b61db636 100644 --- a/swagger_parser/test/e2e/tests/basic/basic_requests.2.0/expected_files/rest_client.dart +++ b/swagger_parser/test/e2e/tests/basic/basic_requests.2.0/expected_files/rest_client.dart @@ -17,6 +17,8 @@ class RestClient { final Dio _dio; final String? _baseUrl; + static String get version => ''; + AuthClient? _auth; UserClient? _user; diff --git a/swagger_parser/test/e2e/tests/basic/basic_requests.3.0/expected_files/rest_client.dart b/swagger_parser/test/e2e/tests/basic/basic_requests.3.0/expected_files/rest_client.dart index 0b9732a9..b61db636 100644 --- a/swagger_parser/test/e2e/tests/basic/basic_requests.3.0/expected_files/rest_client.dart +++ b/swagger_parser/test/e2e/tests/basic/basic_requests.3.0/expected_files/rest_client.dart @@ -17,6 +17,8 @@ class RestClient { final Dio _dio; final String? _baseUrl; + static String get version => ''; + AuthClient? _auth; UserClient? _user; diff --git a/swagger_parser/test/e2e/tests/corrector/expected_files/rest_client.dart b/swagger_parser/test/e2e/tests/corrector/expected_files/rest_client.dart index 5037ce21..55df2338 100644 --- a/swagger_parser/test/e2e/tests/corrector/expected_files/rest_client.dart +++ b/swagger_parser/test/e2e/tests/corrector/expected_files/rest_client.dart @@ -17,6 +17,8 @@ class RestClient { final Dio _dio; final String? _baseUrl; + static String get version => '1.0.0'; + ClientClient? _client; ClientClient get client => _client ??= ClientClient(_dio, baseUrl: _baseUrl); diff --git a/swagger_parser/test/e2e/tests/enum_member_names/expected_files/rest_client.dart b/swagger_parser/test/e2e/tests/enum_member_names/expected_files/rest_client.dart index 6fa2d43d..fb9f9f9a 100644 --- a/swagger_parser/test/e2e/tests/enum_member_names/expected_files/rest_client.dart +++ b/swagger_parser/test/e2e/tests/enum_member_names/expected_files/rest_client.dart @@ -17,6 +17,8 @@ class RestClient { final Dio _dio; final String? _baseUrl; + static String get version => '0.0.0 (v1)'; + ApiClient? _api; ApiClient get api => _api ??= ApiClient(_dio, baseUrl: _baseUrl); diff --git a/swagger_parser/test/e2e/tests/multipart_request_properties/expected_files/rest_client.dart b/swagger_parser/test/e2e/tests/multipart_request_properties/expected_files/rest_client.dart index 1b8ab64a..8765b710 100644 --- a/swagger_parser/test/e2e/tests/multipart_request_properties/expected_files/rest_client.dart +++ b/swagger_parser/test/e2e/tests/multipart_request_properties/expected_files/rest_client.dart @@ -16,6 +16,8 @@ class RestClient { final Dio _dio; final String? _baseUrl; + static String get version => ''; + ClientClient? _client; ClientClient get client => _client ??= ClientClient(_dio, baseUrl: _baseUrl); diff --git a/swagger_parser/test/e2e/tests/multipart_request_with_ref/expected_files/rest_client.dart b/swagger_parser/test/e2e/tests/multipart_request_with_ref/expected_files/rest_client.dart index 5037ce21..55df2338 100644 --- a/swagger_parser/test/e2e/tests/multipart_request_with_ref/expected_files/rest_client.dart +++ b/swagger_parser/test/e2e/tests/multipart_request_with_ref/expected_files/rest_client.dart @@ -17,6 +17,8 @@ class RestClient { final Dio _dio; final String? _baseUrl; + static String get version => '1.0.0'; + ClientClient? _client; ClientClient get client => _client ??= ClientClient(_dio, baseUrl: _baseUrl); diff --git a/swagger_parser/test/e2e/tests/nullable_types/expected_files/rest_client.dart b/swagger_parser/test/e2e/tests/nullable_types/expected_files/rest_client.dart index 6fa2d43d..fb9f9f9a 100644 --- a/swagger_parser/test/e2e/tests/nullable_types/expected_files/rest_client.dart +++ b/swagger_parser/test/e2e/tests/nullable_types/expected_files/rest_client.dart @@ -17,6 +17,8 @@ class RestClient { final Dio _dio; final String? _baseUrl; + static String get version => '0.0.0 (v1)'; + ApiClient? _api; ApiClient get api => _api ??= ApiClient(_dio, baseUrl: _baseUrl); diff --git a/swagger_parser/test/e2e/tests/request_unnamed_types/expected_files/rest_client.dart b/swagger_parser/test/e2e/tests/request_unnamed_types/expected_files/rest_client.dart index 1b8ab64a..8765b710 100644 --- a/swagger_parser/test/e2e/tests/request_unnamed_types/expected_files/rest_client.dart +++ b/swagger_parser/test/e2e/tests/request_unnamed_types/expected_files/rest_client.dart @@ -16,6 +16,8 @@ class RestClient { final Dio _dio; final String? _baseUrl; + static String get version => ''; + ClientClient? _client; ClientClient get client => _client ??= ClientClient(_dio, baseUrl: _baseUrl); diff --git a/swagger_parser/test/generator/root_client_test.dart b/swagger_parser/test/generator/root_client_test.dart index 199c8f67..a7a5fcd2 100644 --- a/swagger_parser/test/generator/root_client_test.dart +++ b/swagger_parser/test/generator/root_client_test.dart @@ -15,6 +15,43 @@ void main() { }); }); + group('Version getter', () { + test('dart', () async { + final clients = [ + const UniversalRestClient(name: 'One', imports: {}, requests: []), + ]; + const fillController = FillController( + config: GeneratorConfig(name: '', outputDirectory: ''), + info: OpenApiInfo(apiVersion: '1.0.0', schemaVersion: OAS.v3_1), + ); + final filledContent = fillController.fillRootClient(clients); + const expectedContents = ''' +import 'package:dio/dio.dart'; + +import 'one/one_client.dart'; + +/// `v1.0.0` +class RestClient { + RestClient( + Dio dio, { + String? baseUrl, + }) : _dio = dio, + _baseUrl = baseUrl; + + final Dio _dio; + final String? _baseUrl; + + static String get version => '1.0.0'; + + OneClient? _one; + + OneClient get one => _one ??= OneClient(_dio, baseUrl: _baseUrl); +} +'''; + expect(filledContent.content, expectedContents); + }); + }); + group('root client with one client', () { test('dart', () async { final clients = [ @@ -39,6 +76,8 @@ class RestClient { final Dio _dio; final String? _baseUrl; + static String get version => ''; + OneClient? _one; OneClient get one => _one ??= OneClient(_dio, baseUrl: _baseUrl); @@ -80,6 +119,8 @@ class RestClient { final Dio _dio; final String? _baseUrl; + static String get version => ''; + OneClient? _one; TwoClient? _two; ThreeClient? _three; @@ -129,6 +170,8 @@ class RestClient { final Dio _dio; final String? _baseUrl; + static String get version => ''; + OneClient? _one; OneClient get one => _one ??= OneClient(_dio, baseUrl: _baseUrl); @@ -174,6 +217,8 @@ class RestClient { final Dio _dio; final String? _baseUrl; + static String get version => ''; + OneClient? _one; TwoClient? _two; ThreeClient? _three;