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

[dart] json_serializable: remove experimental generator #10532

Merged
merged 4 commits into from
Oct 12, 2021
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
10 changes: 0 additions & 10 deletions bin/configs/dart-petstore-json-serializable-client-lib-fake.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion docs/generators/dart.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|pubLibrary|Library name in generated code| |null|
|pubName|Name in generated pubspec| |null|
|pubVersion|Version in generated pubspec| |null|
|serializationLibrary|Specify serialization library|<dl><dt>**native_serialization**</dt><dd>Use native serializer, backwards compatible</dd><dt>**json_serializable**</dt><dd>Use json_serializable. Experimental and subject to breaking changes without further notice</dd></dl>|native_serialization|
|serializationLibrary|Specify serialization library|<dl><dt>**native_serialization**</dt><dd>Use native serializer, backwards compatible</dd></dl>|native_serialization|
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|sourceFolder|Source folder for generated code| |null|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public class DartClientCodegen extends AbstractDartCodegen {
private final Logger LOGGER = LoggerFactory.getLogger(DartClientCodegen.class);

public static final String SERIALIZATION_LIBRARY_NATIVE = "native_serialization";
public static final String SERIALIZATION_LIBRARY_JSON_SERIALIZABLE = "json_serializable";

public DartClientCodegen() {
super();
Expand All @@ -43,7 +42,6 @@ public DartClientCodegen() {

final Map<String, String> serializationOptions = new HashMap<>();
serializationOptions.put(SERIALIZATION_LIBRARY_NATIVE, "Use native serializer, backwards compatible");
serializationOptions.put(SERIALIZATION_LIBRARY_JSON_SERIALIZABLE, "Use json_serializable. Experimental and subject to breaking changes without further notice");
serializationLibrary.setEnum(serializationOptions);
cliOptions.add(serializationLibrary);
}
Expand Down Expand Up @@ -88,15 +86,7 @@ private void setSerializationLibrary() {
LOGGER.info("Using serialization library {}", serialization_library);

switch (serialization_library) {
case SERIALIZATION_LIBRARY_JSON_SERIALIZABLE:
additionalProperties.put(SERIALIZATION_LIBRARY_JSON_SERIALIZABLE, "true");
// json_serializable requires build.yaml
supportingFiles.add(new SupportingFile("build.yaml.mustache",
"" /* main project dir */,
"build.yaml"));
break;

case SERIALIZATION_LIBRARY_NATIVE: // fall trough to default backwards compatible generator
case SERIALIZATION_LIBRARY_NATIVE: // fall through to default backwards compatible generator
default:
additionalProperties.put(SERIALIZATION_LIBRARY_NATIVE, "true");

Expand Down
28 changes: 1 addition & 27 deletions modules/openapi-generator/src/main/resources/dart2/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -197,33 +197,7 @@ class {{{classname}}} {
{{/isMap}}
{{^isMap}}
return await apiClient.deserializeAsync(await _decodeBodyBytes(response), '{{{returnType}}}',) as {{{returnType}}};
{{/isMap}}{{/isArray}}{{/native_serialization}}{{#json_serializable}}
{{#isArray}}
{{#uniqueItems}}
return (json.decode(response.body) as List)
.map((i) => {{{returnBaseType}}}.fromJson(i))
.toSet();
{{/uniqueItems}}
{{^uniqueItems}}
return (json.decode(response.body) as List)
.map((i) => {{{returnBaseType}}}.fromJson(i))
.toList();
{{/uniqueItems}}
{{/isArray}}
{{^isArray}}
{{#isMap}}
return {{{returnType}}}.from(json.decode(response.body));
{{/isMap}}
{{^isMap}}
{{#returnTypeIsPrimitive}}
return response.body as {{{returnBaseType}}};
{{/returnTypeIsPrimitive}}
{{^returnTypeIsPrimitive}}
return {{{returnType}}}.fromJson(json.decode(response.body));
{{/returnTypeIsPrimitive}}
{{/isMap}}
{{/isArray}}
{{/json_serializable}}
{{/isMap}}{{/isArray}}{{/native_serialization}}
}
return Future<{{{returnType}}}>.value();
{{/returnType}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ class ApiClient {
case '{{{classname}}}':
{{#isEnum}}
{{#native_serialization}}return {{{classname}}}TypeTransformer().decode(value);{{/native_serialization}}
{{#json_serializable}} return _$enumDecode(_${{{classname}}}EnumMap, value);{{/json_serializable}}
{{/isEnum}}
{{^isEnum}}
return {{{classname}}}.fromJson(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ String parameterToString(dynamic value) {
{{#model}}
{{#isEnum}}
if (value is {{{classname}}}) {
{{#native_serialization}} return {{{classname}}}TypeTransformer().encode(value).toString();{{/native_serialization}}{{#json_serializable}} return value.toString();{{/json_serializable}}
{{#native_serialization}} return {{{classname}}}TypeTransformer().encode(value).toString();{{/native_serialization}}
}
{{/isEnum}}
{{/model}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import 'dart:io';

import 'package:http/http.dart';
import 'package:intl/intl.dart';
{{#json_serializable}}
import 'package:json_annotation/json_annotation.dart';
{{/json_serializable}}
import 'package:meta/meta.dart';

part 'api_client.dart';
Expand All @@ -26,9 +23,6 @@ part 'auth/http_bearer_auth.dart';
{{#models}}{{#model}}part 'model/{{{classFilename}}}.dart';
{{/model}}{{/models}}

{{#json_serializable}}
part 'api.g.dart';
{{/json_serializable}}
const _delimiters = {'csv': ',', 'ssv': ' ', 'tsv': '\t', 'pipes': '|'};
const _dateEpochMarker = 'epoch';
final _dateFormatter = DateFormat('yyyy-MM-dd');
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@
{{#native_serialization}}
{{>serialization/native/native_enum}}
{{/native_serialization}}
{{#json_serializable}}
{{>serialization/json_serializable/json_serializable_enum}}
{{/json_serializable}}
{{/isEnum}}
{{^isEnum}}
{{#native_serialization}}
{{>serialization/native/native_class}}
{{/native_serialization}}
{{#json_serializable}}
{{>serialization/json_serializable/json_serializable_class}}
{{/json_serializable}}
{{/isEnum}}
{{/model}}
{{/models}}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,5 @@ dependencies:
http: '>=0.13.0 <0.14.0'
intl: '^0.17.0'
meta: '^1.1.8'
{{#json_serializable}}
json_annotation: '^3.1.1'{{/json_serializable}}
dev_dependencies:
test: '>=1.16.0 <1.18.0'
{{#json_serializable}}
build_runner: '^1.10.9'
json_serializable: '^3.5.1'{{/json_serializable}}

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,6 @@
<modules>
<module>samples/openapi3/client/petstore/dart2/petstore_client_lib</module>
<module>samples/openapi3/client/petstore/dart2/petstore</module>
<!--<module>samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake</module>-->
<module>samples/openapi3/client/petstore/dart-dio-next/petstore_client_lib_fake</module>
<module>samples/openapi3/client/petstore/dart-dio-next/dio_http_petstore_client_lib_fake</module>
</modules>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ class PetApi {
// FormatException when trying to decode an empty string.
if (response.body != null && response.statusCode != HttpStatus.noContent) {
return await apiClient.deserializeAsync(await _decodeBodyBytes(response), 'Pet',) as Pet;
}

}
return Future<Pet>.value();
}

Expand Down Expand Up @@ -203,6 +204,7 @@ class PetApi {
return (await apiClient.deserializeAsync(responseBody, 'List<Pet>') as List)
.cast<Pet>()
.toList(growable: false);

}
return Future<List<Pet>>.value();
}
Expand Down Expand Up @@ -272,6 +274,7 @@ class PetApi {
return (await apiClient.deserializeAsync(responseBody, 'List<Pet>') as List)
.cast<Pet>()
.toList(growable: false);

}
return Future<List<Pet>>.value();
}
Expand Down Expand Up @@ -337,7 +340,8 @@ class PetApi {
// FormatException when trying to decode an empty string.
if (response.body != null && response.statusCode != HttpStatus.noContent) {
return await apiClient.deserializeAsync(await _decodeBodyBytes(response), 'Pet',) as Pet;
}

}
return Future<Pet>.value();
}

Expand Down Expand Up @@ -397,7 +401,8 @@ class PetApi {
// FormatException when trying to decode an empty string.
if (response.body != null && response.statusCode != HttpStatus.noContent) {
return await apiClient.deserializeAsync(await _decodeBodyBytes(response), 'Pet',) as Pet;
}

}
return Future<Pet>.value();
}

Expand Down Expand Up @@ -556,7 +561,8 @@ class PetApi {
// FormatException when trying to decode an empty string.
if (response.body != null && response.statusCode != HttpStatus.noContent) {
return await apiClient.deserializeAsync(await _decodeBodyBytes(response), 'ApiResponse',) as ApiResponse;
}

}
return Future<ApiResponse>.value();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class StoreApi {
// FormatException when trying to decode an empty string.
if (response.body != null && response.statusCode != HttpStatus.noContent) {
return Map<String, int>.from(await apiClient.deserializeAsync(await _decodeBodyBytes(response), 'Map<String, int>'),);

}
return Future<Map<String, int>>.value();
}
Expand Down Expand Up @@ -184,7 +185,8 @@ class StoreApi {
// FormatException when trying to decode an empty string.
if (response.body != null && response.statusCode != HttpStatus.noContent) {
return await apiClient.deserializeAsync(await _decodeBodyBytes(response), 'Order',) as Order;
}

}
return Future<Order>.value();
}

Expand Down Expand Up @@ -244,7 +246,8 @@ class StoreApi {
// FormatException when trying to decode an empty string.
if (response.body != null && response.statusCode != HttpStatus.noContent) {
return await apiClient.deserializeAsync(await _decodeBodyBytes(response), 'Order',) as Order;
}

}
return Future<Order>.value();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ class UserApi {
// FormatException when trying to decode an empty string.
if (response.body != null && response.statusCode != HttpStatus.noContent) {
return await apiClient.deserializeAsync(await _decodeBodyBytes(response), 'User',) as User;
}

}
return Future<User>.value();
}

Expand Down Expand Up @@ -366,7 +367,8 @@ class UserApi {
// FormatException when trying to decode an empty string.
if (response.body != null && response.statusCode != HttpStatus.noContent) {
return await apiClient.deserializeAsync(await _decodeBodyBytes(response), 'String',) as String;
}

}
return Future<String>.value();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,5 @@ dependencies:
http: '>=0.13.0 <0.14.0'
intl: '^0.17.0'
meta: '^1.1.8'

dev_dependencies:
test: '>=1.16.0 <1.18.0'

Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ class AnotherFakeApi {
// FormatException when trying to decode an empty string.
if (response.body != null && response.statusCode != HttpStatus.noContent) {
return await apiClient.deserializeAsync(await _decodeBodyBytes(response), 'ModelClient',) as ModelClient;
}

}
return Future<ModelClient>.value();
}
}
Loading