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