From 3b34060fe9c33822f93f29653064b468d97db66b Mon Sep 17 00:00:00 2001 From: Sergei Kimmel Date: Fri, 17 Jan 2025 10:51:30 +0400 Subject: [PATCH 1/2] Bumped up Dart min version to 3.0.0 for json_serializable, because json_serializable requires Dart 3.5 since 6.9.0 --- docs/generators/dart-dio.md | 1 + .../codegen/languages/DartDioClientCodegen.java | 16 ++++++++++++++++ .../resources/dart/libraries/dio/README.mustache | 5 +++++ .../dart/libraries/dio/pubspec.mustache | 9 +++++++-- .../options/DartDioClientOptionsProvider.java | 1 + .../client/petstore/dart-dio/oneof/README.md | 2 +- .../oneof_polymorphism_and_inheritance/README.md | 2 +- .../petstore/dart-dio/oneof_primitive/README.md | 2 +- .../README.md | 2 +- .../pubspec.yaml | 4 ++-- .../dart-dio/petstore_client_lib_fake/README.md | 2 +- 11 files changed, 37 insertions(+), 9 deletions(-) diff --git a/docs/generators/dart-dio.md b/docs/generators/dart-dio.md index f93b09ffbf8d..5a5539cdef11 100644 --- a/docs/generators/dart-dio.md +++ b/docs/generators/dart-dio.md @@ -40,6 +40,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |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| |src| +|supportDart2|Use dependencies compatible with Dart 2.| |false| |useEnumExtension|Allow the 'x-enum-values' extension for enums| |false| ## IMPORT MAPPING diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioClientCodegen.java index 6cd2c7906026..41afebb8cd50 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioClientCodegen.java @@ -71,6 +71,9 @@ public class DartDioClientCodegen extends AbstractDartCodegen { public static final String FINAL_PROPERTIES = "finalProperties"; public static final String FINAL_PROPERTIES_DEFAULT_VALUE = "true"; + public static final String SUPPORT_DART2 = "supportDart2"; + public static final String SUPPORT_DART2_DEFAULT_VALUE = "false"; + private static final String CLIENT_NAME = "clientName"; @Getter @Setter @@ -138,6 +141,11 @@ public DartDioClientCodegen() { final CliOption finalProperties = CliOption.newBoolean(FINAL_PROPERTIES, "Whether properties are marked as final when using Json Serializable for serialization"); finalProperties.setDefault("true"); cliOptions.add(finalProperties); + + // Support Dart 2 Option + final CliOption supportDart2 = CliOption.newBoolean(SUPPORT_DART2, "Use dependencies compatible with Dart 2."); + supportDart2.setDefault("false"); + cliOptions.add(supportDart2); } @Override @@ -183,6 +191,14 @@ public void processOpts() { additionalProperties.put(FINAL_PROPERTIES, Boolean.parseBoolean(additionalProperties.get(FINAL_PROPERTIES).toString())); } + if (!additionalProperties.containsKey(SUPPORT_DART2)) { + additionalProperties.put(SUPPORT_DART2, Boolean.parseBoolean(SUPPORT_DART2_DEFAULT_VALUE)); + LOGGER.debug("supportDart2 not set, using default {}", SUPPORT_DART2_DEFAULT_VALUE); + } + else { + additionalProperties.put(SUPPORT_DART2, Boolean.parseBoolean(additionalProperties.get(SUPPORT_DART2).toString())); + } + if (!additionalProperties.containsKey(CLIENT_NAME)) { final String name = org.openapitools.codegen.utils.StringUtils.camelize(pubName); additionalProperties.put(CLIENT_NAME, name); diff --git a/modules/openapi-generator/src/main/resources/dart/libraries/dio/README.mustache b/modules/openapi-generator/src/main/resources/dart/libraries/dio/README.mustache index 98cd7112caa2..c99271adde34 100644 --- a/modules/openapi-generator/src/main/resources/dart/libraries/dio/README.mustache +++ b/modules/openapi-generator/src/main/resources/dart/libraries/dio/README.mustache @@ -20,7 +20,12 @@ For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}}) ## Requirements +{{#supportDart2}} * Dart 2.15.0+ or Flutter 2.8.0+ +{{/supportDart2}} +{{^supportDart2}} +* Dart 3.0.0+ or Flutter 2.8.0+ +{{/supportDart2}} * Dio 5.0.0+ (https://pub.dev/packages/dio) {{#useJsonSerializable}} * JSON Serializable 6.1.5+ (https://pub.dev/packages/json_serializable) diff --git a/modules/openapi-generator/src/main/resources/dart/libraries/dio/pubspec.mustache b/modules/openapi-generator/src/main/resources/dart/libraries/dio/pubspec.mustache index 5a93026402d2..04cd7f95f7ce 100644 --- a/modules/openapi-generator/src/main/resources/dart/libraries/dio/pubspec.mustache +++ b/modules/openapi-generator/src/main/resources/dart/libraries/dio/pubspec.mustache @@ -10,7 +10,7 @@ publish_to: {{.}} {{/pubPublishTo}} environment: - sdk: '>={{#useJsonSerializable}}2.17.0{{/useJsonSerializable}}{{^useJsonSerializable}}2.15.0{{/useJsonSerializable}} <4.0.0' + sdk: '>={{#useJsonSerializable}}{{#supportDart2}}2.17.0{{/supportDart2}}{{^supportDart2}}3.0.0{{/supportDart2}}{{/useJsonSerializable}}{{^useJsonSerializable}}2.15.0{{/useJsonSerializable}} <4.0.0' dependencies: dio: '^5.2.0' @@ -37,6 +37,11 @@ dev_dependencies: {{/useBuiltValue}} {{#useJsonSerializable}} build_runner: any - json_serializable: '^6.1.5' +{{#supportDart2}} + json_serializable: '>=6.1.5 <6.9.0' +{{/supportDart2}} +{{^supportDart2}} + json_serializable: '^6.9.0' +{{/supportDart2}} {{/useJsonSerializable}} test: ^1.16.0 diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/options/DartDioClientOptionsProvider.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/options/DartDioClientOptionsProvider.java index bcda220f4328..549c9fc19ad5 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/options/DartDioClientOptionsProvider.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/options/DartDioClientOptionsProvider.java @@ -64,6 +64,7 @@ public Map createOptions() { .put(CodegenConstants.SERIALIZATION_LIBRARY, DartDioClientCodegen.SERIALIZATION_LIBRARY_DEFAULT) .put(DartDioClientCodegen.DATE_LIBRARY, DartDioClientCodegen.DATE_LIBRARY_DEFAULT) .put(DartDioClientCodegen.FINAL_PROPERTIES, DartDioClientCodegen.FINAL_PROPERTIES_DEFAULT_VALUE) + .put(DartDioClientCodegen.SUPPORT_DART2, DartDioClientCodegen.SUPPORT_DART2_DEFAULT_VALUE) .put(DartDioClientCodegen.EQUALITY_CHECK_METHOD, DartDioClientCodegen.EQUALITY_CHECK_METHOD_DEFAULT) .put(CodegenConstants.SOURCE_FOLDER, SOURCE_FOLDER_VALUE) .put(DartDioClientCodegen.USE_ENUM_EXTENSION, USE_ENUM_EXTENSION) diff --git a/samples/openapi3/client/petstore/dart-dio/oneof/README.md b/samples/openapi3/client/petstore/dart-dio/oneof/README.md index 0c8f2bded3e7..d68457b49905 100644 --- a/samples/openapi3/client/petstore/dart-dio/oneof/README.md +++ b/samples/openapi3/client/petstore/dart-dio/oneof/README.md @@ -9,7 +9,7 @@ This Dart package is automatically generated by the [OpenAPI Generator](https:// ## Requirements -* Dart 2.15.0+ or Flutter 2.8.0+ +* Dart 3.0.0+ or Flutter 2.8.0+ * Dio 5.0.0+ (https://pub.dev/packages/dio) ## Installation & Usage diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/README.md b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/README.md index 4191207291a2..074c7dd8c289 100644 --- a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/README.md +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/README.md @@ -10,7 +10,7 @@ This Dart package is automatically generated by the [OpenAPI Generator](https:// ## Requirements -* Dart 2.15.0+ or Flutter 2.8.0+ +* Dart 3.0.0+ or Flutter 2.8.0+ * Dio 5.0.0+ (https://pub.dev/packages/dio) ## Installation & Usage diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_primitive/README.md b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/README.md index 8d0583befd31..d56ddc68f49b 100644 --- a/samples/openapi3/client/petstore/dart-dio/oneof_primitive/README.md +++ b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/README.md @@ -9,7 +9,7 @@ This Dart package is automatically generated by the [OpenAPI Generator](https:// ## Requirements -* Dart 2.15.0+ or Flutter 2.8.0+ +* Dart 3.0.0+ or Flutter 2.8.0+ * Dio 5.0.0+ (https://pub.dev/packages/dio) ## Installation & Usage diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/README.md b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/README.md index b4e368f61604..591c966d7713 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/README.md +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/README.md @@ -9,7 +9,7 @@ This Dart package is automatically generated by the [OpenAPI Generator](https:// ## Requirements -* Dart 2.15.0+ or Flutter 2.8.0+ +* Dart 3.0.0+ or Flutter 2.8.0+ * Dio 5.0.0+ (https://pub.dev/packages/dio) * JSON Serializable 6.1.5+ (https://pub.dev/packages/json_serializable) diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/pubspec.yaml b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/pubspec.yaml index 8a32778ad38a..3352f8d86179 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/pubspec.yaml +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/pubspec.yaml @@ -4,7 +4,7 @@ description: OpenAPI API client homepage: homepage environment: - sdk: '>=2.17.0 <4.0.0' + sdk: '>=3.0.0 <4.0.0' dependencies: dio: '^5.2.0' @@ -12,5 +12,5 @@ dependencies: dev_dependencies: build_runner: any - json_serializable: '^6.1.5' + json_serializable: '^6.9.0' test: ^1.16.0 diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/README.md b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/README.md index b7ff35917512..f99b2eed1b85 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/README.md +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/README.md @@ -9,7 +9,7 @@ This Dart package is automatically generated by the [OpenAPI Generator](https:// ## Requirements -* Dart 2.15.0+ or Flutter 2.8.0+ +* Dart 3.0.0+ or Flutter 2.8.0+ * Dio 5.0.0+ (https://pub.dev/packages/dio) ## Installation & Usage From 5b43171ccbea28a792ea58dff7280576b8fa2be4 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Mon, 10 Feb 2025 00:50:53 +0800 Subject: [PATCH 2/2] default to true --- .../openapitools/codegen/languages/DartDioClientCodegen.java | 4 ++-- samples/openapi3/client/petstore/dart-dio/oneof/README.md | 2 +- .../dart-dio/oneof_polymorphism_and_inheritance/README.md | 2 +- .../client/petstore/dart-dio/oneof_primitive/README.md | 2 +- .../petstore_client_lib_fake-json_serializable/README.md | 2 +- .../petstore_client_lib_fake-json_serializable/pubspec.yaml | 4 ++-- .../petstore/dart-dio/petstore_client_lib_fake/README.md | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioClientCodegen.java index 41afebb8cd50..b176d2bfce91 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioClientCodegen.java @@ -72,7 +72,7 @@ public class DartDioClientCodegen extends AbstractDartCodegen { public static final String FINAL_PROPERTIES_DEFAULT_VALUE = "true"; public static final String SUPPORT_DART2 = "supportDart2"; - public static final String SUPPORT_DART2_DEFAULT_VALUE = "false"; + public static final String SUPPORT_DART2_DEFAULT_VALUE = "true"; private static final String CLIENT_NAME = "clientName"; @@ -144,7 +144,7 @@ public DartDioClientCodegen() { // Support Dart 2 Option final CliOption supportDart2 = CliOption.newBoolean(SUPPORT_DART2, "Use dependencies compatible with Dart 2."); - supportDart2.setDefault("false"); + supportDart2.setDefault("true"); cliOptions.add(supportDart2); } diff --git a/samples/openapi3/client/petstore/dart-dio/oneof/README.md b/samples/openapi3/client/petstore/dart-dio/oneof/README.md index 2e7246ae0ad7..6e22b5ad4e16 100644 --- a/samples/openapi3/client/petstore/dart-dio/oneof/README.md +++ b/samples/openapi3/client/petstore/dart-dio/oneof/README.md @@ -9,7 +9,7 @@ This Dart package is automatically generated by the [OpenAPI Generator](https:// ## Requirements -* Dart 3.0.0+ or Flutter 2.8.0+ +* Dart 2.15.0+ or Flutter 2.8.0+ * Dio 5.0.0+ (https://pub.dev/packages/dio) ## Installation & Usage diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/README.md b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/README.md index c3ad54cf6960..bf9cfc26265e 100644 --- a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/README.md +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/README.md @@ -10,7 +10,7 @@ This Dart package is automatically generated by the [OpenAPI Generator](https:// ## Requirements -* Dart 3.0.0+ or Flutter 2.8.0+ +* Dart 2.15.0+ or Flutter 2.8.0+ * Dio 5.0.0+ (https://pub.dev/packages/dio) ## Installation & Usage diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_primitive/README.md b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/README.md index 297edb96192e..3f9cffd228eb 100644 --- a/samples/openapi3/client/petstore/dart-dio/oneof_primitive/README.md +++ b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/README.md @@ -9,7 +9,7 @@ This Dart package is automatically generated by the [OpenAPI Generator](https:// ## Requirements -* Dart 3.0.0+ or Flutter 2.8.0+ +* Dart 2.15.0+ or Flutter 2.8.0+ * Dio 5.0.0+ (https://pub.dev/packages/dio) ## Installation & Usage diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/README.md b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/README.md index c44e58f88559..91dbf764ff66 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/README.md +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/README.md @@ -9,7 +9,7 @@ This Dart package is automatically generated by the [OpenAPI Generator](https:// ## Requirements -* Dart 3.0.0+ or Flutter 2.8.0+ +* Dart 2.15.0+ or Flutter 2.8.0+ * Dio 5.0.0+ (https://pub.dev/packages/dio) * JSON Serializable 6.1.5+ (https://pub.dev/packages/json_serializable) diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/pubspec.yaml b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/pubspec.yaml index 3352f8d86179..cd006f19ae32 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/pubspec.yaml +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/pubspec.yaml @@ -4,7 +4,7 @@ description: OpenAPI API client homepage: homepage environment: - sdk: '>=3.0.0 <4.0.0' + sdk: '>=2.17.0 <4.0.0' dependencies: dio: '^5.2.0' @@ -12,5 +12,5 @@ dependencies: dev_dependencies: build_runner: any - json_serializable: '^6.9.0' + json_serializable: '>=6.1.5 <6.9.0' test: ^1.16.0 diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/README.md b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/README.md index 645b3fd93221..164cd4b4c1b8 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/README.md +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/README.md @@ -9,7 +9,7 @@ This Dart package is automatically generated by the [OpenAPI Generator](https:// ## Requirements -* Dart 3.0.0+ or Flutter 2.8.0+ +* Dart 2.15.0+ or Flutter 2.8.0+ * Dio 5.0.0+ (https://pub.dev/packages/dio) ## Installation & Usage