From b6fc62c15de0087b58d38a610400b3a6888b3499 Mon Sep 17 00:00:00 2001 From: Peter Leibiger <kuhnroyal@gmail.com> Date: Wed, 25 Nov 2020 17:42:32 +0100 Subject: [PATCH 1/5] [dart-dio] Add basic integration test POM This basically just fetches dependencies, runs the built_value generator and empty test cases. Even running empty test cases is more than is currently possible and at least finds compile errors. There are compile errors atm which need to be fixed. --- .../codegen/languages/DartClientCodegen.java | 2 +- .../languages/DartDioClientCodegen.java | 6 +- .../main/resources/dart-dio/api_test.mustache | 29 ++++++ .../resources/dart-dio/model_test.mustache | 28 ++++++ .../main/resources/dart-dio/pubspec.mustache | 1 + samples/client/petstore/dart-dio/.gitignore | 3 + .../dart-dio/.openapi-generator-ignore | 3 + .../dart-dio/.openapi-generator/FILES | 1 - samples/client/petstore/dart-dio/pom.xml | 88 +++++++++++++++++++ samples/client/petstore/dart-dio/pubspec.yaml | 1 + .../dart-dio/test/api_response_test.dart | 27 ++++++ .../petstore/dart-dio/test/category_test.dart | 22 +++++ .../petstore/dart-dio/test/order_test.dart | 43 +++++++++ .../petstore/dart-dio/test/pet_api_test.dart | 74 ++++++++++++++++ .../petstore/dart-dio/test/pet_test.dart | 43 +++++++++ .../dart-dio/test/store_api_test.dart | 46 ++++++++++ .../petstore/dart-dio/test/tag_test.dart | 22 +++++ .../petstore/dart-dio/test/user_api_test.dart | 74 ++++++++++++++++ .../petstore/dart-dio/test/user_test.dart | 53 +++++++++++ 19 files changed, 559 insertions(+), 7 deletions(-) create mode 100644 modules/openapi-generator/src/main/resources/dart-dio/api_test.mustache create mode 100644 modules/openapi-generator/src/main/resources/dart-dio/model_test.mustache create mode 100644 samples/client/petstore/dart-dio/pom.xml create mode 100644 samples/client/petstore/dart-dio/test/api_response_test.dart create mode 100644 samples/client/petstore/dart-dio/test/category_test.dart create mode 100644 samples/client/petstore/dart-dio/test/order_test.dart create mode 100644 samples/client/petstore/dart-dio/test/pet_api_test.dart create mode 100644 samples/client/petstore/dart-dio/test/pet_test.dart create mode 100644 samples/client/petstore/dart-dio/test/store_api_test.dart create mode 100644 samples/client/petstore/dart-dio/test/tag_test.dart create mode 100644 samples/client/petstore/dart-dio/test/user_api_test.dart create mode 100644 samples/client/petstore/dart-dio/test/user_test.dart diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartClientCodegen.java index 9ca0e9fdd7c..d06f3019c57 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartClientCodegen.java @@ -617,7 +617,7 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig { return; // skip if DART_POST_PROCESS_FILE env variable is not defined } - // only procees the following type (or we can simply rely on the file extension to check if it's a Dart file) + // only process the following type (or we can simply rely on the file extension to check if it's a Dart file) Set<String> supportedFileType = Sets.newHashSet( "supporting-mustache", "model-test", 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 cdcb958998a..9e04bfefa45 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 @@ -51,7 +51,7 @@ public class DartDioClientCodegen extends DartClientCodegen { private static final String IS_FORMAT_JSON = "jsonFormat"; private static final String CLIENT_NAME = "clientName"; - private static Set<String> modelToIgnore = new HashSet<>(); + private static final Set<String> modelToIgnore = new HashSet<>(); static { modelToIgnore.add("datetime"); @@ -71,10 +71,6 @@ public class DartDioClientCodegen extends DartClientCodegen { embeddedTemplateDir = "dart-dio"; this.setTemplateDir(embeddedTemplateDir); - //no tests at this time - modelTestTemplateFiles.clear(); - apiTestTemplateFiles.clear(); - cliOptions.add(new CliOption(NULLABLE_FIELDS, "Is the null fields should be in the JSON payload")); CliOption dateLibrary = new CliOption(DATE_LIBRARY, "Option. Date library to use").defaultValue(this.getDateLibrary()); Map<String, String> dateOptions = new HashMap<>(); diff --git a/modules/openapi-generator/src/main/resources/dart-dio/api_test.mustache b/modules/openapi-generator/src/main/resources/dart-dio/api_test.mustache new file mode 100644 index 00000000000..a89ed2d3995 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/dart-dio/api_test.mustache @@ -0,0 +1,29 @@ +import 'package:{{pubName}}/api.dart'; +import 'package:{{pubName}}/api/{{classFilename}}.dart'; +import 'package:test/test.dart'; + +{{#operations}} + +/// tests for {{{classname}}} +void main() { + final instance = {{{clientName}}}().get{{{classname}}}(); + + group({{{classname}}}, () { + {{#operation}} + {{#summary}} + // {{{.}}} + // + {{/summary}} + {{#notes}} + // {{{.}}} + // + {{/notes}} + //{{#returnType}}Future<{{{returnType}}}> {{/returnType}}{{^returnType}}Future {{/returnType}}{{{operationId}}}({{#allParams}}{{#required}}{{{dataType}}} {{{paramName}}}{{^-last}}, {{/-last}}{{/required}}{{/allParams}}{{#hasOptionalParams}}{ {{#allParams}}{{^required}}{{{dataType}}} {{{paramName}}}{{^-last}}, {{/-last}}{{/required}}{{/allParams}} }{{/hasOptionalParams}}) async + test('test {{{operationId}}}', () async { + // TODO + }); + + {{/operation}} + }); +} +{{/operations}} diff --git a/modules/openapi-generator/src/main/resources/dart-dio/model_test.mustache b/modules/openapi-generator/src/main/resources/dart-dio/model_test.mustache new file mode 100644 index 00000000000..0afdb340155 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/dart-dio/model_test.mustache @@ -0,0 +1,28 @@ +{{#models}} +{{#model}} +import 'package:{{pubName}}/model/{{classFilename}}.dart'; +import 'package:test/test.dart'; + +// tests for {{{classname}}} +void main() { + {{^isEnum}} + final instance = {{{classname}}}(); + {{/isEnum}} + + group({{{classname}}}, () { + {{#vars}} + {{#description}} + // {{{description}}} + {{/description}} + // {{{dataType}}} {{{name}}}{{#defaultValue}} (default value: {{{.}}}){{/defaultValue}} + test('to test the property `{{{name}}}`', () async { + // TODO + }); + + {{/vars}} + + }); + +} +{{/model}} +{{/models}} diff --git a/modules/openapi-generator/src/main/resources/dart-dio/pubspec.mustache b/modules/openapi-generator/src/main/resources/dart-dio/pubspec.mustache index fe1bfa2d545..c7e8bfd75f7 100644 --- a/modules/openapi-generator/src/main/resources/dart-dio/pubspec.mustache +++ b/modules/openapi-generator/src/main/resources/dart-dio/pubspec.mustache @@ -13,4 +13,5 @@ dependencies: dev_dependencies: built_value_generator: ^7.1.0 build_runner: ^1.7.1 + test: ^1.3.0 diff --git a/samples/client/petstore/dart-dio/.gitignore b/samples/client/petstore/dart-dio/.gitignore index 8092a49d515..f8005b318fe 100644 --- a/samples/client/petstore/dart-dio/.gitignore +++ b/samples/client/petstore/dart-dio/.gitignore @@ -27,6 +27,9 @@ doc/api/ # (Library packages only! Remove pattern if developing an application package) pubspec.lock +# Don't commit *.g.dart files which are genrated during integration tests +lib/**/*.g.dart + # Don’t commit files and directories created by other development environments. # For example, if your development environment creates any of the following files, # consider putting them in a global ignore file: diff --git a/samples/client/petstore/dart-dio/.openapi-generator-ignore b/samples/client/petstore/dart-dio/.openapi-generator-ignore index 7484ee590a3..911312f6da9 100644 --- a/samples/client/petstore/dart-dio/.openapi-generator-ignore +++ b/samples/client/petstore/dart-dio/.openapi-generator-ignore @@ -21,3 +21,6 @@ #docs/*.md # Then explicitly reverse the ignore rule for a single file: #!docs/README.md + +# Don't regenerate .gitignore as it contains customizations for generated dart files +.gitignore diff --git a/samples/client/petstore/dart-dio/.openapi-generator/FILES b/samples/client/petstore/dart-dio/.openapi-generator/FILES index b14eb44e2a0..e9358a18c39 100644 --- a/samples/client/petstore/dart-dio/.openapi-generator/FILES +++ b/samples/client/petstore/dart-dio/.openapi-generator/FILES @@ -1,4 +1,3 @@ -.gitignore README.md analysis_options.yaml doc/ApiResponse.md diff --git a/samples/client/petstore/dart-dio/pom.xml b/samples/client/petstore/dart-dio/pom.xml new file mode 100644 index 00000000000..de74393ce9e --- /dev/null +++ b/samples/client/petstore/dart-dio/pom.xml @@ -0,0 +1,88 @@ +<project> + <modelVersion>4.0.0</modelVersion> + <groupId>org.openapitools</groupId> + <artifactId>DartDioPetstoreClientTests</artifactId> + <packaging>pom</packaging> + <version>1.0.0-SNAPSHOT</version> + <name>DartDio Petstore Client</name> + <build> + <plugins> + <plugin> + <artifactId>maven-dependency-plugin</artifactId> + <executions> + <execution> + <phase>package</phase> + <goals> + <goal>copy-dependencies</goal> + </goals> + <configuration> + <outputDirectory>${project.build.directory}</outputDirectory> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>exec-maven-plugin</artifactId> + <version>1.2.1</version> + <executions> + <execution> + <id>export-dartfmt</id> + <phase>pre-install-test</phase> + <goals> + <goal>exec</goal> + </goals> + <configuration> + <executable>export</executable> + <arguments> + <argument>DART_FMT_PATH=/usr/local/bin/dartfmt</argument> + </arguments> + </configuration> + </execution> + <execution> + <id>pub-get</id> + <phase>pre-integration-test</phase> + <goals> + <goal>exec</goal> + </goals> + <configuration> + <executable>pub</executable> + <arguments> + <argument>get</argument> + </arguments> + </configuration> + </execution> + <execution> + <id>pub-run-build-runner</id> + <phase>pre-integration-test</phase> + <goals> + <goal>exec</goal> + </goals> + <configuration> + <executable>pub</executable> + <arguments> + <argument>run</argument> + <argument>build_runner</argument> + <argument>build</argument> + </arguments> + </configuration> + </execution> + <execution> + <id>pub-test</id> + <phase>integration-test</phase> + <goals> + <goal>exec</goal> + </goals> + <configuration> + <executable>pub</executable> + <arguments> + <argument>run</argument> + <argument>test</argument> + </arguments> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> diff --git a/samples/client/petstore/dart-dio/pubspec.yaml b/samples/client/petstore/dart-dio/pubspec.yaml index 92cbb8255c5..20b190aa1d3 100644 --- a/samples/client/petstore/dart-dio/pubspec.yaml +++ b/samples/client/petstore/dart-dio/pubspec.yaml @@ -10,4 +10,5 @@ dependencies: dev_dependencies: built_value_generator: ^7.1.0 build_runner: ^1.7.1 + test: ^1.3.0 diff --git a/samples/client/petstore/dart-dio/test/api_response_test.dart b/samples/client/petstore/dart-dio/test/api_response_test.dart new file mode 100644 index 00000000000..d80b2976160 --- /dev/null +++ b/samples/client/petstore/dart-dio/test/api_response_test.dart @@ -0,0 +1,27 @@ +import 'package:openapi/model/api_response.dart'; +import 'package:test/test.dart'; + +// tests for ApiResponse +void main() { + final instance = ApiResponse(); + + group(ApiResponse, () { + // int code (default value: null) + test('to test the property `code`', () async { + // TODO + }); + + // String type (default value: null) + test('to test the property `type`', () async { + // TODO + }); + + // String message (default value: null) + test('to test the property `message`', () async { + // TODO + }); + + + }); + +} diff --git a/samples/client/petstore/dart-dio/test/category_test.dart b/samples/client/petstore/dart-dio/test/category_test.dart new file mode 100644 index 00000000000..571e020bf63 --- /dev/null +++ b/samples/client/petstore/dart-dio/test/category_test.dart @@ -0,0 +1,22 @@ +import 'package:openapi/model/category.dart'; +import 'package:test/test.dart'; + +// tests for Category +void main() { + final instance = Category(); + + group(Category, () { + // int id (default value: null) + test('to test the property `id`', () async { + // TODO + }); + + // String name (default value: null) + test('to test the property `name`', () async { + // TODO + }); + + + }); + +} diff --git a/samples/client/petstore/dart-dio/test/order_test.dart b/samples/client/petstore/dart-dio/test/order_test.dart new file mode 100644 index 00000000000..ea9ac6e14eb --- /dev/null +++ b/samples/client/petstore/dart-dio/test/order_test.dart @@ -0,0 +1,43 @@ +import 'package:openapi/model/order.dart'; +import 'package:test/test.dart'; + +// tests for Order +void main() { + final instance = Order(); + + group(Order, () { + // int id (default value: null) + test('to test the property `id`', () async { + // TODO + }); + + // int petId (default value: null) + test('to test the property `petId`', () async { + // TODO + }); + + // int quantity (default value: null) + test('to test the property `quantity`', () async { + // TODO + }); + + // DateTime shipDate (default value: null) + test('to test the property `shipDate`', () async { + // TODO + }); + + // Order Status + // String status (default value: null) + test('to test the property `status`', () async { + // TODO + }); + + // bool complete (default value: false) + test('to test the property `complete`', () async { + // TODO + }); + + + }); + +} diff --git a/samples/client/petstore/dart-dio/test/pet_api_test.dart b/samples/client/petstore/dart-dio/test/pet_api_test.dart new file mode 100644 index 00000000000..96c8b9e1c1a --- /dev/null +++ b/samples/client/petstore/dart-dio/test/pet_api_test.dart @@ -0,0 +1,74 @@ +import 'package:openapi/api.dart'; +import 'package:openapi/api/pet_api.dart'; +import 'package:test/test.dart'; + + +/// tests for PetApi +void main() { + final instance = Openapi().getPetApi(); + + group(PetApi, () { + // Add a new pet to the store + // + //Future addPet(Pet body) async + test('test addPet', () async { + // TODO + }); + + // Deletes a pet + // + //Future deletePet(int petId, { String apiKey }) async + test('test deletePet', () async { + // TODO + }); + + // Finds Pets by status + // + // Multiple status values can be provided with comma separated strings + // + //Future<List<Pet>> findPetsByStatus(List<String> status) async + test('test findPetsByStatus', () async { + // TODO + }); + + // Finds Pets by tags + // + // Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + // + //Future<List<Pet>> findPetsByTags(List<String> tags) async + test('test findPetsByTags', () async { + // TODO + }); + + // Find pet by ID + // + // Returns a single pet + // + //Future<Pet> getPetById(int petId) async + test('test getPetById', () async { + // TODO + }); + + // Update an existing pet + // + //Future updatePet(Pet body) async + test('test updatePet', () async { + // TODO + }); + + // Updates a pet in the store with form data + // + //Future updatePetWithForm(int petId, { String name, String status }) async + test('test updatePetWithForm', () async { + // TODO + }); + + // uploads an image + // + //Future<ApiResponse> uploadFile(int petId, { String additionalMetadata, Uint8List file }) async + test('test uploadFile', () async { + // TODO + }); + + }); +} diff --git a/samples/client/petstore/dart-dio/test/pet_test.dart b/samples/client/petstore/dart-dio/test/pet_test.dart new file mode 100644 index 00000000000..63cfc070e93 --- /dev/null +++ b/samples/client/petstore/dart-dio/test/pet_test.dart @@ -0,0 +1,43 @@ +import 'package:openapi/model/pet.dart'; +import 'package:test/test.dart'; + +// tests for Pet +void main() { + final instance = Pet(); + + group(Pet, () { + // int id (default value: null) + test('to test the property `id`', () async { + // TODO + }); + + // Category category (default value: null) + test('to test the property `category`', () async { + // TODO + }); + + // String name (default value: null) + test('to test the property `name`', () async { + // TODO + }); + + // BuiltList<String> photoUrls (default value: const []) + test('to test the property `photoUrls`', () async { + // TODO + }); + + // BuiltList<Tag> tags (default value: const []) + test('to test the property `tags`', () async { + // TODO + }); + + // pet status in the store + // String status (default value: null) + test('to test the property `status`', () async { + // TODO + }); + + + }); + +} diff --git a/samples/client/petstore/dart-dio/test/store_api_test.dart b/samples/client/petstore/dart-dio/test/store_api_test.dart new file mode 100644 index 00000000000..92d2ff0f5b6 --- /dev/null +++ b/samples/client/petstore/dart-dio/test/store_api_test.dart @@ -0,0 +1,46 @@ +import 'package:openapi/api.dart'; +import 'package:openapi/api/store_api.dart'; +import 'package:test/test.dart'; + + +/// tests for StoreApi +void main() { + final instance = Openapi().getStoreApi(); + + group(StoreApi, () { + // Delete purchase order by ID + // + // For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + // + //Future deleteOrder(String orderId) async + test('test deleteOrder', () async { + // TODO + }); + + // Returns pet inventories by status + // + // Returns a map of status codes to quantities + // + //Future<Map<String, int>> getInventory() async + test('test getInventory', () async { + // TODO + }); + + // Find purchase order by ID + // + // For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + // + //Future<Order> getOrderById(int orderId) async + test('test getOrderById', () async { + // TODO + }); + + // Place an order for a pet + // + //Future<Order> placeOrder(Order body) async + test('test placeOrder', () async { + // TODO + }); + + }); +} diff --git a/samples/client/petstore/dart-dio/test/tag_test.dart b/samples/client/petstore/dart-dio/test/tag_test.dart new file mode 100644 index 00000000000..c2757a71863 --- /dev/null +++ b/samples/client/petstore/dart-dio/test/tag_test.dart @@ -0,0 +1,22 @@ +import 'package:openapi/model/tag.dart'; +import 'package:test/test.dart'; + +// tests for Tag +void main() { + final instance = Tag(); + + group(Tag, () { + // int id (default value: null) + test('to test the property `id`', () async { + // TODO + }); + + // String name (default value: null) + test('to test the property `name`', () async { + // TODO + }); + + + }); + +} diff --git a/samples/client/petstore/dart-dio/test/user_api_test.dart b/samples/client/petstore/dart-dio/test/user_api_test.dart new file mode 100644 index 00000000000..618e8a94f89 --- /dev/null +++ b/samples/client/petstore/dart-dio/test/user_api_test.dart @@ -0,0 +1,74 @@ +import 'package:openapi/api.dart'; +import 'package:openapi/api/user_api.dart'; +import 'package:test/test.dart'; + + +/// tests for UserApi +void main() { + final instance = Openapi().getUserApi(); + + group(UserApi, () { + // Create user + // + // This can only be done by the logged in user. + // + //Future createUser(User body) async + test('test createUser', () async { + // TODO + }); + + // Creates list of users with given input array + // + //Future createUsersWithArrayInput(List<User> body) async + test('test createUsersWithArrayInput', () async { + // TODO + }); + + // Creates list of users with given input array + // + //Future createUsersWithListInput(List<User> body) async + test('test createUsersWithListInput', () async { + // TODO + }); + + // Delete user + // + // This can only be done by the logged in user. + // + //Future deleteUser(String username) async + test('test deleteUser', () async { + // TODO + }); + + // Get user by user name + // + //Future<User> getUserByName(String username) async + test('test getUserByName', () async { + // TODO + }); + + // Logs user into the system + // + //Future<String> loginUser(String username, String password) async + test('test loginUser', () async { + // TODO + }); + + // Logs out current logged in user session + // + //Future logoutUser() async + test('test logoutUser', () async { + // TODO + }); + + // Updated user + // + // This can only be done by the logged in user. + // + //Future updateUser(String username, User body) async + test('test updateUser', () async { + // TODO + }); + + }); +} diff --git a/samples/client/petstore/dart-dio/test/user_test.dart b/samples/client/petstore/dart-dio/test/user_test.dart new file mode 100644 index 00000000000..b598e7f7fef --- /dev/null +++ b/samples/client/petstore/dart-dio/test/user_test.dart @@ -0,0 +1,53 @@ +import 'package:openapi/model/user.dart'; +import 'package:test/test.dart'; + +// tests for User +void main() { + final instance = User(); + + group(User, () { + // int id (default value: null) + test('to test the property `id`', () async { + // TODO + }); + + // String username (default value: null) + test('to test the property `username`', () async { + // TODO + }); + + // String firstName (default value: null) + test('to test the property `firstName`', () async { + // TODO + }); + + // String lastName (default value: null) + test('to test the property `lastName`', () async { + // TODO + }); + + // String email (default value: null) + test('to test the property `email`', () async { + // TODO + }); + + // String password (default value: null) + test('to test the property `password`', () async { + // TODO + }); + + // String phone (default value: null) + test('to test the property `phone`', () async { + // TODO + }); + + // User Status + // int userStatus (default value: null) + test('to test the property `userStatus`', () async { + // TODO + }); + + + }); + +} -- GitLab From 996b9b9de618a1c0d3465c70c8cfd85a0ed95574 Mon Sep 17 00:00:00 2001 From: Peter Leibiger <kuhnroyal@gmail.com> Date: Wed, 25 Nov 2020 16:51:57 +0100 Subject: [PATCH 2/5] [dart-dio] Fix missing BuiltSet import in models that use enums --- .../codegen/languages/DartDioClientCodegen.java | 8 ++++++-- samples/client/petstore/dart-dio/lib/model/order.dart | 1 + 2 files changed, 7 insertions(+), 2 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 9e04bfefa45..2d0a3ae0cb7 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 @@ -84,6 +84,7 @@ public class DartDioClientCodegen extends DartClientCodegen { typeMapping.put("AnyType", "Object"); importMapping.put("BuiltList", "package:built_collection/built_collection.dart"); + importMapping.put("BuiltSet", "package:built_collection/built_collection.dart"); importMapping.put("BuiltMap", "package:built_collection/built_collection.dart"); importMapping.put("JsonObject", "package:built_value/json_object.dart"); importMapping.put("Uint8List", "dart:typed_data"); @@ -105,7 +106,6 @@ public class DartDioClientCodegen extends DartClientCodegen { this.nullableFields = nullableFields; } - @Override public String getName() { return "dart-dio"; @@ -312,6 +312,11 @@ public class DartDioClientCodegen extends DartClientCodegen { if (property.dataType.contains("JsonObject")) { model.imports.add("JsonObject"); } + + if (property.isEnum) { + // enums are generated with built_value and make use of BuiltSet + model.imports.add("BuiltSet"); + } } @Override @@ -374,5 +379,4 @@ public class DartDioClientCodegen extends DartClientCodegen { return objs; } - } diff --git a/samples/client/petstore/dart-dio/lib/model/order.dart b/samples/client/petstore/dart-dio/lib/model/order.dart index d817bec8360..3931fb9d72b 100644 --- a/samples/client/petstore/dart-dio/lib/model/order.dart +++ b/samples/client/petstore/dart-dio/lib/model/order.dart @@ -1,3 +1,4 @@ + import 'package:built_collection/built_collection.dart'; import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; -- GitLab From 653f20729b017a2ddbbf98c7ed29bc257f46ff8a Mon Sep 17 00:00:00 2001 From: Peter Leibiger <kuhnroyal@gmail.com> Date: Wed, 25 Nov 2020 18:04:06 +0100 Subject: [PATCH 3/5] [dart-dio] Fix compile error when the return type is a Map * the compile error was `serializerForType(Map<String, int>)` in `StoreApi` which needs to be `serializerForType(Map)` * use final instead of var in response handling --- .../src/main/resources/dart-dio/api.mustache | 25 +++++++++++-------- .../petstore/dart-dio/lib/api/pet_api.dart | 20 +++++++-------- .../petstore/dart-dio/lib/api/store_api.dart | 12 ++++----- .../petstore/dart-dio/lib/api/user_api.dart | 8 +++--- 4 files changed, 35 insertions(+), 30 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/dart-dio/api.mustache b/modules/openapi-generator/src/main/resources/dart-dio/api.mustache index 0f1d1fca5f6..4964983f776 100644 --- a/modules/openapi-generator/src/main/resources/dart-dio/api.mustache +++ b/modules/openapi-generator/src/main/resources/dart-dio/api.mustache @@ -95,18 +95,23 @@ class {{classname}} { ){{#returnType}}.then((response) { {{#isResponseFile}} - var data = response.data; + final data = response.data; {{/isResponseFile}} {{^isResponseFile}} - {{#isArray}} - final FullType type = const FullType(BuiltList, const [const FullType({{returnBaseType}})]); - BuiltList<{{returnBaseType}}> dataList = _serializers.deserialize(response.data is String ? jsonDecode(response.data) : response.data, specifiedType: type); - var data = dataList.toList(); - {{/isArray}} - {{^isArray}} - var serializer = _serializers.serializerForType({{{returnType}}}); - var data = _serializers.deserializeWith<{{{returnType}}}>(serializer, response.data is String ? jsonDecode(response.data) : response.data); - {{/isArray}} + {{#isArray}} + final FullType type = const FullType(BuiltList, const [const FullType({{returnBaseType}})]); + final BuiltList<{{returnBaseType}}> dataList = _serializers.deserialize(response.data is String ? jsonDecode(response.data) : response.data, specifiedType: type); + final data = dataList.toList(); + {{/isArray}} + {{^isArray}} + {{#isMap}} + final serializer = _serializers.serializerForType(Map); + {{/isMap}} + {{^isMap}} + final serializer = _serializers.serializerForType({{{returnType}}}); + {{/isMap}} + final data = _serializers.deserializeWith<{{{returnType}}}>(serializer, response.data is String ? jsonDecode(response.data) : response.data); + {{/isArray}} {{/isResponseFile}} return Response<{{{returnType}}}>( diff --git a/samples/client/petstore/dart-dio/lib/api/pet_api.dart b/samples/client/petstore/dart-dio/lib/api/pet_api.dart index 7d714d1ddc3..ffac6cdde3e 100644 --- a/samples/client/petstore/dart-dio/lib/api/pet_api.dart +++ b/samples/client/petstore/dart-dio/lib/api/pet_api.dart @@ -126,9 +126,9 @@ class PetApi { onReceiveProgress: onReceiveProgress, ).then((response) { - final FullType type = const FullType(BuiltList, const [const FullType(Pet)]); - BuiltList<Pet> dataList = _serializers.deserialize(response.data is String ? jsonDecode(response.data) : response.data, specifiedType: type); - var data = dataList.toList(); + final FullType type = const FullType(BuiltList, const [const FullType(Pet)]); + final BuiltList<Pet> dataList = _serializers.deserialize(response.data is String ? jsonDecode(response.data) : response.data, specifiedType: type); + final data = dataList.toList(); return Response<List<Pet>>( data: data, @@ -177,9 +177,9 @@ class PetApi { onReceiveProgress: onReceiveProgress, ).then((response) { - final FullType type = const FullType(BuiltList, const [const FullType(Pet)]); - BuiltList<Pet> dataList = _serializers.deserialize(response.data is String ? jsonDecode(response.data) : response.data, specifiedType: type); - var data = dataList.toList(); + final FullType type = const FullType(BuiltList, const [const FullType(Pet)]); + final BuiltList<Pet> dataList = _serializers.deserialize(response.data is String ? jsonDecode(response.data) : response.data, specifiedType: type); + final data = dataList.toList(); return Response<List<Pet>>( data: data, @@ -227,8 +227,8 @@ class PetApi { onReceiveProgress: onReceiveProgress, ).then((response) { - var serializer = _serializers.serializerForType(Pet); - var data = _serializers.deserializeWith<Pet>(serializer, response.data is String ? jsonDecode(response.data) : response.data); + final serializer = _serializers.serializerForType(Pet); + final data = _serializers.deserializeWith<Pet>(serializer, response.data is String ? jsonDecode(response.data) : response.data); return Response<Pet>( data: data, @@ -361,8 +361,8 @@ class PetApi { onReceiveProgress: onReceiveProgress, ).then((response) { - var serializer = _serializers.serializerForType(ApiResponse); - var data = _serializers.deserializeWith<ApiResponse>(serializer, response.data is String ? jsonDecode(response.data) : response.data); + final serializer = _serializers.serializerForType(ApiResponse); + final data = _serializers.deserializeWith<ApiResponse>(serializer, response.data is String ? jsonDecode(response.data) : response.data); return Response<ApiResponse>( data: data, diff --git a/samples/client/petstore/dart-dio/lib/api/store_api.dart b/samples/client/petstore/dart-dio/lib/api/store_api.dart index f12cce29910..8d915410e71 100644 --- a/samples/client/petstore/dart-dio/lib/api/store_api.dart +++ b/samples/client/petstore/dart-dio/lib/api/store_api.dart @@ -83,8 +83,8 @@ class StoreApi { onReceiveProgress: onReceiveProgress, ).then((response) { - var serializer = _serializers.serializerForType(Map<String, int>); - var data = _serializers.deserializeWith<Map<String, int>>(serializer, response.data is String ? jsonDecode(response.data) : response.data); + final serializer = _serializers.serializerForType(Map); + final data = _serializers.deserializeWith<Map<String, int>>(serializer, response.data is String ? jsonDecode(response.data) : response.data); return Response<Map<String, int>>( data: data, @@ -132,8 +132,8 @@ class StoreApi { onReceiveProgress: onReceiveProgress, ).then((response) { - var serializer = _serializers.serializerForType(Order); - var data = _serializers.deserializeWith<Order>(serializer, response.data is String ? jsonDecode(response.data) : response.data); + final serializer = _serializers.serializerForType(Order); + final data = _serializers.deserializeWith<Order>(serializer, response.data is String ? jsonDecode(response.data) : response.data); return Response<Order>( data: data, @@ -184,8 +184,8 @@ class StoreApi { onReceiveProgress: onReceiveProgress, ).then((response) { - var serializer = _serializers.serializerForType(Order); - var data = _serializers.deserializeWith<Order>(serializer, response.data is String ? jsonDecode(response.data) : response.data); + final serializer = _serializers.serializerForType(Order); + final data = _serializers.deserializeWith<Order>(serializer, response.data is String ? jsonDecode(response.data) : response.data); return Response<Order>( data: data, diff --git a/samples/client/petstore/dart-dio/lib/api/user_api.dart b/samples/client/petstore/dart-dio/lib/api/user_api.dart index f043b6855a8..f70b829cfd4 100644 --- a/samples/client/petstore/dart-dio/lib/api/user_api.dart +++ b/samples/client/petstore/dart-dio/lib/api/user_api.dart @@ -199,8 +199,8 @@ class UserApi { onReceiveProgress: onReceiveProgress, ).then((response) { - var serializer = _serializers.serializerForType(User); - var data = _serializers.deserializeWith<User>(serializer, response.data is String ? jsonDecode(response.data) : response.data); + final serializer = _serializers.serializerForType(User); + final data = _serializers.deserializeWith<User>(serializer, response.data is String ? jsonDecode(response.data) : response.data); return Response<User>( data: data, @@ -250,8 +250,8 @@ class UserApi { onReceiveProgress: onReceiveProgress, ).then((response) { - var serializer = _serializers.serializerForType(String); - var data = _serializers.deserializeWith<String>(serializer, response.data is String ? jsonDecode(response.data) : response.data); + final serializer = _serializers.serializerForType(String); + final data = _serializers.deserializeWith<String>(serializer, response.data is String ? jsonDecode(response.data) : response.data); return Response<String>( data: data, -- GitLab From 95fb197525af985cc67595ba5e02c9f8047cc28c Mon Sep 17 00:00:00 2001 From: Peter Leibiger <kuhnroyal@gmail.com> Date: Wed, 25 Nov 2020 19:11:24 +0100 Subject: [PATCH 4/5] [dart-dio] Generate docs after changes --- docs/generators/dart-dio.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/generators/dart-dio.md b/docs/generators/dart-dio.md index f10e875630a..eb46e2522a3 100644 --- a/docs/generators/dart-dio.md +++ b/docs/generators/dart-dio.md @@ -32,6 +32,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl | ---------- | ------- | |BuiltList|package:built_collection/built_collection.dart| |BuiltMap|package:built_collection/built_collection.dart| +|BuiltSet|package:built_collection/built_collection.dart| |JsonObject|package:built_value/json_object.dart| |Uint8List|dart:typed_data| -- GitLab From 04b34c59a4fe59588bd534fe786e11ace24c63cf Mon Sep 17 00:00:00 2001 From: Peter Leibiger <kuhnroyal@gmail.com> Date: Wed, 2 Dec 2020 12:39:16 +0100 Subject: [PATCH 5/5] [dart-dio] Add integration test to CI execution list --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index 18602dffd2e..14c22234600 100644 --- a/pom.xml +++ b/pom.xml @@ -1350,6 +1350,7 @@ <module>samples/server/petstore/go-api-server</module> <module>samples/server/petstore/go-gin-api-server</module> <module>samples/client/petstore/dart2/petstore</module> + <module>samples/client/petstore/dart-dio</module> <module>samples/client/petstore/dart-jaguar/openapi</module> <module>samples/client/petstore/dart-jaguar/flutter_petstore/openapi</module> </modules> -- GitLab