-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Bump dart2 code compatibility to Dart 2.14 and introduce sound null-safety #10541
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |
| {{#operations}} | ||
|
|
||
| class {{{classname}}} { | ||
| {{{classname}}}([ApiClient apiClient]) : apiClient = apiClient ?? defaultApiClient; | ||
| {{{classname}}}([ApiClient? apiClient]) : apiClient = apiClient ?? defaultApiClient; | ||
|
|
||
| final ApiClient apiClient; | ||
| {{#operation}} | ||
|
|
@@ -49,24 +49,13 @@ class {{{classname}}} { | |
| /// | ||
| {{/-last}} | ||
| {{/allParams}} | ||
| Future<Response> {{{nickname}}}WithHttpInfo({{#allParams}}{{#required}}{{{dataType}}} {{{paramName}}},{{^-last}} {{/-last}}{{/required}}{{/allParams}}{{#hasOptionalParams}}{ {{#allParams}}{{^required}}{{{dataType}}} {{{paramName}}},{{^-last}} {{/-last}}{{/required}}{{/allParams}} }{{/hasOptionalParams}}) async { | ||
| {{#hasParams}} | ||
| // Verify required params are set. | ||
| {{#allParams}} | ||
| {{#required}} | ||
| if ({{{paramName}}} == null) { | ||
| throw ApiException(HttpStatus.badRequest, 'Missing required param: {{{paramName}}}'); | ||
| } | ||
| {{/required}} | ||
| {{/allParams}} | ||
|
|
||
| {{/hasParams}} | ||
| Future<Response> {{{nickname}}}WithHttpInfo({{#allParams}}{{#required}}{{{dataType}}} {{{paramName}}},{{^-last}} {{/-last}}{{/required}}{{/allParams}}{{#hasOptionalParams}}{ {{#allParams}}{{^required}}{{{dataType}}}? {{{paramName}}},{{^-last}} {{/-last}}{{/required}}{{/allParams}} }{{/hasOptionalParams}}) async { | ||
| // ignore: prefer_const_declarations | ||
| final path = r'{{{path}}}'{{#pathParams}} | ||
| .replaceAll({{=<% %>=}}'{<% baseName %>}'<%={{ }}=%>, {{{paramName}}}{{^isString}}.toString(){{/isString}}){{/pathParams}}; | ||
|
|
||
| // ignore: prefer_final_locals | ||
| Object postBody{{#bodyParam}} = {{{paramName}}}{{/bodyParam}}; | ||
| Object? postBody{{#bodyParam}} = {{{paramName}}}{{/bodyParam}}; | ||
|
|
||
| final queryParams = <QueryParam>[]; | ||
| final headerParams = <String, String>{}; | ||
|
|
@@ -174,7 +163,7 @@ class {{{classname}}} { | |
| /// | ||
| {{/-last}} | ||
| {{/allParams}} | ||
| Future<{{{returnType}}}{{^returnType}}void{{/returnType}}> {{{nickname}}}({{#allParams}}{{#required}}{{{dataType}}} {{{paramName}}},{{^-last}} {{/-last}}{{/required}}{{/allParams}}{{#hasOptionalParams}}{ {{#allParams}}{{^required}}{{{dataType}}} {{{paramName}}},{{^-last}} {{/-last}}{{/required}}{{/allParams}} }{{/hasOptionalParams}}) async { | ||
| Future<{{#returnType}}{{{.}}}?{{/returnType}}{{^returnType}}void{{/returnType}}> {{{nickname}}}({{#allParams}}{{#required}}{{{dataType}}} {{{paramName}}},{{^-last}} {{/-last}}{{/required}}{{/allParams}}{{#hasOptionalParams}}{ {{#allParams}}{{^required}}{{{dataType}}}? {{{paramName}}},{{^-last}} {{/-last}}{{/required}}{{/allParams}} }{{/hasOptionalParams}}) async { | ||
| final response = await {{{nickname}}}WithHttpInfo({{#allParams}}{{#required}}{{{paramName}}},{{^-last}} {{/-last}}{{/required}}{{/allParams}}{{#hasOptionalParams}} {{#allParams}}{{^required}}{{{paramName}}}: {{{paramName}}},{{^-last}} {{/-last}}{{/required}}{{/allParams}} {{/hasOptionalParams}}); | ||
| if (response.statusCode >= HttpStatus.badRequest) { | ||
| throw ApiException(response.statusCode, await _decodeBodyBytes(response)); | ||
|
|
@@ -183,7 +172,7 @@ class {{{classname}}} { | |
| // When a remote server returns no body with a status of 204, we shall not decode it. | ||
| // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" | ||
| // FormatException when trying to decode an empty string. | ||
| if (response.body != null && response.statusCode != HttpStatus.noContent) { | ||
| if (response.statusCode != HttpStatus.noContent) { | ||
| {{#native_serialization}} | ||
| {{#isArray}} | ||
| final responseBody = await _decodeBodyBytes(response); | ||
|
|
@@ -225,7 +214,6 @@ class {{{classname}}} { | |
| {{/isArray}} | ||
| {{/json_serializable}} | ||
| } | ||
| return Future<{{{returnType}}}>.value(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this was added recently to satisfy stricter linter config, so pls revert #10263 |
||
| {{/returnType}} | ||
| } | ||
| {{/operation}} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,12 +33,7 @@ class ApiClient { | |
| Client get client => _client; | ||
|
|
||
| /// Requests to use a new HTTP [Client] in this class. | ||
| /// | ||
| /// If the [newClient] is null, an [ArgumentError] is thrown. | ||
| set client(Client newClient) { | ||
| if (newClient == null) { | ||
| throw ArgumentError('New client instance cannot be null.'); | ||
| } | ||
| _client = newClient; | ||
| } | ||
|
|
||
|
|
@@ -55,7 +50,7 @@ class ApiClient { | |
| /// or deleted. | ||
| Map<String, Authentication> get authentications => Map.unmodifiable(_authentications); | ||
|
|
||
| T getAuthentication<T extends Authentication>(String name) { | ||
| T? getAuthentication<T extends Authentication>(String name) { | ||
| final authentication = _authentications[name]; | ||
| return authentication is T ? authentication : null; | ||
| } | ||
|
|
@@ -66,10 +61,10 @@ class ApiClient { | |
| String path, | ||
| String method, | ||
| List<QueryParam> queryParams, | ||
| Object body, | ||
| Object? body, | ||
| Map<String, String> headerParams, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| Map<String, String> formParams, | ||
| String nullableContentType, | ||
| String? nullableContentType, | ||
| List<String> authNames, | ||
| ) async { | ||
| _updateParamsForAuth(authNames, queryParams, headerParams); | ||
|
|
@@ -149,12 +144,12 @@ class ApiClient { | |
| } | ||
| {{#native_serialization}} | ||
|
|
||
| Future<dynamic> deserializeAsync(String json, String targetType, {bool growable}) async => | ||
| Future<dynamic> deserializeAsync(String json, String targetType, {bool? growable}) async => | ||
| // ignore: deprecated_member_use_from_same_package | ||
| deserialize(json, targetType, growable: growable); | ||
|
|
||
| @Deprecated('Scheduled for removal in OpenAPI Generator 6.x. Use deserializeAsync() instead.') | ||
| dynamic deserialize(String json, String targetType, {bool growable}) { | ||
| dynamic deserialize(String json, String targetType, {bool? growable}) { | ||
| // Remove all spaces. Necessary for regular expressions as well. | ||
| targetType = targetType.replaceAll(' ', ''); // ignore: parameter_assignments | ||
|
|
||
|
|
@@ -166,10 +161,10 @@ class ApiClient { | |
| {{/native_serialization}} | ||
|
|
||
| // ignore: deprecated_member_use_from_same_package | ||
| Future<String> serializeAsync(Object value) async => serialize(value); | ||
| Future<String> serializeAsync(Object? value) async => serialize(value); | ||
|
|
||
| @Deprecated('Scheduled for removal in OpenAPI Generator 6.x. Use serializeAsync() instead.') | ||
| String serialize(Object value) => value == null ? '' : json.encode(value); | ||
| String serialize(Object? value) => value == null ? '' : json.encode(value); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it ever make sense to serialise null object? |
||
|
|
||
| /// Update query and header parameters based on authentication settings. | ||
| /// @param authNames The authentications to apply | ||
|
|
@@ -188,7 +183,7 @@ class ApiClient { | |
| } | ||
|
|
||
| {{#native_serialization}} | ||
| static dynamic _deserialize(dynamic value, String targetType, {bool growable}) { | ||
| static dynamic _deserialize(dynamic value, String targetType, {bool? growable}) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to make growable false or true by default? this would avoid doing |
||
| try { | ||
| switch (targetType) { | ||
| case 'String': | ||
|
|
@@ -216,21 +211,21 @@ class ApiClient { | |
| {{/model}} | ||
| {{/models}} | ||
| default: | ||
| Match match; | ||
| Match? match; | ||
| if (value is List && (match = _regList.firstMatch(targetType)) != null) { | ||
| targetType = match[1]; // ignore: parameter_assignments | ||
| targetType = match![1]!; // ignore: parameter_assignments | ||
| return value | ||
| .map<dynamic>((dynamic v) => _deserialize(v, targetType, growable: growable)) | ||
| .toList(growable: growable); | ||
| .toList(growable: growable == true); | ||
| } | ||
| if (value is Set && (match = _regSet.firstMatch(targetType)) != null) { | ||
| targetType = match[1]; // ignore: parameter_assignments | ||
| targetType = match![1]!; // ignore: parameter_assignments | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yea, that's better than my defauling to |
||
| return value | ||
| .map<dynamic>((dynamic v) => _deserialize(v, targetType, growable: growable)) | ||
| .toSet(); | ||
| } | ||
| if (value is Map && (match = _regMap.firstMatch(targetType)) != null) { | ||
| targetType = match[1]; // ignore: parameter_assignments | ||
| targetType = match![1]!; // ignore: parameter_assignments | ||
| return Map<String, dynamic>.fromIterables( | ||
| value.keys.cast<String>(), | ||
| value.values.map<dynamic>((dynamic v) => _deserialize(v, targetType, growable: growable)), | ||
|
|
@@ -249,8 +244,8 @@ class ApiClient { | |
| /// Primarily intended for use in an isolate. | ||
| class DeserializationMessage { | ||
| const DeserializationMessage({ | ||
| @required this.json, | ||
| @required this.targetType, | ||
| required this.json, | ||
| required this.targetType, | ||
| this.growable, | ||
| }); | ||
|
|
||
|
|
@@ -261,7 +256,7 @@ class DeserializationMessage { | |
| final String targetType; | ||
|
|
||
| /// Whether to make deserialized lists or maps growable. | ||
| final bool growable; | ||
| final bool? growable; | ||
| } | ||
|
|
||
| /// Primarily intended for use in an isolate. | ||
|
|
@@ -281,4 +276,4 @@ Future<dynamic> deserializeAsync(DeserializationMessage message) async { | |
| {{/native_serialization}} | ||
|
|
||
| /// Primarily intended for use in an isolate. | ||
| Future<String> serializeAsync(Object value) async => value == null ? '' : json.encode(value); | ||
| Future<String> serializeAsync(Object? value) async => value == null ? '' : json.encode(value); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,9 +6,9 @@ class ApiException implements Exception { | |
| ApiException.withInner(this.code, this.message, this.innerException, this.stackTrace); | ||
|
|
||
| int code = 0; | ||
| String message; | ||
| Exception innerException; | ||
| StackTrace stackTrace; | ||
| String? message; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. another design question, when does it make sense to raise ApiException without a message? |
||
| Exception? innerException; | ||
| StackTrace? stackTrace; | ||
|
|
||
| @override | ||
| String toString() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there really no other method for this already? Im really surprised this needs to be introduced as new code @wing328 ?