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

Add Open API version number to root client #259

Merged
merged 4 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions swagger_parser/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down
2 changes: 1 addition & 1 deletion swagger_parser/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class RestClient {
final Dio _dio;
final String? _baseUrl;

static String get version => '';

AuthClient? _auth;
UserClient? _user;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class RestClient {
final Dio _dio;
final String? _baseUrl;

static String get version => '';

AuthClient? _auth;
UserClient? _user;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
45 changes: 45 additions & 0 deletions swagger_parser/test/generator/root_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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);
Expand Down Expand Up @@ -80,6 +119,8 @@ class RestClient {
final Dio _dio;
final String? _baseUrl;

static String get version => '';

OneClient? _one;
TwoClient? _two;
ThreeClient? _three;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -174,6 +217,8 @@ class RestClient {
final Dio _dio;
final String? _baseUrl;

static String get version => '';

OneClient? _one;
TwoClient? _two;
ThreeClient? _three;
Expand Down