Skip to content

Commit 096f2d0

Browse files
austbotwing328
authored andcommitted
Adds Http Info To Dart Api (#3851)
1 parent 239d68d commit 096f2d0

File tree

4 files changed

+210
-42
lines changed

4 files changed

+210
-42
lines changed

modules/openapi-generator/src/main/resources/dart2/api.mustache

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ class {{classname}} {
99
{{classname}}([ApiClient apiClient]) : apiClient = apiClient ?? defaultApiClient;
1010

1111
{{#operation}}
12-
/// {{summary}}
12+
/// {{summary}} with HTTP info returned
1313
///
1414
/// {{notes}}
15-
{{#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 {
15+
{{#returnType}}Future<Response> {{/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 {
1616
Object postBody{{#bodyParam}} = {{paramName}}{{/bodyParam}};
1717

1818
// verify required params are set
@@ -87,7 +87,14 @@ class {{classname}} {
8787
formParams,
8888
contentType,
8989
authNames);
90+
return response;
91+
}
9092

93+
/// {{summary}}
94+
///
95+
/// {{notes}}
96+
{{#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 {
97+
Response response = await {{nickname}}WithHttpInfo({{#allParams}}{{#required}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/required}}{{/allParams}}{{#hasOptionalParams}} {{#allParams}}{{^required}}{{paramName}}: {{paramName}}{{#hasMore}}, {{/hasMore}}{{/required}}{{/allParams}} {{/hasOptionalParams}});
9198
if(response.statusCode >= 400) {
9299
throw ApiException(response.statusCode, _decodeBodyBytes(response));
93100
} else if(response.body != null) {
@@ -112,6 +119,7 @@ class {{classname}} {
112119
return{{#returnType}} null{{/returnType}};
113120
}
114121
}
122+
115123
{{/operation}}
116124
}
117125
{{/operations}}

samples/client/petstore/dart2/openapi/lib/api/pet_api.dart

Lines changed: 80 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ class PetApi {
77

88
PetApi([ApiClient apiClient]) : apiClient = apiClient ?? defaultApiClient;
99

10-
/// Add a new pet to the store
10+
/// Add a new pet to the store with HTTP info returned
1111
///
1212
///
13-
Future addPet(Pet body) async {
13+
Future addPetWithHttpInfo(Pet body) async {
1414
Object postBody = body;
1515

1616
// verify required params are set
@@ -48,18 +48,26 @@ class PetApi {
4848
formParams,
4949
contentType,
5050
authNames);
51+
return response;
52+
}
5153

54+
/// Add a new pet to the store
55+
///
56+
///
57+
Future addPet(Pet body) async {
58+
Response response = await addPetWithHttpInfo(body);
5259
if(response.statusCode >= 400) {
5360
throw ApiException(response.statusCode, _decodeBodyBytes(response));
5461
} else if(response.body != null) {
5562
} else {
5663
return;
5764
}
5865
}
59-
/// Deletes a pet
66+
67+
/// Deletes a pet with HTTP info returned
6068
///
6169
///
62-
Future deletePet(int petId, { String apiKey }) async {
70+
Future deletePetWithHttpInfo(int petId, { String apiKey }) async {
6371
Object postBody;
6472

6573
// verify required params are set
@@ -98,18 +106,26 @@ class PetApi {
98106
formParams,
99107
contentType,
100108
authNames);
109+
return response;
110+
}
101111

112+
/// Deletes a pet
113+
///
114+
///
115+
Future deletePet(int petId, { String apiKey }) async {
116+
Response response = await deletePetWithHttpInfo(petId, apiKey: apiKey );
102117
if(response.statusCode >= 400) {
103118
throw ApiException(response.statusCode, _decodeBodyBytes(response));
104119
} else if(response.body != null) {
105120
} else {
106121
return;
107122
}
108123
}
109-
/// Finds Pets by status
124+
125+
/// Finds Pets by status with HTTP info returned
110126
///
111127
/// Multiple status values can be provided with comma separated strings
112-
Future<List<Pet>> findPetsByStatus(List<String> status) async {
128+
Future<Response> findPetsByStatusWithHttpInfo(List<String> status) async {
113129
Object postBody;
114130

115131
// verify required params are set
@@ -148,7 +164,14 @@ class PetApi {
148164
formParams,
149165
contentType,
150166
authNames);
167+
return response;
168+
}
151169

170+
/// Finds Pets by status
171+
///
172+
/// Multiple status values can be provided with comma separated strings
173+
Future<List<Pet>> findPetsByStatus(List<String> status) async {
174+
Response response = await findPetsByStatusWithHttpInfo(status);
152175
if(response.statusCode >= 400) {
153176
throw ApiException(response.statusCode, _decodeBodyBytes(response));
154177
} else if(response.body != null) {
@@ -157,10 +180,11 @@ class PetApi {
157180
return null;
158181
}
159182
}
160-
/// Finds Pets by tags
183+
184+
/// Finds Pets by tags with HTTP info returned
161185
///
162186
/// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
163-
Future<List<Pet>> findPetsByTags(List<String> tags) async {
187+
Future<Response> findPetsByTagsWithHttpInfo(List<String> tags) async {
164188
Object postBody;
165189

166190
// verify required params are set
@@ -199,7 +223,14 @@ class PetApi {
199223
formParams,
200224
contentType,
201225
authNames);
226+
return response;
227+
}
202228

229+
/// Finds Pets by tags
230+
///
231+
/// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
232+
Future<List<Pet>> findPetsByTags(List<String> tags) async {
233+
Response response = await findPetsByTagsWithHttpInfo(tags);
203234
if(response.statusCode >= 400) {
204235
throw ApiException(response.statusCode, _decodeBodyBytes(response));
205236
} else if(response.body != null) {
@@ -208,10 +239,11 @@ class PetApi {
208239
return null;
209240
}
210241
}
211-
/// Find pet by ID
242+
243+
/// Find pet by ID with HTTP info returned
212244
///
213245
/// Returns a single pet
214-
Future<Pet> getPetById(int petId) async {
246+
Future<Response> getPetByIdWithHttpInfo(int petId) async {
215247
Object postBody;
216248

217249
// verify required params are set
@@ -249,7 +281,14 @@ class PetApi {
249281
formParams,
250282
contentType,
251283
authNames);
284+
return response;
285+
}
252286

287+
/// Find pet by ID
288+
///
289+
/// Returns a single pet
290+
Future<Pet> getPetById(int petId) async {
291+
Response response = await getPetByIdWithHttpInfo(petId);
253292
if(response.statusCode >= 400) {
254293
throw ApiException(response.statusCode, _decodeBodyBytes(response));
255294
} else if(response.body != null) {
@@ -258,10 +297,11 @@ class PetApi {
258297
return null;
259298
}
260299
}
261-
/// Update an existing pet
300+
301+
/// Update an existing pet with HTTP info returned
262302
///
263303
///
264-
Future updatePet(Pet body) async {
304+
Future updatePetWithHttpInfo(Pet body) async {
265305
Object postBody = body;
266306

267307
// verify required params are set
@@ -299,18 +339,26 @@ class PetApi {
299339
formParams,
300340
contentType,
301341
authNames);
342+
return response;
343+
}
302344

345+
/// Update an existing pet
346+
///
347+
///
348+
Future updatePet(Pet body) async {
349+
Response response = await updatePetWithHttpInfo(body);
303350
if(response.statusCode >= 400) {
304351
throw ApiException(response.statusCode, _decodeBodyBytes(response));
305352
} else if(response.body != null) {
306353
} else {
307354
return;
308355
}
309356
}
310-
/// Updates a pet in the store with form data
357+
358+
/// Updates a pet in the store with form data with HTTP info returned
311359
///
312360
///
313-
Future updatePetWithForm(int petId, { String name, String status }) async {
361+
Future updatePetWithFormWithHttpInfo(int petId, { String name, String status }) async {
314362
Object postBody;
315363

316364
// verify required params are set
@@ -360,18 +408,26 @@ class PetApi {
360408
formParams,
361409
contentType,
362410
authNames);
411+
return response;
412+
}
363413

414+
/// Updates a pet in the store with form data
415+
///
416+
///
417+
Future updatePetWithForm(int petId, { String name, String status }) async {
418+
Response response = await updatePetWithFormWithHttpInfo(petId, name: name, status: status );
364419
if(response.statusCode >= 400) {
365420
throw ApiException(response.statusCode, _decodeBodyBytes(response));
366421
} else if(response.body != null) {
367422
} else {
368423
return;
369424
}
370425
}
371-
/// uploads an image
426+
427+
/// uploads an image with HTTP info returned
372428
///
373429
///
374-
Future<ApiResponse> uploadFile(int petId, { String additionalMetadata, MultipartFile file }) async {
430+
Future<Response> uploadFileWithHttpInfo(int petId, { String additionalMetadata, MultipartFile file }) async {
375431
Object postBody;
376432

377433
// verify required params are set
@@ -420,7 +476,14 @@ class PetApi {
420476
formParams,
421477
contentType,
422478
authNames);
479+
return response;
480+
}
423481

482+
/// uploads an image
483+
///
484+
///
485+
Future<ApiResponse> uploadFile(int petId, { String additionalMetadata, MultipartFile file }) async {
486+
Response response = await uploadFileWithHttpInfo(petId, additionalMetadata: additionalMetadata, file: file );
424487
if(response.statusCode >= 400) {
425488
throw ApiException(response.statusCode, _decodeBodyBytes(response));
426489
} else if(response.body != null) {
@@ -429,4 +492,5 @@ class PetApi {
429492
return null;
430493
}
431494
}
495+
432496
}

samples/client/petstore/dart2/openapi/lib/api/store_api.dart

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ class StoreApi {
77

88
StoreApi([ApiClient apiClient]) : apiClient = apiClient ?? defaultApiClient;
99

10-
/// Delete purchase order by ID
10+
/// Delete purchase order by ID with HTTP info returned
1111
///
1212
/// For valid response try integer IDs with value &lt; 1000. Anything above 1000 or nonintegers will generate API errors
13-
Future deleteOrder(String orderId) async {
13+
Future deleteOrderWithHttpInfo(String orderId) async {
1414
Object postBody;
1515

1616
// verify required params are set
@@ -48,18 +48,26 @@ class StoreApi {
4848
formParams,
4949
contentType,
5050
authNames);
51+
return response;
52+
}
5153

54+
/// Delete purchase order by ID
55+
///
56+
/// For valid response try integer IDs with value &lt; 1000. Anything above 1000 or nonintegers will generate API errors
57+
Future deleteOrder(String orderId) async {
58+
Response response = await deleteOrderWithHttpInfo(orderId);
5259
if(response.statusCode >= 400) {
5360
throw ApiException(response.statusCode, _decodeBodyBytes(response));
5461
} else if(response.body != null) {
5562
} else {
5663
return;
5764
}
5865
}
59-
/// Returns pet inventories by status
66+
67+
/// Returns pet inventories by status with HTTP info returned
6068
///
6169
/// Returns a map of status codes to quantities
62-
Future<Map<String, int>> getInventory() async {
70+
Future<Response> getInventoryWithHttpInfo() async {
6371
Object postBody;
6472

6573
// verify required params are set
@@ -94,7 +102,14 @@ class StoreApi {
94102
formParams,
95103
contentType,
96104
authNames);
105+
return response;
106+
}
97107

108+
/// Returns pet inventories by status
109+
///
110+
/// Returns a map of status codes to quantities
111+
Future<Map<String, int>> getInventory() async {
112+
Response response = await getInventoryWithHttpInfo();
98113
if(response.statusCode >= 400) {
99114
throw ApiException(response.statusCode, _decodeBodyBytes(response));
100115
} else if(response.body != null) {
@@ -104,10 +119,11 @@ class StoreApi {
104119
return null;
105120
}
106121
}
107-
/// Find purchase order by ID
122+
123+
/// Find purchase order by ID with HTTP info returned
108124
///
109125
/// For valid response try integer IDs with value &lt;&#x3D; 5 or &gt; 10. Other values will generated exceptions
110-
Future<Order> getOrderById(int orderId) async {
126+
Future<Response> getOrderByIdWithHttpInfo(int orderId) async {
111127
Object postBody;
112128

113129
// verify required params are set
@@ -145,7 +161,14 @@ class StoreApi {
145161
formParams,
146162
contentType,
147163
authNames);
164+
return response;
165+
}
148166

167+
/// Find purchase order by ID
168+
///
169+
/// For valid response try integer IDs with value &lt;&#x3D; 5 or &gt; 10. Other values will generated exceptions
170+
Future<Order> getOrderById(int orderId) async {
171+
Response response = await getOrderByIdWithHttpInfo(orderId);
149172
if(response.statusCode >= 400) {
150173
throw ApiException(response.statusCode, _decodeBodyBytes(response));
151174
} else if(response.body != null) {
@@ -154,10 +177,11 @@ class StoreApi {
154177
return null;
155178
}
156179
}
157-
/// Place an order for a pet
180+
181+
/// Place an order for a pet with HTTP info returned
158182
///
159183
///
160-
Future<Order> placeOrder(Order body) async {
184+
Future<Response> placeOrderWithHttpInfo(Order body) async {
161185
Object postBody = body;
162186

163187
// verify required params are set
@@ -195,7 +219,14 @@ class StoreApi {
195219
formParams,
196220
contentType,
197221
authNames);
222+
return response;
223+
}
198224

225+
/// Place an order for a pet
226+
///
227+
///
228+
Future<Order> placeOrder(Order body) async {
229+
Response response = await placeOrderWithHttpInfo(body);
199230
if(response.statusCode >= 400) {
200231
throw ApiException(response.statusCode, _decodeBodyBytes(response));
201232
} else if(response.body != null) {
@@ -204,4 +235,5 @@ class StoreApi {
204235
return null;
205236
}
206237
}
238+
207239
}

0 commit comments

Comments
 (0)