From 464eb0ab8542c9f6b7b3191046b354c7d8e44542 Mon Sep 17 00:00:00 2001 From: austbot Date: Fri, 6 Sep 2019 15:24:22 -0500 Subject: [PATCH] Adds Http Info To Dart Api --- .../src/main/resources/dart2/api.mustache | 12 ++- .../dart2/openapi/lib/api/pet_api.dart | 96 +++++++++++++++---- .../dart2/openapi/lib/api/store_api.dart | 48 ++++++++-- .../dart2/openapi/lib/api/user_api.dart | 96 +++++++++++++++---- 4 files changed, 210 insertions(+), 42 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/dart2/api.mustache b/modules/openapi-generator/src/main/resources/dart2/api.mustache index 9ecac421b67d..c5acc6314dfc 100644 --- a/modules/openapi-generator/src/main/resources/dart2/api.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/api.mustache @@ -9,10 +9,10 @@ class {{classname}} { {{classname}}([ApiClient apiClient]) : apiClient = apiClient ?? defaultApiClient; {{#operation}} - /// {{summary}} + /// {{summary}} with HTTP info returned /// /// {{notes}} - {{#returnType}}Future<{{{returnType}}}> {{/returnType}}{{^returnType}}Future {{/returnType}}{{nickname}}({{#allParams}}{{#required}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/required}}{{/allParams}}{{#hasOptionalParams}}{ {{#allParams}}{{^required}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/required}}{{/allParams}} }{{/hasOptionalParams}}) async { + {{#returnType}}Future {{/returnType}}{{^returnType}}Future {{/returnType}}{{nickname}}WithHttpInfo({{#allParams}}{{#required}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/required}}{{/allParams}}{{#hasOptionalParams}}{ {{#allParams}}{{^required}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/required}}{{/allParams}} }{{/hasOptionalParams}}) async { Object postBody{{#bodyParam}} = {{paramName}}{{/bodyParam}}; // verify required params are set @@ -87,7 +87,14 @@ class {{classname}} { formParams, contentType, authNames); + return response; + } + /// {{summary}} + /// + /// {{notes}} + {{#returnType}}Future<{{{returnType}}}> {{/returnType}}{{^returnType}}Future {{/returnType}}{{nickname}}({{#allParams}}{{#required}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/required}}{{/allParams}}{{#hasOptionalParams}}{ {{#allParams}}{{^required}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/required}}{{/allParams}} }{{/hasOptionalParams}}) async { + Response response = await {{nickname}}WithHttpInfo({{#allParams}}{{#required}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/required}}{{/allParams}}{{#hasOptionalParams}} {{#allParams}}{{^required}}{{paramName}}: {{paramName}}{{#hasMore}}, {{/hasMore}}{{/required}}{{/allParams}} {{/hasOptionalParams}}); if(response.statusCode >= 400) { throw ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { @@ -112,6 +119,7 @@ class {{classname}} { return{{#returnType}} null{{/returnType}}; } } + {{/operation}} } {{/operations}} diff --git a/samples/client/petstore/dart2/openapi/lib/api/pet_api.dart b/samples/client/petstore/dart2/openapi/lib/api/pet_api.dart index 35416e655ede..2b00c7d63b73 100644 --- a/samples/client/petstore/dart2/openapi/lib/api/pet_api.dart +++ b/samples/client/petstore/dart2/openapi/lib/api/pet_api.dart @@ -7,10 +7,10 @@ class PetApi { PetApi([ApiClient apiClient]) : apiClient = apiClient ?? defaultApiClient; - /// Add a new pet to the store + /// Add a new pet to the store with HTTP info returned /// /// - Future addPet(Pet body) async { + Future addPetWithHttpInfo(Pet body) async { Object postBody = body; // verify required params are set @@ -48,7 +48,14 @@ class PetApi { formParams, contentType, authNames); + return response; + } + /// Add a new pet to the store + /// + /// + Future addPet(Pet body) async { + Response response = await addPetWithHttpInfo(body); if(response.statusCode >= 400) { throw ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { @@ -56,10 +63,11 @@ class PetApi { return; } } - /// Deletes a pet + + /// Deletes a pet with HTTP info returned /// /// - Future deletePet(int petId, { String apiKey }) async { + Future deletePetWithHttpInfo(int petId, { String apiKey }) async { Object postBody; // verify required params are set @@ -98,7 +106,14 @@ class PetApi { formParams, contentType, authNames); + return response; + } + /// Deletes a pet + /// + /// + Future deletePet(int petId, { String apiKey }) async { + Response response = await deletePetWithHttpInfo(petId, apiKey: apiKey ); if(response.statusCode >= 400) { throw ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { @@ -106,10 +121,11 @@ class PetApi { return; } } - /// Finds Pets by status + + /// Finds Pets by status with HTTP info returned /// /// Multiple status values can be provided with comma separated strings - Future> findPetsByStatus(List status) async { + Future findPetsByStatusWithHttpInfo(List status) async { Object postBody; // verify required params are set @@ -148,7 +164,14 @@ class PetApi { formParams, contentType, authNames); + return response; + } + /// Finds Pets by status + /// + /// Multiple status values can be provided with comma separated strings + Future> findPetsByStatus(List status) async { + Response response = await findPetsByStatusWithHttpInfo(status); if(response.statusCode >= 400) { throw ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { @@ -157,10 +180,11 @@ class PetApi { return null; } } - /// Finds Pets by tags + + /// Finds Pets by tags with HTTP info returned /// /// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. - Future> findPetsByTags(List tags) async { + Future findPetsByTagsWithHttpInfo(List tags) async { Object postBody; // verify required params are set @@ -199,7 +223,14 @@ class PetApi { formParams, contentType, authNames); + return response; + } + /// Finds Pets by tags + /// + /// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + Future> findPetsByTags(List tags) async { + Response response = await findPetsByTagsWithHttpInfo(tags); if(response.statusCode >= 400) { throw ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { @@ -208,10 +239,11 @@ class PetApi { return null; } } - /// Find pet by ID + + /// Find pet by ID with HTTP info returned /// /// Returns a single pet - Future getPetById(int petId) async { + Future getPetByIdWithHttpInfo(int petId) async { Object postBody; // verify required params are set @@ -249,7 +281,14 @@ class PetApi { formParams, contentType, authNames); + return response; + } + /// Find pet by ID + /// + /// Returns a single pet + Future getPetById(int petId) async { + Response response = await getPetByIdWithHttpInfo(petId); if(response.statusCode >= 400) { throw ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { @@ -258,10 +297,11 @@ class PetApi { return null; } } - /// Update an existing pet + + /// Update an existing pet with HTTP info returned /// /// - Future updatePet(Pet body) async { + Future updatePetWithHttpInfo(Pet body) async { Object postBody = body; // verify required params are set @@ -299,7 +339,14 @@ class PetApi { formParams, contentType, authNames); + return response; + } + /// Update an existing pet + /// + /// + Future updatePet(Pet body) async { + Response response = await updatePetWithHttpInfo(body); if(response.statusCode >= 400) { throw ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { @@ -307,10 +354,11 @@ class PetApi { return; } } - /// Updates a pet in the store with form data + + /// Updates a pet in the store with form data with HTTP info returned /// /// - Future updatePetWithForm(int petId, { String name, String status }) async { + Future updatePetWithFormWithHttpInfo(int petId, { String name, String status }) async { Object postBody; // verify required params are set @@ -360,7 +408,14 @@ class PetApi { formParams, contentType, authNames); + return response; + } + /// Updates a pet in the store with form data + /// + /// + Future updatePetWithForm(int petId, { String name, String status }) async { + Response response = await updatePetWithFormWithHttpInfo(petId, name: name, status: status ); if(response.statusCode >= 400) { throw ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { @@ -368,10 +423,11 @@ class PetApi { return; } } - /// uploads an image + + /// uploads an image with HTTP info returned /// /// - Future uploadFile(int petId, { String additionalMetadata, MultipartFile file }) async { + Future uploadFileWithHttpInfo(int petId, { String additionalMetadata, MultipartFile file }) async { Object postBody; // verify required params are set @@ -420,7 +476,14 @@ class PetApi { formParams, contentType, authNames); + return response; + } + /// uploads an image + /// + /// + Future uploadFile(int petId, { String additionalMetadata, MultipartFile file }) async { + Response response = await uploadFileWithHttpInfo(petId, additionalMetadata: additionalMetadata, file: file ); if(response.statusCode >= 400) { throw ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { @@ -429,4 +492,5 @@ class PetApi { return null; } } + } diff --git a/samples/client/petstore/dart2/openapi/lib/api/store_api.dart b/samples/client/petstore/dart2/openapi/lib/api/store_api.dart index 59e59725ec63..3b48cbbc4a3b 100644 --- a/samples/client/petstore/dart2/openapi/lib/api/store_api.dart +++ b/samples/client/petstore/dart2/openapi/lib/api/store_api.dart @@ -7,10 +7,10 @@ class StoreApi { StoreApi([ApiClient apiClient]) : apiClient = apiClient ?? defaultApiClient; - /// Delete purchase order by ID + /// Delete purchase order by ID with HTTP info returned /// /// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors - Future deleteOrder(String orderId) async { + Future deleteOrderWithHttpInfo(String orderId) async { Object postBody; // verify required params are set @@ -48,7 +48,14 @@ class StoreApi { formParams, contentType, authNames); + return response; + } + /// 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 { + Response response = await deleteOrderWithHttpInfo(orderId); if(response.statusCode >= 400) { throw ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { @@ -56,10 +63,11 @@ class StoreApi { return; } } - /// Returns pet inventories by status + + /// Returns pet inventories by status with HTTP info returned /// /// Returns a map of status codes to quantities - Future> getInventory() async { + Future getInventoryWithHttpInfo() async { Object postBody; // verify required params are set @@ -94,7 +102,14 @@ class StoreApi { formParams, contentType, authNames); + return response; + } + /// Returns pet inventories by status + /// + /// Returns a map of status codes to quantities + Future> getInventory() async { + Response response = await getInventoryWithHttpInfo(); if(response.statusCode >= 400) { throw ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { @@ -104,10 +119,11 @@ class StoreApi { return null; } } - /// Find purchase order by ID + + /// Find purchase order by ID with HTTP info returned /// /// For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions - Future getOrderById(int orderId) async { + Future getOrderByIdWithHttpInfo(int orderId) async { Object postBody; // verify required params are set @@ -145,7 +161,14 @@ class StoreApi { formParams, contentType, authNames); + return response; + } + /// Find purchase order by ID + /// + /// For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + Future getOrderById(int orderId) async { + Response response = await getOrderByIdWithHttpInfo(orderId); if(response.statusCode >= 400) { throw ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { @@ -154,10 +177,11 @@ class StoreApi { return null; } } - /// Place an order for a pet + + /// Place an order for a pet with HTTP info returned /// /// - Future placeOrder(Order body) async { + Future placeOrderWithHttpInfo(Order body) async { Object postBody = body; // verify required params are set @@ -195,7 +219,14 @@ class StoreApi { formParams, contentType, authNames); + return response; + } + /// Place an order for a pet + /// + /// + Future placeOrder(Order body) async { + Response response = await placeOrderWithHttpInfo(body); if(response.statusCode >= 400) { throw ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { @@ -204,4 +235,5 @@ class StoreApi { return null; } } + } diff --git a/samples/client/petstore/dart2/openapi/lib/api/user_api.dart b/samples/client/petstore/dart2/openapi/lib/api/user_api.dart index 475f0655b958..5a35ba394c08 100644 --- a/samples/client/petstore/dart2/openapi/lib/api/user_api.dart +++ b/samples/client/petstore/dart2/openapi/lib/api/user_api.dart @@ -7,10 +7,10 @@ class UserApi { UserApi([ApiClient apiClient]) : apiClient = apiClient ?? defaultApiClient; - /// Create user + /// Create user with HTTP info returned /// /// This can only be done by the logged in user. - Future createUser(User body) async { + Future createUserWithHttpInfo(User body) async { Object postBody = body; // verify required params are set @@ -48,7 +48,14 @@ class UserApi { formParams, contentType, authNames); + return response; + } + /// Create user + /// + /// This can only be done by the logged in user. + Future createUser(User body) async { + Response response = await createUserWithHttpInfo(body); if(response.statusCode >= 400) { throw ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { @@ -56,10 +63,11 @@ class UserApi { return; } } - /// Creates list of users with given input array + + /// Creates list of users with given input array with HTTP info returned /// /// - Future createUsersWithArrayInput(List body) async { + Future createUsersWithArrayInputWithHttpInfo(List body) async { Object postBody = body; // verify required params are set @@ -97,7 +105,14 @@ class UserApi { formParams, contentType, authNames); + return response; + } + /// Creates list of users with given input array + /// + /// + Future createUsersWithArrayInput(List body) async { + Response response = await createUsersWithArrayInputWithHttpInfo(body); if(response.statusCode >= 400) { throw ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { @@ -105,10 +120,11 @@ class UserApi { return; } } - /// Creates list of users with given input array + + /// Creates list of users with given input array with HTTP info returned /// /// - Future createUsersWithListInput(List body) async { + Future createUsersWithListInputWithHttpInfo(List body) async { Object postBody = body; // verify required params are set @@ -146,7 +162,14 @@ class UserApi { formParams, contentType, authNames); + return response; + } + /// Creates list of users with given input array + /// + /// + Future createUsersWithListInput(List body) async { + Response response = await createUsersWithListInputWithHttpInfo(body); if(response.statusCode >= 400) { throw ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { @@ -154,10 +177,11 @@ class UserApi { return; } } - /// Delete user + + /// Delete user with HTTP info returned /// /// This can only be done by the logged in user. - Future deleteUser(String username) async { + Future deleteUserWithHttpInfo(String username) async { Object postBody; // verify required params are set @@ -195,7 +219,14 @@ class UserApi { formParams, contentType, authNames); + return response; + } + /// Delete user + /// + /// This can only be done by the logged in user. + Future deleteUser(String username) async { + Response response = await deleteUserWithHttpInfo(username); if(response.statusCode >= 400) { throw ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { @@ -203,10 +234,11 @@ class UserApi { return; } } - /// Get user by user name + + /// Get user by user name with HTTP info returned /// /// - Future getUserByName(String username) async { + Future getUserByNameWithHttpInfo(String username) async { Object postBody; // verify required params are set @@ -244,7 +276,14 @@ class UserApi { formParams, contentType, authNames); + return response; + } + /// Get user by user name + /// + /// + Future getUserByName(String username) async { + Response response = await getUserByNameWithHttpInfo(username); if(response.statusCode >= 400) { throw ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { @@ -253,10 +292,11 @@ class UserApi { return null; } } - /// Logs user into the system + + /// Logs user into the system with HTTP info returned /// /// - Future loginUser(String username, String password) async { + Future loginUserWithHttpInfo(String username, String password) async { Object postBody; // verify required params are set @@ -299,7 +339,14 @@ class UserApi { formParams, contentType, authNames); + return response; + } + /// Logs user into the system + /// + /// + Future loginUser(String username, String password) async { + Response response = await loginUserWithHttpInfo(username, password); if(response.statusCode >= 400) { throw ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { @@ -308,10 +355,11 @@ class UserApi { return null; } } - /// Logs out current logged in user session + + /// Logs out current logged in user session with HTTP info returned /// /// - Future logoutUser() async { + Future logoutUserWithHttpInfo() async { Object postBody; // verify required params are set @@ -346,7 +394,14 @@ class UserApi { formParams, contentType, authNames); + return response; + } + /// Logs out current logged in user session + /// + /// + Future logoutUser() async { + Response response = await logoutUserWithHttpInfo(); if(response.statusCode >= 400) { throw ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { @@ -354,10 +409,11 @@ class UserApi { return; } } - /// Updated user + + /// Updated user with HTTP info returned /// /// This can only be done by the logged in user. - Future updateUser(String username, User body) async { + Future updateUserWithHttpInfo(String username, User body) async { Object postBody = body; // verify required params are set @@ -398,7 +454,14 @@ class UserApi { formParams, contentType, authNames); + return response; + } + /// Updated user + /// + /// This can only be done by the logged in user. + Future updateUser(String username, User body) async { + Response response = await updateUserWithHttpInfo(username, body); if(response.statusCode >= 400) { throw ApiException(response.statusCode, _decodeBodyBytes(response)); } else if(response.body != null) { @@ -406,4 +469,5 @@ class UserApi { return; } } + }