Skip to content

Commit 8e1bb3d

Browse files
ludoo0d0awing328
authored andcommitted
[dart-dio] Fix basepath (#4911)
* Fix basepath * regenerate sample petstore
1 parent e675360 commit 8e1bb3d

File tree

6 files changed

+215
-200
lines changed

6 files changed

+215
-200
lines changed

modules/openapi-generator/src/main/resources/dart-dio/apilib.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class {{clientName}} {
1111
1212
Dio dio;
1313
Serializers serializers;
14-
String basePath = "http://petstore.swagger.io/v2";
14+
String basePath = "{{{basePath}}}";
1515
1616
{{clientName}}({this.dio, Serializers serializers}) {
1717
if (dio == null) {

samples/client/petstore/dart-dio/README.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -57,36 +57,36 @@ All URIs are relative to *http://petstore.swagger.io/v2*
5757

5858
Class | Method | HTTP request | Description
5959
------------ | ------------- | ------------- | -------------
60-
*PetApi* | [**addPet**](doc//PetApi.md#addpet) | **post** /pet | Add a new pet to the store
61-
*PetApi* | [**deletePet**](doc//PetApi.md#deletepet) | **delete** /pet/{petId} | Deletes a pet
62-
*PetApi* | [**findPetsByStatus**](doc//PetApi.md#findpetsbystatus) | **get** /pet/findByStatus | Finds Pets by status
63-
*PetApi* | [**findPetsByTags**](doc//PetApi.md#findpetsbytags) | **get** /pet/findByTags | Finds Pets by tags
64-
*PetApi* | [**getPetById**](doc//PetApi.md#getpetbyid) | **get** /pet/{petId} | Find pet by ID
65-
*PetApi* | [**updatePet**](doc//PetApi.md#updatepet) | **put** /pet | Update an existing pet
66-
*PetApi* | [**updatePetWithForm**](doc//PetApi.md#updatepetwithform) | **post** /pet/{petId} | Updates a pet in the store with form data
67-
*PetApi* | [**uploadFile**](doc//PetApi.md#uploadfile) | **post** /pet/{petId}/uploadImage | uploads an image
68-
*StoreApi* | [**deleteOrder**](doc//StoreApi.md#deleteorder) | **delete** /store/order/{orderId} | Delete purchase order by ID
69-
*StoreApi* | [**getInventory**](doc//StoreApi.md#getinventory) | **get** /store/inventory | Returns pet inventories by status
70-
*StoreApi* | [**getOrderById**](doc//StoreApi.md#getorderbyid) | **get** /store/order/{orderId} | Find purchase order by ID
71-
*StoreApi* | [**placeOrder**](doc//StoreApi.md#placeorder) | **post** /store/order | Place an order for a pet
72-
*UserApi* | [**createUser**](doc//UserApi.md#createuser) | **post** /user | Create user
73-
*UserApi* | [**createUsersWithArrayInput**](doc//UserApi.md#createuserswitharrayinput) | **post** /user/createWithArray | Creates list of users with given input array
74-
*UserApi* | [**createUsersWithListInput**](doc//UserApi.md#createuserswithlistinput) | **post** /user/createWithList | Creates list of users with given input array
75-
*UserApi* | [**deleteUser**](doc//UserApi.md#deleteuser) | **delete** /user/{username} | Delete user
76-
*UserApi* | [**getUserByName**](doc//UserApi.md#getuserbyname) | **get** /user/{username} | Get user by user name
77-
*UserApi* | [**loginUser**](doc//UserApi.md#loginuser) | **get** /user/login | Logs user into the system
78-
*UserApi* | [**logoutUser**](doc//UserApi.md#logoutuser) | **get** /user/logout | Logs out current logged in user session
79-
*UserApi* | [**updateUser**](doc//UserApi.md#updateuser) | **put** /user/{username} | Updated user
60+
*PetApi* | [**addPet**](doc\/PetApi.md#addpet) | **post** /pet | Add a new pet to the store
61+
*PetApi* | [**deletePet**](doc\/PetApi.md#deletepet) | **delete** /pet/{petId} | Deletes a pet
62+
*PetApi* | [**findPetsByStatus**](doc\/PetApi.md#findpetsbystatus) | **get** /pet/findByStatus | Finds Pets by status
63+
*PetApi* | [**findPetsByTags**](doc\/PetApi.md#findpetsbytags) | **get** /pet/findByTags | Finds Pets by tags
64+
*PetApi* | [**getPetById**](doc\/PetApi.md#getpetbyid) | **get** /pet/{petId} | Find pet by ID
65+
*PetApi* | [**updatePet**](doc\/PetApi.md#updatepet) | **put** /pet | Update an existing pet
66+
*PetApi* | [**updatePetWithForm**](doc\/PetApi.md#updatepetwithform) | **post** /pet/{petId} | Updates a pet in the store with form data
67+
*PetApi* | [**uploadFile**](doc\/PetApi.md#uploadfile) | **post** /pet/{petId}/uploadImage | uploads an image
68+
*StoreApi* | [**deleteOrder**](doc\/StoreApi.md#deleteorder) | **delete** /store/order/{orderId} | Delete purchase order by ID
69+
*StoreApi* | [**getInventory**](doc\/StoreApi.md#getinventory) | **get** /store/inventory | Returns pet inventories by status
70+
*StoreApi* | [**getOrderById**](doc\/StoreApi.md#getorderbyid) | **get** /store/order/{orderId} | Find purchase order by ID
71+
*StoreApi* | [**placeOrder**](doc\/StoreApi.md#placeorder) | **post** /store/order | Place an order for a pet
72+
*UserApi* | [**createUser**](doc\/UserApi.md#createuser) | **post** /user | Create user
73+
*UserApi* | [**createUsersWithArrayInput**](doc\/UserApi.md#createuserswitharrayinput) | **post** /user/createWithArray | Creates list of users with given input array
74+
*UserApi* | [**createUsersWithListInput**](doc\/UserApi.md#createuserswithlistinput) | **post** /user/createWithList | Creates list of users with given input array
75+
*UserApi* | [**deleteUser**](doc\/UserApi.md#deleteuser) | **delete** /user/{username} | Delete user
76+
*UserApi* | [**getUserByName**](doc\/UserApi.md#getuserbyname) | **get** /user/{username} | Get user by user name
77+
*UserApi* | [**loginUser**](doc\/UserApi.md#loginuser) | **get** /user/login | Logs user into the system
78+
*UserApi* | [**logoutUser**](doc\/UserApi.md#logoutuser) | **get** /user/logout | Logs out current logged in user session
79+
*UserApi* | [**updateUser**](doc\/UserApi.md#updateuser) | **put** /user/{username} | Updated user
8080

8181

8282
## Documentation For Models
8383

84-
- [ApiResponse](doc//ApiResponse.md)
85-
- [Category](doc//Category.md)
86-
- [Order](doc//Order.md)
87-
- [Pet](doc//Pet.md)
88-
- [Tag](doc//Tag.md)
89-
- [User](doc//User.md)
84+
- [ApiResponse](doc\/ApiResponse.md)
85+
- [Category](doc\/Category.md)
86+
- [Order](doc\/Order.md)
87+
- [Pet](doc\/Pet.md)
88+
- [Tag](doc\/Tag.md)
89+
- [User](doc\/User.md)
9090

9191

9292
## Documentation For Authorization

samples/client/petstore/dart-dio/lib/api/pet_api.dart

Lines changed: 77 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:built_value/serializer.dart';
88
import 'package:openapi/model/pet.dart';
99
import 'package:openapi/model/api_response.dart';
1010
import 'dart:typed_data';
11+
import 'package:openapi/api_util.dart';
1112

1213
class PetApi {
1314
final Dio _dio;
@@ -22,26 +23,24 @@ class PetApi {
2223

2324
String path = "/pet";
2425

25-
// query params
26-
Map<String, dynamic> queryParams = {};
27-
Map<String, String> headerParams = Map.from(headers ?? {});
28-
Map<String, String> formParams = {};
26+
Map<String, dynamic> queryParams = {};
27+
Map<String, String> headerParams = Map.from(headers ?? {});
28+
dynamic bodyData;
2929

30-
queryParams.removeWhere((key, value) => value == null);
31-
headerParams.removeWhere((key, value) => value == null);
32-
formParams.removeWhere((key, value) => value == null);
30+
queryParams.removeWhere((key, value) => value == null);
31+
headerParams.removeWhere((key, value) => value == null);
32+
33+
List<String> contentTypes = ["application/json","application/xml"];
3334

34-
List<String> contentTypes = [
35-
"application/json",
36-
"application/xml"];
3735

3836
var serializedBody = _serializers.serialize(body);
3937
var jsonbody = json.encode(serializedBody);
38+
bodyData = jsonbody;
4039

4140
return _dio.request(
4241
path,
4342
queryParameters: queryParams,
44-
data: jsonbody,
43+
data: bodyData,
4544
options: Options(
4645
method: 'post'.toUpperCase(),
4746
headers: headerParams,
@@ -57,22 +56,22 @@ class PetApi {
5756

5857
String path = "/pet/{petId}".replaceAll("{" + "petId" + "}", petId.toString());
5958

60-
// query params
61-
Map<String, dynamic> queryParams = {};
62-
Map<String, String> headerParams = Map.from(headers ?? {});
63-
Map<String, String> formParams = {};
59+
Map<String, dynamic> queryParams = {};
60+
Map<String, String> headerParams = Map.from(headers ?? {});
61+
dynamic bodyData;
6462

6563
headerParams["api_key"] = apiKey;
66-
queryParams.removeWhere((key, value) => value == null);
67-
headerParams.removeWhere((key, value) => value == null);
68-
formParams.removeWhere((key, value) => value == null);
64+
queryParams.removeWhere((key, value) => value == null);
65+
headerParams.removeWhere((key, value) => value == null);
66+
67+
List<String> contentTypes = [];
6968

70-
List<String> contentTypes = [];
7169

7270

7371
return _dio.request(
7472
path,
7573
queryParameters: queryParams,
74+
data: bodyData,
7675
options: Options(
7776
method: 'delete'.toUpperCase(),
7877
headers: headerParams,
@@ -88,22 +87,22 @@ class PetApi {
8887

8988
String path = "/pet/findByStatus";
9089

91-
// query params
92-
Map<String, dynamic> queryParams = {};
93-
Map<String, String> headerParams = Map.from(headers ?? {});
94-
Map<String, String> formParams = {};
90+
Map<String, dynamic> queryParams = {};
91+
Map<String, String> headerParams = Map.from(headers ?? {});
92+
dynamic bodyData;
9593

9694
queryParams["status"] = status;
97-
queryParams.removeWhere((key, value) => value == null);
98-
headerParams.removeWhere((key, value) => value == null);
99-
formParams.removeWhere((key, value) => value == null);
95+
queryParams.removeWhere((key, value) => value == null);
96+
headerParams.removeWhere((key, value) => value == null);
97+
98+
List<String> contentTypes = [];
10099

101-
List<String> contentTypes = [];
102100

103101

104102
return _dio.request(
105103
path,
106104
queryParameters: queryParams,
105+
data: bodyData,
107106
options: Options(
108107
method: 'get'.toUpperCase(),
109108
headers: headerParams,
@@ -134,22 +133,22 @@ class PetApi {
134133

135134
String path = "/pet/findByTags";
136135

137-
// query params
138-
Map<String, dynamic> queryParams = {};
139-
Map<String, String> headerParams = Map.from(headers ?? {});
140-
Map<String, String> formParams = {};
136+
Map<String, dynamic> queryParams = {};
137+
Map<String, String> headerParams = Map.from(headers ?? {});
138+
dynamic bodyData;
141139

142140
queryParams["tags"] = tags;
143-
queryParams.removeWhere((key, value) => value == null);
144-
headerParams.removeWhere((key, value) => value == null);
145-
formParams.removeWhere((key, value) => value == null);
141+
queryParams.removeWhere((key, value) => value == null);
142+
headerParams.removeWhere((key, value) => value == null);
143+
144+
List<String> contentTypes = [];
146145

147-
List<String> contentTypes = [];
148146

149147

150148
return _dio.request(
151149
path,
152150
queryParameters: queryParams,
151+
data: bodyData,
153152
options: Options(
154153
method: 'get'.toUpperCase(),
155154
headers: headerParams,
@@ -180,21 +179,21 @@ class PetApi {
180179

181180
String path = "/pet/{petId}".replaceAll("{" + "petId" + "}", petId.toString());
182181

183-
// query params
184-
Map<String, dynamic> queryParams = {};
185-
Map<String, String> headerParams = Map.from(headers ?? {});
186-
Map<String, String> formParams = {};
182+
Map<String, dynamic> queryParams = {};
183+
Map<String, String> headerParams = Map.from(headers ?? {});
184+
dynamic bodyData;
187185

188-
queryParams.removeWhere((key, value) => value == null);
189-
headerParams.removeWhere((key, value) => value == null);
190-
formParams.removeWhere((key, value) => value == null);
186+
queryParams.removeWhere((key, value) => value == null);
187+
headerParams.removeWhere((key, value) => value == null);
188+
189+
List<String> contentTypes = [];
191190

192-
List<String> contentTypes = [];
193191

194192

195193
return _dio.request(
196194
path,
197195
queryParameters: queryParams,
196+
data: bodyData,
198197
options: Options(
199198
method: 'get'.toUpperCase(),
200199
headers: headerParams,
@@ -224,26 +223,24 @@ class PetApi {
224223

225224
String path = "/pet";
226225

227-
// query params
228-
Map<String, dynamic> queryParams = {};
229-
Map<String, String> headerParams = Map.from(headers ?? {});
230-
Map<String, String> formParams = {};
226+
Map<String, dynamic> queryParams = {};
227+
Map<String, String> headerParams = Map.from(headers ?? {});
228+
dynamic bodyData;
229+
230+
queryParams.removeWhere((key, value) => value == null);
231+
headerParams.removeWhere((key, value) => value == null);
231232

232-
queryParams.removeWhere((key, value) => value == null);
233-
headerParams.removeWhere((key, value) => value == null);
234-
formParams.removeWhere((key, value) => value == null);
233+
List<String> contentTypes = ["application/json","application/xml"];
235234

236-
List<String> contentTypes = [
237-
"application/json",
238-
"application/xml"];
239235

240236
var serializedBody = _serializers.serialize(body);
241237
var jsonbody = json.encode(serializedBody);
238+
bodyData = jsonbody;
242239

243240
return _dio.request(
244241
path,
245242
queryParameters: queryParams,
246-
data: jsonbody,
243+
data: bodyData,
247244
options: Options(
248245
method: 'put'.toUpperCase(),
249246
headers: headerParams,
@@ -259,22 +256,23 @@ class PetApi {
259256

260257
String path = "/pet/{petId}".replaceAll("{" + "petId" + "}", petId.toString());
261258

262-
// query params
263-
Map<String, dynamic> queryParams = {};
264-
Map<String, String> headerParams = Map.from(headers ?? {});
265-
Map<String, String> formParams = {};
259+
Map<String, dynamic> queryParams = {};
260+
Map<String, String> headerParams = Map.from(headers ?? {});
261+
dynamic bodyData;
266262

267-
queryParams.removeWhere((key, value) => value == null);
268-
headerParams.removeWhere((key, value) => value == null);
269-
formParams.removeWhere((key, value) => value == null);
263+
queryParams.removeWhere((key, value) => value == null);
264+
headerParams.removeWhere((key, value) => value == null);
270265

271-
List<String> contentTypes = [
272-
"application/x-www-form-urlencoded"];
266+
List<String> contentTypes = ["application/x-www-form-urlencoded"];
267+
268+
Map<String, dynamic> formData = {};
269+
bodyData = FormData.fromMap(formData);
273270

274271

275272
return _dio.request(
276273
path,
277274
queryParameters: queryParams,
275+
data: bodyData,
278276
options: Options(
279277
method: 'post'.toUpperCase(),
280278
headers: headerParams,
@@ -290,22 +288,29 @@ class PetApi {
290288

291289
String path = "/pet/{petId}/uploadImage".replaceAll("{" + "petId" + "}", petId.toString());
292290

293-
// query params
294-
Map<String, dynamic> queryParams = {};
295-
Map<String, String> headerParams = Map.from(headers ?? {});
296-
Map<String, String> formParams = {};
291+
Map<String, dynamic> queryParams = {};
292+
Map<String, String> headerParams = Map.from(headers ?? {});
293+
dynamic bodyData;
294+
295+
queryParams.removeWhere((key, value) => value == null);
296+
headerParams.removeWhere((key, value) => value == null);
297297

298-
queryParams.removeWhere((key, value) => value == null);
299-
headerParams.removeWhere((key, value) => value == null);
300-
formParams.removeWhere((key, value) => value == null);
298+
List<String> contentTypes = ["multipart/form-data"];
301299

302-
List<String> contentTypes = [
303-
"multipart/form-data"];
300+
Map<String, dynamic> formData = {};
301+
if (additionalMetadata != null) {
302+
formData['additionalMetadata'] = parameterToString(additionalMetadata);
303+
}
304+
if (file != null) {
305+
formData['file'] = MultipartFile.fromBytes(file, filename: "file");
306+
}
307+
bodyData = FormData.fromMap(formData);
304308

305309

306310
return _dio.request(
307311
path,
308312
queryParameters: queryParams,
313+
data: bodyData,
309314
options: Options(
310315
method: 'post'.toUpperCase(),
311316
headers: headerParams,

0 commit comments

Comments
 (0)